]> skyeroc.xyz Git - dgamelaunch/commitdiff
Error handling for negative numbers.
authorJoshua Kwan <joshk@triplehelix.org>
Sun, 1 Feb 2004 08:10:18 +0000 (08:10 +0000)
committerJoshua Kwan <joshk@triplehelix.org>
Sun, 1 Feb 2004 08:10:18 +0000 (08:10 +0000)
git-svn-id: svn://katsu.triplehelix.org/dgamelaunch/trunk@204 db0b04b0-f4d1-0310-9a6d-de3e77497b0e

config.l

index 4a8856267aa4cf3178d214c7e712f2974e010930..e4ad02eb1cace0300070dde2d9171069c17fdeef 100644 (file)
--- a/config.l
+++ b/config.l
@@ -14,7 +14,7 @@ unsigned int line = 1, col = 0;
 
 %}
 
-NUMBER         [0-9]+
+NUMBER         -?[0-9]+
 VALUE          \".*\"
 MALSTRING      \"[^\"\n]*\n
 WHITE          [\t ]*
@@ -22,7 +22,30 @@ COMMENT              ^#.*
 
 %%
 
-{NUMBER} { yylval.i = atoi(yytext); return TYPE_NUMBER; }
+{NUMBER} { 
+  unsigned int x;
+  errno = 0;
+  
+  if (atoi(yytext) < 0)
+  {
+    fprintf(stderr,"%s:%d: negative value not accepted! Fix it now!\n",
+      config, line);
+    graceful_exit(1);
+  }
+  
+  x = strtoul(yytext, NULL, 10);
+  
+  if (errno == ERANGE)
+  {
+    fprintf(stderr, "%s:%d: %s is too big! Fix it now!\n",
+      config, line, yytext);
+    graceful_exit(1);
+  }
+  
+  yylval.i = x;
+  return TYPE_NUMBER;
+}
+
 {VALUE}        {
   yytext[yyleng - 1] = '\0'; /* Kill the trailing quote */
   yylval.s = strdup(yytext + 1); /* kill leading quote */