#1464 vsnprintf cause application crash on machines with P3 CPU

closed-invalid
nobody
2010-09-01
2010-09-01
b-s-a
No

This code always cause program error on machine with CPU Intel Pentium III. Replacing vsnprintf by _vsnprintf fixes the problem. On P4, Core 2 and AMD Athlon 64 no problems.

#include <string>
#include <iostream>
#include <cstdarg>
#include <cstdio>
#include <vector>

std::string formatString(const char *format, ...)
{
va_list ap1;
va_list ap2;
va_start(ap1, format);
va_copy(ap2, ap1);
const int size = ::vsnprintf(NULL, 0, format, ap2) + 1;
va_end(ap2);

std::vector<char> buffer(size);
::vsnprintf(&*buffer.begin(), size, format, ap1);
va_end(ap1);

std::string result(buffer.begin(), buffer.end()-1);

return result;
}

int main()
{
std::string txt = "some text";
std::cout << formatString("%s:%u", txt.c_str(), 1235) << std::endl;
return 0;
}

mingw-runtime versions 3.18 and 3.16

$ mingw32-g++ -v
Using built-in specs.
Target: mingw32
Configured with: /var/tmp/cross/mingw32/portage/cross-mingw32/gcc-4.4.3-r2/work/gcc-4.4.3/configure --prefix=/usr --bindir=/usr/x86_64-pc-linux-gnu/mingw32/gcc-bin/4.4.3 --includedir=/usr/lib/gcc/mingw32/4.4.3/include --datadir=/usr/share/gcc-data/mingw32/4.4.3 --mandir=/usr/share/gcc-data/mingw32/4.4.3/man --infodir=/usr/share/gcc-data/mingw32/4.4.3/info --with-gxx-include-dir=/usr/lib/gcc/mingw32/4.4.3/include/g++-v4 --host=x86_64-pc-linux-gnu --target=mingw32 --build=x86_64-pc-linux-gnu --disable-altivec --disable-fixed-point --without-ppl --without-cloog --enable-nls --without-included-gettext --with-system-zlib --disable-checking --disable-werror --enable-secureplt --disable-libmudflap --disable-libssp --disable-libgomp --enable-cld --with-python-dir=/share/gcc-data/mingw32/4.4.3/python --disable-libgcj --enable-languages=c,c++,fortran --with-sysroot=/usr/mingw32 --disable-bootstrap --disable-libgomp --with-bugurl=http://bugs.gentoo.org/ --with-pkgversion='Gentoo 4.4.3-r2 p1.2'
Thread model: win32
gcc version 4.4.3 (Gentoo 4.4.3-r2 p1.2)

Discussion

  • b-s-a

    b-s-a - 2010-09-01

    gdb detects SIGILL when executing this call.

     
  • b-s-a

    b-s-a - 2010-09-01

    Invalid compile flags were passed while building mingw-runtime (-march=core2).

     
  • b-s-a

    b-s-a - 2010-09-01
    • status: open --> closed-invalid
     

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

Sign up for the SourceForge newsletter:





No, thanks