mirror of
https://github.com/allankoechke/soci.git
synced 2026-11-30 10:58:24 +00:00
Fix bug in cstring_to_integer() for out of range inputs
Check for ERANGE which is the only way to detect a value out of range of long long type.
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
|
||||
#include "soci/error.h"
|
||||
|
||||
#include <cerrno>
|
||||
#include <cstdlib>
|
||||
#include <limits>
|
||||
|
||||
@@ -30,7 +31,7 @@ bool cstring_to_integer(T& result, char const* buf)
|
||||
char * end;
|
||||
const long long t = strtoll(buf, &end, 10);
|
||||
|
||||
if (end == buf || *end != '\0')
|
||||
if (end == buf || *end != '\0' || errno == ERANGE)
|
||||
return false;
|
||||
|
||||
// successfully converted to long long
|
||||
@@ -53,7 +54,7 @@ bool cstring_to_unsigned(T& result, char const* buf)
|
||||
char * end;
|
||||
const unsigned long long t = strtoull(buf, &end, 10);
|
||||
|
||||
if (end == buf || *end != '\0')
|
||||
if (end == buf || *end != '\0' || errno == ERANGE)
|
||||
return false;
|
||||
|
||||
// successfully converted to unsigned long long
|
||||
|
||||
Reference in New Issue
Block a user