From 5b8c09c1240ca0df3d451bb5cb95d88602efd341 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 19 Jan 2016 13:00:02 +0100 Subject: string2Int: Barf on negative numbers for unsigned types --- src/libutil/util.hh | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libutil') diff --git a/src/libutil/util.hh b/src/libutil/util.hh index cf93c6378a06..a889ef2f14fa 100644 --- a/src/libutil/util.hh +++ b/src/libutil/util.hh @@ -8,7 +8,7 @@ #include #include #include - +#include #include #ifndef HAVE_STRUCT_DIRENT_D_TYPE @@ -359,6 +359,8 @@ bool statusOk(int status); /* Parse a string into an integer. */ template bool string2Int(const string & s, N & n) { + if (string(s, 0, 1) == "-" && !std::numeric_limits::is_signed) + return false; std::istringstream str(s); str >> n; return str && str.get() == EOF; -- cgit 1.4.1