On Thu, Dec 16, 2004 at 02:21:25AM -0700, Warren Young wrote:
> Yes. Also, all sprintf()s should be replaced with snprintf() or
> _snprintf() wherever possible. Added to the Wishlist.
sql_string.h is the only place I found sprintf's, so here's the patch.
I figured snprintf() with a stack-based buffer was faster than
making an ostringstream to do these conversions, so I didn't get
fancy.
- Chris
Index: mysql++/lib/sql_string.h
diff -u mysql++/lib/sql_string.h:1.2 mysql++/lib/sql_string.h:1.3
--- mysql++/lib/sql_string.h:1.2 Fri Dec 17 00:16:19 2004
+++ mysql++/lib/sql_string.h Fri Dec 17 00:38:10 2004
@@ -30,26 +30,26 @@
std::string::operator = (str); return *this;
}
SQLString (char i) : is_string(false), processed(false)
- {char s[6]; sprintf(s,"%dh",(short int)i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%dh",(short int)i); *this=s;}
SQLString (unsigned char i) : is_string(false), processed(false)
- {char s[6]; sprintf(s,"%uh",(short int)i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%uh",(short int)i); *this=s;}
SQLString (short int i) : is_string(false), processed(false)
- {char s[6]; sprintf(s,"%dh",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%dh",i); *this=s;}
SQLString (unsigned short int i) : is_string(false), processed(false)
- {char s[6]; sprintf(s,"%uh",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%uh",i); *this=s;}
SQLString (int i) : is_string(false), processed(false)
- {char s[11]; sprintf(s,"%d",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%d",i); *this=s;}
SQLString (unsigned int i) : is_string(false), processed(false)
- {char s[11]; sprintf(s,"%u",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%u",i); *this=s;}
/*SQLString (longlong i) : is_string(false), processed(false)
- {char s[22]; sprintf(s,"%dL",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%dL",i); *this=s;}
SQLString (ulonglong i) : is_string(false), processed(false)
- {char s[22]; sprintf(s,"%uL",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%uL",i); *this=s;}
*/
SQLString (float i) : is_string(false), processed(false)
- {char s[40]; sprintf(s,"%g",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%g",i); *this=s;}
SQLString (double i) : is_string(false), processed(false)
- {char s[40]; sprintf(s,"%g",i); *this=s;}
+ {char s[64]; snprintf(s,sizeof(s),"%g",i); *this=s;}
};
}; // end namespace mysqlpp