vsnprintf portability problem

This is a discussion on vsnprintf portability problem within the C Programming forums, part of the General Programming Boards category; I'm working on porting the nebula device to 64-bit linux and I've hit a snag with the logger. It has ...

  1. #1
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179

    vsnprintf portability problem

    I'm working on porting the nebula device to 64-bit linux and I've hit a snag with the logger. It has a printf style function that handles the logging:
    Code:
    void
    nDefaultLogHandler::PutLineBuffer(const char* msg, va_list argList)
    {
        n_assert(msg);
        int n, size = 100;
    
        static char* staticArray = new char [10000];
    
    #ifdef __WIN32__
            n = _vsnprintf	(staticArray, 10000, msg, argList);
    #else
            n = vsnprintf	(staticArray, 10000, msg, argList);
    #endif
        
        if( n > -1 && n < 10000 )
            this->lineBuffer.Put( staticArray );
    }
    This compiles fine, but when I run it I get a segfault:
    #0 0x000000397ed745e0 in ?? () from /lib64/libc.so.6
    #1 0x000000397ed4503b in _IO_vfprintf_internal (s=0x7ffffff924b0, format=Variable "format" is not available.
    ) at vfprintf.c:1559
    #2 0x000000397ed65c1a in _IO_vsnprintf (string=0x12f4fd0 "", maxlen=Variable "maxlen" is not available.
    ) at vsnprintf.c:120
    #3 0x00002aaaaaafcc50 in nDefaultLogHandler::PutLineBuffer (this=0x503950, msg=0x2aaab1730290 "%s just redefined type from %s -> %s\n",
    argList=0x7ffffff926d0) at kernel/ndefaultloghandler.cc:103
    I tried changing the whole thing to a more standard va_start vsnprintf va_end style, but I just get type conversion errors between va_arg and char. Does anyone know a portable way to do the vsnprintf?
    Illusion and reality become impartiality and confidence.

  2. #2
    GA ichijoji's Avatar
    Join Date
    Nov 2002
    Posts
    179
    To provide more info, I tried replacing the function with this and it gave the same error:
    Code:
    void nDefaultLogHandler::PutLineBuffer(const char* msg, ...) {
    	char str[10000];
    	va_list ap;
    	va_start(ap,msg);
    	vsprintf(str,msg,ap);
    	this->lineBuffer.Put(str);
    	va_end(ap);
    }
    Illusion and reality become impartiality and confidence.

  3. #3
    Frequently Quite Prolix dwks's Avatar
    Join Date
    Apr 2005
    Location
    Canada
    Posts
    8,048
    You're probably passing invalid arguments to the function. printf("%s") will fail no matter which printf() lookalike you use.

    Post the calls to your function.
    dwk

    Seek and ye shall find. quaere et invenies.

    "Simplicity does not precede complexity, but follows it." -- Alan Perlis
    "Testing can only prove the presence of bugs, not their absence." -- Edsger Dijkstra
    "The only real mistake is the one from which we learn nothing." -- John Powell


    Other boards: DaniWeb, TPS
    Unofficial Wiki FAQ: cpwiki.sf.net

    My website: http://dwks.theprogrammingsite.com/
    Projects: codeform, xuni, atlantis, nort, etc.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Memory problem with Borland C 3.1
    By AZ1699 in forum C Programming
    Replies: 16
    Last Post: 11-16-2007, 11:22 AM
  2. Someone having same problem with Code Block?
    By ofayto in forum C++ Programming
    Replies: 1
    Last Post: 07-12-2007, 09:38 AM
  3. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 03:51 PM
  4. WS_POPUP, continuation of old problem
    By blurrymadness in forum Windows Programming
    Replies: 1
    Last Post: 04-20-2007, 07:54 PM
  5. beginner problem
    By The_Nymph in forum C Programming
    Replies: 4
    Last Post: 03-05-2002, 05:46 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21