diff options
author | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-12-09 17:30:47 +0000 |
---|---|---|
committer | giraffedata <giraffedata@9d0c8265-081b-0410-96cb-a4ca84ce46f8> | 2007-12-09 17:30:47 +0000 |
commit | d97e2f3a64b09a748bb0984fba33f3595298853a (patch) | |
tree | d5f388bde91bdc4ecad19f87c757c2790801ce69 /lib/libpm.c | |
parent | b4799443c85bee0e0afc1fa23e034d2253a07635 (diff) | |
download | netpbm-mirror-d97e2f3a64b09a748bb0984fba33f3595298853a.tar.gz netpbm-mirror-d97e2f3a64b09a748bb0984fba33f3595298853a.tar.xz netpbm-mirror-d97e2f3a64b09a748bb0984fba33f3595298853a.zip |
fix overflow calculation
git-svn-id: http://svn.code.sf.net/p/netpbm/code/trunk@479 9d0c8265-081b-0410-96cb-a4ca84ce46f8
Diffstat (limited to 'lib/libpm.c')
-rw-r--r-- | lib/libpm.c | 50 |
1 files changed, 50 insertions, 0 deletions
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 <errno.h> #include <setjmp.h> #include <time.h> +#include <limits.h> #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; +} + + + |