aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>1998-06-07 21:02:38 +0000
committerEric S. Raymond <esr@thyrsus.com>1998-06-07 21:02:38 +0000
commit661782c919727ee927e35dc059d0dd27d091d326 (patch)
tree35e63772f28e227a30b2ee3c98c30a182b097345
parent7e496ae9a594a8b5a7f430948143f3ee35c85631 (diff)
downloadfetchmail-661782c919727ee927e35dc059d0dd27d091d326.tar.gz
fetchmail-661782c919727ee927e35dc059d0dd27d091d326.tar.bz2
fetchmail-661782c919727ee927e35dc059d0dd27d091d326.zip
More from Gunter.
svn path=/trunk/; revision=1925
-rw-r--r--options.c36
1 files changed, 35 insertions, 1 deletions
diff --git a/options.c b/options.c
index ce0f1f68..d18008ad 100644
--- a/options.c
+++ b/options.c
@@ -13,6 +13,8 @@
#if defined(STDC_HEADERS)
#include <stdlib.h>
#include <limits.h>
+#else
+#include <ctype.h>
#endif
#include "getopt.h"
@@ -159,7 +161,39 @@ static int xatoi(char *s, int *errflagptr)
return (int) value; /* shut up, I know what I'm doing */
#else
- return atoi(s);
+ int i;
+ char *dp;
+# if defined (STDC_HEADERS)
+ size_t len;
+# else
+ int len;
+# endif
+
+ /* We do only base 10 conversions here (atoi)! */
+
+ len = strlen(s);
+ /* check for leading white spaces */
+ for (i = 0; (i < len) && isspace(s[i]); i++)
+ ;
+
+ dp = &s[i];
+
+ /* check for +/- */
+ if (i < len && (s[i] == '+' || s[i] == '-')) i++;
+
+ /* skip over digits */
+ for ( /* no init */ ; (i < len) && isdigit(s[i]); i++)
+ ;
+
+ /* check for trailing garbage */
+ if (i != len) {
+ (void) fprintf(stderr, "String '%s' is not a valid number string.\n", s);
+ (*errflagptr)++;
+ return 0;
+ }
+
+ /* atoi should be safe by now, except for number range over/underflow */
+ return atoi(dp);
#endif
}