#181 sprintf(3) is not defined when building with g++ 3.4.6


I'm checking Squid-3 and, aside from other issues related to that software, I noticed that cppunit/TestAssert.h:82 fresh out of CVS fails because sprintf(3) is (correctly) not defined. snprintf(3) should be used instead, much like sprintf_s(3) is used two lines above with Visual Studio. Applying the patch

Index: include/cppunit/TestAssert.h

RCS file: /cvsroot/cppunit/cppunit/include/cppunit/TestAssert.h,v
retrieving revision 1.30
diff -u -r1.30 TestAssert.h
--- include/cppunit/TestAssert.h 24 Feb 2007 21:13:04 -0000 1.30
+++ include/cppunit/TestAssert.h 3 Sep 2007 17:46:48 -0000
@@ -79,7 +79,7 @@
#ifdef __STDC_SECURE_LIB__ // Use secure version with visual studio 2005 to avoid warning.
sprintf_s(buffer, sizeof(buffer), "%.*g", precision, x);
- sprintf(buffer, "%.*g", precision, x);
+ snprintf(buffer, sizeof(buffer), "%.*g", precision, x);
return buffer;

solves the problem.

I suggest availability of snprintf() and sprintf() be checked at configure time, and the former preferred over the latter if both are available. Please let me know if you want me to submit a complete patch.

Sincerely, p.


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

Sign up for the SourceForge newsletter:

No, thanks