]> git.gag.com Git - fw/sdcc/commitdiff
* src/SDCCval.c (constVal): fixed bug 730366
authormaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 13 Sep 2005 18:25:27 +0000 (18:25 +0000)
committermaartenbrock <maartenbrock@4a8a32a2-be11-0410-ad9d-d568d2c75423>
Tue, 13 Sep 2005 18:25:27 +0000 (18:25 +0000)
* support/Util/SDCCerr.c,
* support/Util/SDCCerr.h: added warning W_INVALID_INT_CONST

git-svn-id: https://sdcc.svn.sourceforge.net/svnroot/sdcc/trunk/sdcc@3891 4a8a32a2-be11-0410-ad9d-d568d2c75423

ChangeLog
src/SDCCval.c
support/Util/SDCCerr.c
support/Util/SDCCerr.h

index 93cf0fba80bfbe54878d324248ffc3d74aa95ebc..46cbbc3829c068da7b33142374071db0c76aad94 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2005-09-13 Maarten Brock <sourceforge.brock AT dse.nl>
+
+       * src/SDCCval.c (constVal): fixed bug 730366
+       * support/Util/SDCCerr.c,
+       * support/Util/SDCCerr.h: added warning W_INVALID_INT_CONST
+
 2005-09-10 Maarten Brock <sourceforge.brock AT dse.nl>
 
        * as/mcs51/lkmem.c (summary2): fixed report for absolute areas (bug 1210220)
index 0cc9d811f7506eabbdd694b1569065c5991f7232..f760c6a7e33f4076b1a18fcb02673440a7677238 100644 (file)
@@ -27,6 +27,7 @@
 #include <math.h>
 #include <stdlib.h>
 #include <limits.h>
+#include <errno.h>
 #include "newalloc.h"
 
 int cNestLevel;
@@ -103,16 +104,16 @@ convertIListToConstList(initList *src, literalList **lList)
 {
     initList    *iLoop;
     literalList *head, *last, *newL;
-    
+
     head = last = NULL;
-    
+
     if (!src || src->type != INIT_DEEP)
     {
-       return FALSE;
+        return FALSE;
     }
-    
+
     iLoop =  src->init.deep;
-    
+
     while (iLoop)
     {
        if (iLoop->type != INIT_NODE)
@@ -144,7 +145,7 @@ convertIListToConstList(initList *src, literalList **lList)
            newL->literalValue = val;
            newL->count = 1;
            newL->next = NULL;
-           
+
            if (last)
            {
                last->next = newL;
@@ -157,12 +158,12 @@ convertIListToConstList(initList *src, literalList **lList)
        }
        iLoop = iLoop->next;
     }
-    
-    if (!head)    
+
+    if (!head)
     {
        return FALSE;
     }
-    
+
     *lList = head;
     return TRUE;
 }
@@ -171,17 +172,17 @@ literalList *
 copyLiteralList(literalList *src)
 {
     literalList *head, *prev, *newL;
-    
+
     head = prev = NULL;
-    
+
     while (src)
     {
        newL = Safe_alloc(sizeof(literalList));
-       
+
        newL->literalValue = src->literalValue;
        newL->count = src->count;
        newL->next = NULL;
-       
+
        if (prev)
        {
            prev->next = newL;
@@ -193,7 +194,7 @@ copyLiteralList(literalList *src)
        prev = newL;
        src = src->next;
     }
-    
+
     return head;
 }
 
@@ -480,7 +481,7 @@ constFixed16x16Val (char *s)
   SPEC_NOUN (val->type) = V_FLOAT;
   SPEC_SCLS (val->type) = S_LITERAL;
   SPEC_CVAL (val->type).v_fixed16x16 = fixed16x16FromDouble ( sval );
+
   return val;
 }
 
