stdio.h not needed
[fw/sdcc] / support / cpp / cppexp.c
index 54fb434b3a1d9747a6f52449d0b17bedb0ec47ce..2bc875f70a65f3b9dc2f7b1c014e266797e9f663 100644 (file)
@@ -24,18 +24,16 @@ Written by Per Bothner 1994. */
 
 /* Parse a C expression from text in a string  */
 
-#if defined(_MSC_VER)
-#include <malloc.h>
-#endif
-
 #include "config.h"   
 #include "cpplib.h"
 
-extern char *xmalloc PARAMS ((unsigned));
-extern char *xrealloc PARAMS ((char *, unsigned));
+#include "newalloc.h"
+
+//extern char *xmalloc PARAMS ((unsigned));
+//extern char *xrealloc PARAMS ((char *, unsigned));
 
-#ifdef MULTIBYTE_CHARS
 #include <stdlib.h>
+#ifdef MULTIBYTE_CHARS
 #include <locale.h>
 #endif
 
@@ -68,7 +66,7 @@ struct arglist {
 #define NULL_PTR ((GENERIC_PTR)0)
 #endif
 
-extern char *xmalloc ();
+//extern char *xmalloc ();
 
 #ifndef CHAR_TYPE_SIZE
 #define CHAR_TYPE_SIZE BITS_PER_UNIT
@@ -228,7 +226,7 @@ parse_number (
     if (largest_digit < digit)
       largest_digit = digit;
     nd = n * base + digit;
-    overflow |= ULONG_MAX_over_base < n | nd < n;
+    overflow |= ((ULONG_MAX_over_base < n) | (nd < n)) ;
     n = nd;
   }
 
@@ -284,7 +282,7 @@ cpp_lex (
 cpp_reader *pfile)
 {
   register int c;
-  register int namelen;
+/*  register int namelen; */
   register struct token *toktab;
   enum cpp_token token;
   struct operation op;
@@ -337,7 +335,7 @@ cpp_reader *pfile)
         It is mostly copied from c-lex.c.  */
       {
         register int result = 0;
-       register num_chars = 0;
+       register int num_chars = 0;
        unsigned width = MAX_CHAR_TYPE_SIZE;
        int wide_flag = 0;
        int max_chars;
@@ -369,7 +367,7 @@ cpp_reader *pfile)
              {
                c = cpp_parse_escape (pfile, &ptr);
                if (width < HOST_BITS_PER_INT
-                 && (unsigned) c >= (1 << width))
+                 && (unsigned) c >= (1U << width))
                    cpp_pedwarn (pfile,
                                 "escape sequence out of range for character");
              }
@@ -650,7 +648,7 @@ right_shift (
 
 #define COMPARE(OP) \
   top->unsignedp = 0;\
-  top->value = (unsigned1 || unsigned2) ? (unsigned long) v1 OP v2 : (v1 OP v2)
+  top->value = (unsigned1 || unsigned2) ? (unsigned long) v1 OP (unsigned long) v2 : (v1 OP v2)
 
 /* Parse and evaluate a C expression, reading from PFILE.
    Returns the value of the expression.  */
@@ -674,7 +672,7 @@ cpp_parse_expr (
   struct operation *stack = init_stack;
   struct operation *limit = stack + INIT_STACK_SIZE;
   register struct operation *top = stack;
-  int lprio, rprio;
+  int lprio, rprio = 0;
 
   top->rprio = 0;
   top->flags = 0;
@@ -967,7 +965,7 @@ cpp_parse_expr (
          if (top != stack)
            cpp_error (pfile, "internal error in #if expression");
          if (stack != init_stack)
-           free (stack);
+           Safe_free (stack);
          return top->value;
        }
       top++;
@@ -979,10 +977,10 @@ cpp_parse_expr (
          int old_size = (char*)limit - (char*)stack;
          int new_size = 2 * old_size;
          if (stack != init_stack)
-           new_stack = (struct operation*) xrealloc (stack, new_size);
+           new_stack = (struct operation*) Safe_realloc (stack, new_size);
          else
            {
-             new_stack = (struct operation*) xmalloc (new_size);
+             new_stack = (struct operation*) Safe_malloc (new_size);
              bcopy ((char *) stack, (char *) new_stack, old_size);
            }
          stack = new_stack;
@@ -996,7 +994,7 @@ cpp_parse_expr (
     }
  syntax_error:
   if (stack != init_stack)
-    free (stack);
+    Safe_free (stack);
   skip_rest_of_line (pfile);
   return 0;
 }