aboutsummaryrefslogtreecommitdiff
path: root/src/libutil
diff options
context:
space:
mode:
authorEelco Dolstra <eelco.dolstra@logicblox.com>2016-01-19 13:00:02 +0100
committerEelco Dolstra <eelco.dolstra@logicblox.com>2016-01-20 16:45:05 +0100
commit5b8c09c1240ca0df3d451bb5cb95d88602efd341 (patch)
tree3884fd3ba8c3db3586447b1eefb506a8907a79d0 /src/libutil
parent3baf8be1d149e034f771d2a0acf9d50563164cf6 (diff)
string2Int: Barf on negative numbers for unsigned types
Diffstat (limited to 'src/libutil')
-rw-r--r--src/libutil/util.hh4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/libutil/util.hh b/src/libutil/util.hh
index cf93c6378..a889ef2f1 100644
--- a/src/libutil/util.hh
+++ b/src/libutil/util.hh
@@ -8,7 +8,7 @@
#include <unistd.h>
#include <signal.h>
#include <functional>
-
+#include <limits>
#include <cstdio>
#ifndef HAVE_STRUCT_DIRENT_D_TYPE
@@ -359,6 +359,8 @@ bool statusOk(int status);
/* Parse a string into an integer. */
template<class N> bool string2Int(const string & s, N & n)
{
+ if (string(s, 0, 1) == "-" && !std::numeric_limits<N>::is_signed)
+ return false;
std::istringstream str(s);
str >> n;
return str && str.get() == EOF;