@@ -491,8 +492,6 @@ value *constVal (char *s)
 {
   value *val;
   short hex = 0, octal = 0;
-  char scanFmt[10];
-  int scI = 0;
   double dval;
 
   val = newValue ();           /* alloc space for value   */
@@ -509,26 +508,16 @@ value *constVal (char *s)
   if (!hex && *s == '0' && *(s + 1))
     octal = 1;
 
-  /* create the scan string */
-  scanFmt[scI++] = '%';
-
-  scanFmt[scI++] = 'l';
-
-  if (octal)
-    scanFmt[scI++] = 'o';
-  else if (hex)
-    scanFmt[scI++] = 'x';
-  else
-    scanFmt[scI++] = 'f';
-
-  scanFmt[scI++] = '\0';
-
-  if (octal || hex) {
+  errno = 0;
+  if (hex || octal) {
     unsigned long sval;
-    sscanf (s, scanFmt, &sval);
+    sval = strtoul (s, NULL, 0);
     dval=sval;
+    if (errno) {
+      werror (W_INVALID_INT_CONST, s, dval);
+    }
   } else {
-    sscanf (s, scanFmt, &dval);
+    sscanf (s, "%lf", &dval);
   }
 
   /* Setup the flags first */
@@ -577,6 +566,20 @@ value *constVal (char *s)
     }
   }
 
+  /* check for out of range */
+  if (dval<-2147483648.0) {
+    dval = LONG_MIN;
+    werror (W_INVALID_INT_CONST, s, dval);
+  }
+  if (dval>2147483647.0 && !SPEC_USIGN (val->type)) {
+    dval = LONG_MAX;
+    werror (W_INVALID_INT_CONST, s, dval);
+  }
+  if (dval>4294967295.0) {
+    dval = ULONG_MAX;
+    werror (W_INVALID_INT_CONST, s, dval);
+  }
+
   if (SPEC_LONG (val->type))
     {
       if (SPEC_USIGN (val->type))
@@ -615,9 +618,9 @@ unsigned char hexEscape(char **src)
 
   (*src)++ ;   /* Skip over the 'x' */
   s = *src ;   /* Save for error detection */
-  
+
   value = strtol (*src, src, 16);
-  
+
   if (s == *src) {
       // no valid hex found
       werror(E_INVALID_HEX);
@@ -655,9 +658,9 @@ unsigned char octalEscape (char **str) {
   return value;
 }
 
-/*! 
+/*!
   /fn int copyStr (char *dest, char *src)
-  
+
   Copies a source string to a dest buffer interpreting escape sequences
   and special characters
 
@@ -667,7 +670,7 @@ unsigned char octalEscape (char **str) {
 
 */
 
-int 
+int
 copyStr (char *dest, char *src)
 
 {
@@ -716,7 +719,7 @@ copyStr (char *dest, char *src)
              src-- ;
              break;
 
-           case 'x': 
+           case 'x':
              *dest++ = hexEscape(&src) ;
              src-- ;
              break ;
@@ -1253,7 +1256,7 @@ valPlus (value * lval, value * rval)
                                        RESULT_TYPE_INT,
                                        '+');
   SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
-  
+
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) + floatFromVal (rval);
   else
@@ -1295,7 +1298,7 @@ valMinus (value * lval, value * rval)
                                        RESULT_TYPE_INT,
                                        '-');
   SPEC_SCLS (val->etype) = S_LITERAL; /* will remain literal */
-  
+
   if (IS_FLOAT (val->type))
     SPEC_CVAL (val->type).v_float = floatFromVal (lval) - floatFromVal (rval);
   else
@@ -1565,7 +1568,7 @@ valBitwise (value * lval, value * rval, int op)
        }
       break;
     }
-    
+
   return cheapestVal(val);
 }
 
index 19548189fe670d7b3174a173b882b61ea0a328f4..65cd91ec6095913d5296b2dc257e5746d0ae3c3c 100644 (file)
@@ -420,6 +420,8 @@ struct
    "absolute address for sfr '%s' probably out of range." },
 { E_BANKED_WITH_CALLEESAVES, ERROR_LEVEL_ERROR,
    "Both banked and callee-saves cannot be used together." },
+{ W_INVALID_INT_CONST, ERROR_LEVEL_WARNING,
+   "integer constant '%s' out of range, truncated to %.0lf." },
 };
 
 /*
index 8d7e29562db5333b22cdb43a50ae96f26031fc6e..0859facbb378b79133ae5c5d2eb52e330d4c1c12 100644 (file)
@@ -199,6 +199,7 @@ SDCCERR - SDCC Standard error handler
 #define E_SHADOWREGS_NO_ISR           181 /* shadowregs keyword following non-ISR function */
 #define W_SFR_ABSRANGE                182 /* sfr at address out of range */
 #define E_BANKED_WITH_CALLEESAVES     183 /* banked and callee-saves mixed */
+#define W_INVALID_INT_CONST           184 /* invalid integer literal string */
 
 #define MAX_ERROR_WARNING             256 /* size of disable warnings array */