|
From: <ric...@us...> - 2011-10-04 00:50:11
|
Revision: 1135
http://loki-lib.svn.sourceforge.net/loki-lib/?rev=1135&view=rev
Author: rich_sposato
Date: 2011-10-04 00:50:00 +0000 (Tue, 04 Oct 2011)
Log Message:
-----------
Fixed bugs 2792371 and 2694060 by adding checks for end of format.
Modified Paths:
--------------
trunk/include/loki/SafeFormat.h
Modified: trunk/include/loki/SafeFormat.h
===================================================================
--- trunk/include/loki/SafeFormat.h 2011-10-03 05:05:41 UTC (rev 1134)
+++ trunk/include/loki/SafeFormat.h 2011-10-04 00:50:00 UTC (rev 1135)
@@ -135,6 +135,11 @@
// Print (or gobble in case of the "*" specifier) an int
PrintfState& operator()(LOKI_SAFEFORMAT_UNSIGNED_LONG i) {
+ if ( '\0' == *format_ )
+ {
+ ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" );
+ throw ex;
+ }
if (result_ == -1) return *this; // don't even bother
// % [flags] [width] [.prec] [modifier] type_char
// Fetch the flags
@@ -208,6 +213,11 @@
}
PrintfState& operator()(const char *const s) {
+ if ( '\0' == *format_ )
+ {
+ ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" );
+ throw ex;
+ }
if (result_ == -1) return *this;
ReadLeaders();
const char fmt = *format_;
@@ -219,7 +229,7 @@
result_ = -1;
return *this;
}
- const size_t len = std::min(std::strlen(s), prec_);
+ const size_t len = std::min(std::strlen(s), prec_);
if (width_ > len) {
if (LeftJustify()) {
Write(s, s + len);
@@ -359,6 +369,11 @@
template <class Value>
void PrintUsing_snprintf(Value n, const char* check_fmt_char) {
+ if ( '\0' == *format_ )
+ {
+ ::std::logic_error ex( "invalid number of parameters for Loki::SafeFormat!" );
+ throw ex;
+ }
const Char *const fmt = format_ - 1;
assert(*fmt == '%');
// enforce format string validity
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|