From d97e2f3a64b09a748bb0984fba33f3595298853a Mon Sep 17 00:00:00 2001 From: giraffedata Date: Sun, 9 Dec 2007 17:30:47 +0000 Subject: fix overflow calculation git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@479 9d0c8265-081b-0410-96cb-a4ca84ce46f8 --- lib/libpm.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'lib/libpm.c') diff --git a/lib/libpm.c b/lib/libpm.c index 9752d622..34ef3ac4 100644 --- a/lib/libpm.c +++ b/lib/libpm.c @@ -17,6 +17,7 @@ #include #include #include +#include #include "pm_c_util.h" #include "mallocvar.h" @@ -764,3 +765,52 @@ pm_randseed(void) { return time(NULL) ^ getpid(); } + + + +unsigned int +pm_parse_width(const char * const arg) { +/*---------------------------------------------------------------------------- + Return the image width represented by the decimal ASCIIZ string + 'arg'. Fail if it doesn't validly represent a width or represents + a width that can't be conveniently used in computation. +-----------------------------------------------------------------------------*/ + unsigned int width; + const char * error; + + interpret_uint(arg, &width, &error); + + if (error) { + pm_error("'%s' is invalid as an image width. %s", arg, error); + strfree(error); + } else { + if (width > INT_MAX-10) + pm_error("Width %u is too large for computations.", width); + } + return width; +} + + + +unsigned int +pm_parse_height(const char * const arg) { +/*---------------------------------------------------------------------------- + Same as pm_parse_width(), but for height. +-----------------------------------------------------------------------------*/ + unsigned int height; + const char * error; + + interpret_uint(arg, &height, &error); + + if (error) { + pm_error("'%s' is invalid as an image height. %s", arg, error); + strfree(error); + } else { + if (height > INT_MAX-10) + pm_error("Height %u is too large for computations.", height); + } + return height; +} + + + -- cgit 1.4.1