#116 StringUtil: vsnprintf causes SIGSEGV

closed
nobody
core (26)
5
2009-05-23
2008-06-30
Anonymous
No

In function vform, when buffer is small function vsnprintf is calling twice and causing SIGSEGV. It appears because for each call to vsnprintf we need to clear args argument by calling va_start/va_end.

So, i think, it is neccessary to find other way to calculate size of string buffer.

Discussion

  • Nobody/Anonymous

    to joshtaylor not correct
    int vsnprintf(char* buffer, size_t nsize, const char* format, va_list param)

    va_list param -- no reference

    std::string StringUtil::vform(const char* format, va_list args) {
    size_t size = 1024;
    char* buffer = new char[size];

    while (1) {
    int n = VSNPRINTF(buffer, size, format, args);

    // If that worked, return a string.
    if ((n > -1) && (static_cast<size_t>(n) < size)) {
    std::string s(buffer);
    delete [] buffer;
    return s;
    }

    // Else try again with more space.
    size = (n > -1) ?
    n + 1 : // ISO/IEC 9899:1999
    size * 2; // twice the old size

    delete [] buffer;
    buffer = new char[size];
    }
    }

    --------------it's no problem!

     
  • darkangel

    darkangel - 2009-05-23
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks