Fixed bugs 2792371 and 2694060 by adding checks for end of format.

git-svn-id: svn://svn.code.sf.net/p/loki-lib/code/trunk@1135 7ec92016-0320-0410-acc4-a06ded1c099a
This commit is contained in:
rich_sposato 2011-10-04 00:50:00 +00:00
parent 9fe637bf8b
commit 5fdebe2bf7

View file

@ -135,6 +135,11 @@ namespace Loki
// Print (or gobble in case of the "*" specifier) an int // Print (or gobble in case of the "*" specifier) an int
PrintfState& operator()(LOKI_SAFEFORMAT_UNSIGNED_LONG i) { 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 if (result_ == -1) return *this; // don't even bother
// % [flags] [width] [.prec] [modifier] type_char // % [flags] [width] [.prec] [modifier] type_char
// Fetch the flags // Fetch the flags
@ -208,6 +213,11 @@ namespace Loki
} }
PrintfState& operator()(const char *const s) { 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; if (result_ == -1) return *this;
ReadLeaders(); ReadLeaders();
const char fmt = *format_; const char fmt = *format_;
@ -359,6 +369,11 @@ namespace Loki
template <class Value> template <class Value>
void PrintUsing_snprintf(Value n, const char* check_fmt_char) { 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; const Char *const fmt = format_ - 1;
assert(*fmt == '%'); assert(*fmt == '%');
// enforce format string validity // enforce format string validity