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:
Vadim Zeitlin
2026-04-28 00:35:05 +02:00
parent 8f5245bbcd
commit 42c80b61ca

View File

@@ -10,6 +10,7 @@
#include "soci/error.h" #include "soci/error.h"
#include <cerrno>
#include <cstdlib> #include <cstdlib>
#include <limits> #include <limits>
@@ -30,7 +31,7 @@ bool cstring_to_integer(T& result, char const* buf)
char * end; char * end;
const long long t = strtoll(buf, &end, 10); const long long t = strtoll(buf, &end, 10);
if (end == buf || *end != '\0') if (end == buf || *end != '\0' || errno == ERANGE)
return false; return false;
// successfully converted to long long // successfully converted to long long
@@ -53,7 +54,7 @@ bool cstring_to_unsigned(T& result, char const* buf)
char * end; char * end;
const unsigned long long t = strtoull(buf, &end, 10); const unsigned long long t = strtoull(buf, &end, 10);
if (end == buf || *end != '\0') if (end == buf || *end != '\0' || errno == ERANGE)
return false; return false;
// successfully converted to unsigned long long // successfully converted to unsigned long long