From 951b5877caa2dbc7bbbaad4be91cc9f67bb01b24 Mon Sep 17 00:00:00 2001 From: giraffedata Date: Tue, 18 Dec 2007 16:14:31 +0000 Subject: Reject obviously negative number as unsigned number git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@495 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/util/nstring.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/util') diff --git a/lib/util/nstring.c b/lib/util/nstring.c index 3e2da669..0fa78c7a 100644 --- a/lib/util/nstring.c +++ b/lib/util/nstring.c @@ -934,7 +934,7 @@ interpret_uint(const char * const string, char * tail; unsigned long ulongValue; - errno = 0; // So we can tell if strtoul() overflowed + errno = 0; /* So we can tell if strtoul() overflowed */ ulongValue = strtoul(string, &tail, 10); @@ -944,6 +944,9 @@ interpret_uint(const char * const string, asprintfN(errorP, "Number too large"); else if (ulongValue > UINT_MAX) asprintfN(errorP, "Number too large"); + else if (string[0] == '-') + asprintfN(errorP, "Negative number"); + /* Sleazy code; string may have leading spaces. */ else { *valueP = ulongValue; *errorP = NULL; -- cgit 1.4.1