]> andersk Git - splint.git/blobdiff - src/cpplib.c
Fixed localtime/gmtime null anntation.
[splint.git] / src / cpplib.c
index b8837a62d5f78af69c50f8a46723703f8b66287c..5aff1e99c75028d74ffe01e561487b3d32750459 100644 (file)
@@ -1,6 +1,6 @@
 /*
 ** Splint - annotation-assisted static program checker
-** Copyright (C) 1994-2002 University of Virginia,
+** Copyright (C) 1994-2003 University of Virginia,
 **         Massachusetts Institute of Technology
 **
 ** This program is free software; you can redistribute it and/or modify it
@@ -62,22 +62,26 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # endif
 
 # include <string.h>
-
 # if !(defined (WIN32) || defined (OS2) && defined (__IBMC__))
 # include <unistd.h>
 # endif
-
 # include <sys/types.h>
 # include <sys/stat.h>
 # include <fcntl.h>
-
 # if defined (WIN32) || defined (OS2) && defined (__IBMC__)
 # include <io.h>
+/* SMF */
+# ifndef BCC32
 # include <sys/utime.h>                /* for __DATE__ and __TIME__ */
+# endif
+
 # include <time.h>
 # else
 # ifndef VMS
-# ifndef USG
+/*
+** evans 2002-07-03: exception for WATCOM 10.6 compiler suggest by Adam Clarke 
+*/
+# if !defined (USG) && !defined (__WATCOMC__)
 # include <time.h> /* Reported by Paul Smith */
 # include <sys/time.h>
 # include <sys/resource.h>
@@ -93,14 +97,13 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 # include <errno.h>
 
 # include "splintMacros.nf"
-# include "llbasic.h"
+# include "basic.h"
 # include "lcllib.h"
 # include "cpplib.h"
 # include "cpperror.h"
 # include "cpphash.h"
 # include "cppexp.h"
 # include "version.h"
-# include "portab.h"
 # include "osd.h"
 
 /*
@@ -110,6 +113,10 @@ Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 /*@+boolint@*/
 /*@+charint@*/
 
+/* Warnings for using sprintf - suppress them all for now... */
+/*@-bufferoverflowhigh@*/
+/*@-bounds@*/
+
 #define NO_SHORTNAMES
 
 # ifdef open
@@ -148,13 +155,11 @@ static void cpp_setLocation (cppReader *p_pfile)
 
 static enum cpp_token cpp_handleComment (cppReader *p_pfile,
                                         struct parse_marker *p_smark)
-     /*@modifies p_pfile, p_smark@*/;
-
+   /*@modifies p_pfile, p_smark@*/;
+  
 static bool cpp_shouldCheckMacro (cppReader *p_pfile, char *p_p) /*@modifies p_p@*/ ;
 
-static int cppReader_checkMacroNameLoc (fileloc p_loc,
-                                       char *p_symname,
-                                       cstring p_usage) ;
+static size_t cppReader_checkMacroNameLoc (fileloc p_loc, char *p_symname, cstring p_usage) ;
 
 static bool cpp_skipIncludeFile (cstring p_fname) /*@*/ ;
 
@@ -163,7 +168,7 @@ static bool cpp_skipIncludeFile (cstring p_fname) /*@*/ ;
 #endif
 
 /* Symbols to predefine.  */
-
+  
 #ifdef CPP_PREDEFINES
 static /*@observer@*/ char *predefs = CPP_PREDEFINES;
 #else
@@ -196,7 +201,7 @@ static /*@observer@*/ char *predefs = "";
 /*@constant observer char *WCHAR_TYPE@*/
 #define WCHAR_TYPE "int"
 #endif
-
+  
 /* The string value for __USER_LABEL_PREFIX__ */
 
 #ifndef USER_LABEL_PREFIX
@@ -219,7 +224,7 @@ static bool is_idstart[256];
 static bool is_hor_space[256];
 /* table to tell if c is horizontal or vertical space.  */
 static bool is_space[256];
-
+  
 static /*@exposed@*/ /*@null@*/ cppBuffer *
 cppReader_getBuffer (/*@special@*/ cppReader *p_pfile)
      /*@uses p_pfile->buffer@*/
@@ -237,18 +242,28 @@ static int cpp_peekN (cppReader *p_pfile, int p_n) /*@*/ ;
 # define cppBuffer_get(BUFFER) \
   ((BUFFER)->cur < (BUFFER)->rlimit ? *(BUFFER)->cur++ : EOF)
 
+/*@function static int cppBuffer_reachedEOF (sef cppBuffer *p_b) modifies nothing; @*/
+# define cppBuffer_reachedEOF(b) \
+  ((b)->cur < (b)->rlimit ? FALSE : TRUE)
+
 /* Append string STR (of length N) to PFILE's output buffer.  Make space. */
 /*@function static void cppReader_puts (sef cppReader *p_file, char *p_str, sef size_t p_n)
                      modifies *p_file; @*/
 # define cppReader_puts(PFILE, STR, N) \
   cpplib_reserve(PFILE, N), cppReader_putStrN (PFILE, STR,N)
-
+  
 /* Append character CH to PFILE's output buffer.  Assume sufficient space. */
 
 /*@function static void cppReader_putCharQ (cppReader *p_file, char p_ch)
                     modifies *p_file; @*/
 # define cppReader_putCharQ(PFILE, CH) (*(PFILE)->limit++ = (CH))
-
+/*
+static void cppReader_putCharQ (cppReader *p_file, char p_ch)
+{
+  fprintf (stderr, "put char: %c\n", p_ch);
+  (*(p_file)->limit++ = (p_ch));
+}
+*/
 /* Append character CH to PFILE's output buffer.  Make space if need be. */
 
 /*@function static void cppReader_putChar (sef cppReader *p_file, char p_ch)
@@ -288,6 +303,9 @@ static void cppBuffer_forward (cppBuffer *p_buf, int p_n) /*@modifies *p_buf@*/
 /*@function static int cppReader_getC (cppReader *p_pfile) modifies *p_pfile; @*/
 # define cppReader_getC(pfile)   (cppBuffer_get (cppReader_getBufferSafe (pfile)))
 
+/*@function static int cppReader_reachedEOF (sef cppReader *p_pfile) modifies *p_pfile; @*/
+# define cppReader_reachedEOF(pfile)   (cppBuffer_reachedEOF (cppReader_getBufferSafe (pfile)))
+
 /*@function static int cppReader_peekC (cppReader *) modifies nothing;@*/
 # define cppReader_peekC(pfile)  (cpplib_bufPeek (cppReader_getBufferSafe (pfile)))
 
@@ -342,6 +360,8 @@ static void cppReader_scanBuffer (cppReader *p_pfile);
 
 # if defined (WIN32) || defined (OS2) && defined (__IBMC__)
 
+/* SMF */
+# ifndef BCC32
 /*
 ** WIN32 (at least the VC++ include files) does not define mode_t.
 */
@@ -349,6 +369,7 @@ static void cppReader_scanBuffer (cppReader *p_pfile);
 /*@-incondefs@*/ /*@-czechtypes@*/
 typedef unsigned int mode_t;
 /*@=incondefs@*/ /*@=czechtypes@*/
+# endif
 
 # endif
 
@@ -378,7 +399,7 @@ static int /*@alt void@*/ finclude (cppReader *p_pfile, int p_f,
                                    /*@dependent@*/ /*@null@*/ struct file_name_list *p_dirptr);
 
 static void validate_else (cppReader *p_pfile, cstring p_directive);
-
+  
 static void conditional_skip (cppReader *p_pfile, int p_skip,
                              enum node_type p_type,
                              /*@dependent@*/ /*@null@*/ char *p_control_macro);
@@ -462,7 +483,7 @@ static int do_warning (cppReader *, struct directive *, char *, char *);
 /* -I directories are added to the end, then the defaults are added.  */
 
 /*@access cstring@*/
-
+  
 static struct default_include {
   /*@dependent@*/ /*@observer@*/ cstring fname;        /* The name of the directory.  */
   int cplusplus;               /* Only look here if we're compiling C++.  */
@@ -581,7 +602,7 @@ static void
 quote_string (cppReader *pfile, char *src)
 {
   char c;
-
+  
   cppReader_putCharQ (pfile, '\"');
   for (;;)
     {
@@ -722,7 +743,7 @@ cppReader_define (cppReader *pfile, char *str)
   (void) do_define (pfile, NULL, buf, buf + strlen (buf));
   sfree (buf);
 }
-
+  
 /* Append a chain of `struct file_name_list's
    to the end of the main include chain.
    FIRST is gthe beginning of the chain to append, and LAST is the end.  */
@@ -755,11 +776,17 @@ cppReader_appendIncludeChain (cppReader *pfile,
       opts->first_bracket_include = first;
 
       for (dir = first; ; dir = dir->next) {
-       int len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+       size_t len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+
        if (len > pfile->max_include_len)
-         pfile->max_include_len = len;
+         {
+           pfile->max_include_len = len;
+         }
+
        if (dir == last)
-         break;
+         {
+           break;
+         }
       }
     }
 
@@ -767,7 +794,7 @@ cppReader_appendIncludeChain (cppReader *pfile,
   /* last->next = NULL; */
   opts->last_include = last;
 }
-
+  
 # if 0
 static /*@unused@*/ void 
 cppReader_showIncludeChain (cppReader *pfile)
@@ -790,7 +817,7 @@ cppReader_showIncludeChain (cppReader *pfile)
     }
 }
 # endif
-
+  
 cstring 
 cppReader_getIncludePath ()
 {
@@ -815,11 +842,11 @@ cppReader_getIncludePath ()
 }
 
 void
-cppReader_addIncludeChain (cppReader *pfile, struct file_name_list *dir)
+cppReader_addIncludeChain (cppReader *pfile, /*@only@*/ struct file_name_list *dir)
 {
   struct cppOptions *opts = CPPOPTIONS (pfile);
 
-  if (dir == 0)
+  if (dir == NULL)
     {
       return;
     }
@@ -836,8 +863,9 @@ cppReader_addIncludeChain (cppReader *pfile, struct file_name_list *dir)
 
   if (opts->first_bracket_include == 0)
     {
-      int len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
+      size_t len = cstring_length (dir->fname) + INCLUDE_LEN_FUDGE;
       opts->first_bracket_include = dir;
+      
       if (len > pfile->max_include_len)
        {
          pfile->max_include_len = len;
@@ -856,7 +884,7 @@ static void
 path_include (cppReader *pfile, char *path)
 {
   char *p;
-
+  
 #ifdef __CYGWIN32__
   char *win32temp;
 
@@ -912,7 +940,7 @@ path_include (cppReader *pfile, char *path)
       p++;
     }
 }
-
+  
 void
 cppOptions_init (cppOptions *opts)
 {
@@ -942,6 +970,9 @@ cppOptions_init (cppOptions *opts)
   opts->warn_comments = 0;
   opts->warnings_are_errors = 0;
 
+  /* Added 2003-07-10: */
+  opts->traditional = FALSE;
+  opts->c89 = TRUE;
   initialize_char_syntax (opts);
 }
 
@@ -953,7 +984,7 @@ cppReader_nullUnderflow (/*@unused@*/ cppReader *pfile)
 
 void
 cppReader_nullCleanup (/*@unused@*/ cppBuffer *pbuf,
-             /*@unused@*/ cppReader *pfile)
+                      /*@unused@*/ cppReader *pfile)
 {
   ;
 }
@@ -1169,17 +1200,34 @@ copy_rest_of_line (cppReader *pfile)
       llassert (pfile->buffer != NULL);
 
       c = cppReader_getC (pfile);
+
       switch (c)
        {
        case EOF:
          goto end_directive;
        case '\\':
-         if (cppReader_peekC (pfile) == '\n')
+         /*
+         ** Patch from Brian St. Pierre for handling MS-DOS files.
+         */
+
+         DPRINTF (("Reading directive: %d", (int) c));
+
+         if (cppReader_peekC (pfile) == '\n'
+             || cppReader_peekC (pfile) == '\r')
            {
+             DPRINTF (("Reading directive..."));
+             if (cppReader_peekC (pfile) == '\r')
+               {
+                 DPRINTF (("Reading directive..."));
+                 cppReader_forward (pfile, 1);
+               }
+             
+             DPRINTF (("Reading directive..."));
              cppReader_forward (pfile, 1);
              continue;
            }
 
+         DPRINTF (("Falling..."));
        /*@fallthrough@*/ case '\'': case '\"':
          goto scan_directive_token;
 
@@ -1667,7 +1715,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
     /* Handle the start of a symbol.  */
     if (is_idchar[(int) c] && nargs > 0) {
       char *id_beg = p - 1;
-      int id_len;
+      size_t id_len;
 
       --exp_p;
       while (p != limit && is_idchar[(int) *p])
@@ -1675,7 +1723,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
          p++;
        }
 
-      id_len = p - id_beg;
+      id_len = size_fromInt (p - id_beg);
 
       if (is_idstart[(int) c]
          && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '\"'))) {
@@ -1686,7 +1734,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
 
          if (arg->name[0] == c
              && arg->length == id_len
-             && strncmp (arg->name, id_beg, size_fromInt (id_len)) == 0) {
+             && strncmp (arg->name, id_beg, id_len) == 0) {
            char *p1;
 
            if (expected_delimiter && CPPOPTIONS (pfile)->warn_stringify) {
@@ -1782,7 +1830,7 @@ collect_expansion (cppReader *pfile, char *buf, char *limit,
       llfatalbug (cstring_makeLiteral ("Maximum definition size exceeded."));
     }
 
-  return defn;
+  /*@i1@*/ return defn; /* Spurious warning here */
 }
 
 /*
@@ -1846,7 +1894,6 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
   defn->pattern = NULL;
   defn->nargs = nargs;
   defn->predefined = NULL;
-
   exp_p = defn->expansion = (char *) defn + sizeof (*defn);
 
   defn->line = 0;
@@ -1984,7 +2031,7 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
          continue;
        }
        /*@switchbreak@*/ break;
-
+  
       case '/':
        if (expected_delimiter != '\0') /* No comments inside strings.  */
          /*@switchbreak@*/ break;
@@ -2006,7 +2053,7 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
     /* Handle the start of a symbol.  */
     if (is_idchar[(int) c] && nargs > 0) {
       char *id_beg = p - 1;
-      int id_len;
+      size_t id_len;
 
       --exp_p;
       while (p != limit && is_idchar[(int) *p])
@@ -2014,7 +2061,7 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
          p++;
        }
 
-      id_len = p - id_beg;
+      id_len = size_fromInt (p - id_beg);
 
       if (is_idstart[(int) c]
          && ! (id_len == 1 && c == 'L' && (*p == '\'' || *p == '\"'))) {
@@ -2025,7 +2072,7 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
 
          if (arg->name[0] == c
              && arg->length == id_len
-             && strncmp (arg->name, id_beg, size_fromInt (id_len)) == 0) {
+             && strncmp (arg->name, id_beg, id_len) == 0) {
            char *p1;
 
            if (expected_delimiter) { /* && CPPOPTIONS (pfile)->warn_stringify) { */
@@ -2129,7 +2176,7 @@ collect_expansionLoc (fileloc loc, char *buf, char *limit,
       llfatalbug (cstring_makeLiteral ("Maximum definition size exceeded."));
     }
 
-  return defn;
+  /*@i1@*/ return defn; /* Spurious warning here */
 }
 
 /*
@@ -2155,7 +2202,7 @@ static char rest_extension[] = "...";
 /* Create a DEFINITION node from a #define directive.  Arguments are
    as for do_define.  */
 
-
+  
 static /*@null@*/ macroDef
 create_definition (/*@exposed@*/ char *buf, char *limit,
                   cppReader *pfile, bool predefinition,
@@ -2163,7 +2210,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
 {
   char *bp;                    /* temp ptr into input buffer */
   char *symname;               /* remember where symbol name starts */
-  int sym_length;              /* and how long it is */
+  size_t sym_length;           /* and how long it is */
   int rest_args = 0;   /* really int! */
   int line;
   int col;
@@ -2178,7 +2225,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
   DPRINTF (("Create definition: %s", buf));
   *limit = save;
 
-  cppBuffer_lineAndColumn (CPPBUFFER (pfile), &line, &col);
+  cppBuffer_getLineAndColumn (CPPBUFFER (pfile), &line, &col);
 
   bp = buf;
 
@@ -2225,7 +2272,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
        if (!is_idstart[(int) *bp])
          {
            cppReader_pedwarnLit (pfile,
-                           cstring_makeLiteralTemp ("invalid character in macro parameter name"));
+                           cstring_makeLiteralTemp ("Invalid character in macro parameter name"));
          }
 
        /* Find the end of the arg name.  */
@@ -2242,7 +2289,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
              }
          }
 
-       temp->length = bp - temp->name;
+       temp->length = size_fromInt (bp - temp->name);
 
        if (rest_args != 0)
          {
@@ -2273,7 +2320,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
          for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
            {
              if (temp->length == otemp->length &&
-                 strncmp (temp->name, otemp->name, size_fromInt (temp->length)) == 0) {
+                 strncmp (temp->name, otemp->name, temp->length) == 0) {
                cstring name = cstring_copyLength (temp->name, temp->length);
                cppReader_error (pfile,
                           message ("duplicate argument name `%x' in `#define'", name));
@@ -2282,7 +2329,7 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
            }
        }
       }
-
+  
     ++bp;                      /* skip paren */
     SKIP_WHITE_SPACE (bp);
     /* now everything from bp before limit is the definition.  */
@@ -2293,19 +2340,21 @@ create_definition (/*@exposed@*/ char *buf, char *limit,
        the argument names in reverse order
        with comma-space between them.  */
     defn->args.argnames = (char *) dmalloc (size_fromInt (arglengths + 1));
-
+  
     {
       struct arglist *temp;
       int i = 0;
-      for (temp = arg_ptrs; temp != NULL; temp = temp->next) {
-       memcpy (&defn->args.argnames[i], temp->name, size_fromInt (temp->length));
-       i += temp->length;
-       if (temp->next != 0) {
-         defn->args.argnames[i++] = ',';
-         defn->args.argnames[i++] = ' ';
+      for (temp = arg_ptrs; temp != NULL; temp = temp->next) 
+       {
+         memcpy (&defn->args.argnames[i], temp->name, temp->length);
+         i += temp->length;
+         if (temp->next != 0)
+           {
+             defn->args.argnames[i++] = ',';
+             defn->args.argnames[i++] = ' ';
+           }
        }
-      }
-
+      
       defn->args.argnames[i] = '\0';
     }
 
@@ -2377,7 +2426,7 @@ cpplib_createDefinition (cstring def,
   char *limit = buf + cstring_length (def);
   char *bp;                    /* temp ptr into input buffer */
   char *symname;               /* remember where symbol name starts */
-  int sym_length;              /* and how long it is */
+  size_t sym_length;           /* and how long it is */
   int rest_args = 0;   /* really int! */
   int line = fileloc_lineno (loc);
   cstring file = fileloc_filename (loc);
@@ -2412,7 +2461,7 @@ cpplib_createDefinition (cstring def,
   if (*bp == '(') {
     struct arglist *arg_ptrs = NULL;
     int argno = 0;
-
+  
     bp++;                      /* skip '(' */
     SKIP_WHITE_SPACE (bp);
 
@@ -2456,7 +2505,7 @@ cpplib_createDefinition (cstring def,
              }
          }
 
-       temp->length = bp - temp->name;
+       temp->length = size_fromInt (bp - temp->name);
        
        if (rest_args != 0)
          {
@@ -2489,7 +2538,7 @@ cpplib_createDefinition (cstring def,
          for (otemp = temp->next; otemp != NULL; otemp = otemp->next)
            {
              if (temp->length == otemp->length &&
-                 strncmp (temp->name, otemp->name, size_fromInt (temp->length)) == 0) {
+                 strncmp (temp->name, otemp->name, temp->length) == 0) {
                cstring name = cstring_copyLength (temp->name, temp->length);
 
                voptgenerror (FLG_PREPROC,
@@ -2516,7 +2565,7 @@ cpplib_createDefinition (cstring def,
       struct arglist *temp;
       int i = 0;
       for (temp = arg_ptrs; temp != NULL; temp = temp->next) {
-       memcpy (&defn->args.argnames[i], temp->name, size_fromInt (temp->length));
+       memcpy (&defn->args.argnames[i], temp->name, temp->length);
        i += temp->length;
        if (temp->next != 0) {
          defn->args.argnames[i++] = ',';
@@ -2593,9 +2642,7 @@ nope:
 /* Check a purported macro name SYMNAME, and yield its length.
    USAGE is the kind of name this is intended for.  */
 
-int cppReader_checkMacroName (cppReader *pfile,
-                             char *symname,
-                             cstring usage)
+size_t cppReader_checkMacroName (cppReader *pfile, char *symname, cstring usage)
 {
   char *p;
   size_t sym_length;
@@ -2629,17 +2676,15 @@ int cppReader_checkMacroName (cppReader *pfile,
        }
     }
 
-  return size_toInt (sym_length);
+  return sym_length;
 }
-
+  
 /*
 ** evans 2001-12-31
 ** Gasp...cut-and-pasted from above to deal with pfile (should replace throughout with this...)
 */
 
-int cppReader_checkMacroNameLoc (fileloc loc,
-                                char *symname,
-                                cstring usage)
+size_t cppReader_checkMacroNameLoc (fileloc loc, char *symname, cstring usage)
 {
   char *p;
   size_t sym_length;
@@ -2675,9 +2720,9 @@ int cppReader_checkMacroNameLoc (fileloc loc,
        }
     }
 
-  return size_toInt (sym_length);
+  return sym_length;
 }
-
+  
 /* Return zero if two DEFINITIONs are isomorphic.  */
 
 static bool
@@ -2719,21 +2764,23 @@ compare_defs (DEFINITION *d1, DEFINITION *d2)
   if (a1 != a2)
     return TRUE;
 
-  if (comp_def_part (first, p1, d1->length - (p1 - d1->expansion),
-                    p2, d2->length - (p2 - d2->expansion), 1))
+  if (comp_def_part (first, p1, size_toInt (d1->length - (p1 - d1->expansion)),
+                    p2, size_toInt (d2->length - (p2 - d2->expansion)), 1))
     return TRUE;
 
   return FALSE;
 }
 
-/* Return TRUE if two parts of two macro definitions are effectively different.
-   One of the parts starts at BEG1 and has LEN1 chars;
-   the other has LEN2 chars at BEG2.
-   Any sequence of whitespace matches any other sequence of whitespace.
-   FIRST means these parts are the first of a macro definition;
-   so ignore leading whitespace entirely.
-   LAST means these parts are the last of a macro definition;
-   so ignore trailing whitespace entirely.  */
+/*
+** Return TRUE if two parts of two macro definitions are effectively different.
+**    One of the parts starts at BEG1 and has LEN1 chars;
+**    the other has LEN2 chars at BEG2.
+**    Any sequence of whitespace matches any other sequence of whitespace.
+**    FIRST means these parts are the first of a macro definition;
+**    so ignore leading whitespace entirely.
+**    LAST means these parts are the last of a macro definition;
+**    so ignore trailing whitespace entirely.  
+*/
 
 static bool
 comp_def_part (bool first, char *beg1, int len1, char *beg2, int len2, bool last)
@@ -2760,11 +2807,13 @@ comp_def_part (bool first, char *beg1, int len1, char *beg2, int len2, bool last
   return (beg1 != end1) || (beg2 != end2);
 }
 
-/* Process a #define command.
-   BUF points to the contents of the #define command, as a contiguous string.
-   LIMIT points to the first character past the end of the definition.
-   KEYWORD is the keyword-table entry for #define,
-   or NULL for a "predefined" macro.  */
+/* 
+** Process a #define command.
+**    BUF points to the contents of the #define command, as a contiguous string.
+**    LIMIT points to the first character past the end of the definition.
+**    KEYWORD is the keyword-table entry for #define,
+**    or NULL for a "predefined" macro.  
+*/
 
 static int
 do_defineAux (cppReader *pfile, struct directive *keyword,
@@ -2773,8 +2822,6 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
   int hashcode;
   macroDef mdef;
   hashNode hp;
-  
-  DPRINTF (("Define aux: %d", noExpand));
 
   mdef = create_definition (buf, limit, pfile, keyword == NULL, noExpand);
 
@@ -2783,11 +2830,7 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
 
   hashcode = cpphash_hashCode (mdef.symnam, mdef.symlen, CPP_HASHSIZE);
 
-  DPRINTF (("Macro: %s / %s", 
-           cstring_copyLength (mdef.symnam, mdef.symlen),
-           bool_unparse (noExpand)));
-
-  if ((hp = cpphash_lookup (mdef.symnam, mdef.symlen, hashcode)) != NULL)
+  if ((hp = cpphash_lookup (mdef.symnam, size_toInt (mdef.symlen), hashcode)) != NULL)
     {
       bool ok = FALSE;
 
@@ -2801,7 +2844,7 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
       else if (hp->type == T_CONST)
        ok = !CPPOPTIONS (pfile)->done_initializing;
       else {
-       BADBRANCH;
+       ok = FALSE; /* Redefining anything else is bad. */
       }
 
       /* Print the warning if it's not ok.  */
@@ -2844,7 +2887,6 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
                            message ("Macro %q already defined",
                                     cstring_copyLength (mdef.symnam,
                                                         mdef.symlen)));
-
            }
        }
 
@@ -2876,7 +2918,6 @@ do_defineAux (cppReader *pfile, struct directive *keyword,
   return 0;
 
 nope:
-
   return 1;
 }
 
@@ -2888,15 +2929,17 @@ do_define (cppReader *pfile, struct directive *keyword,
   return do_defineAux (pfile, keyword, buf, limit, FALSE);
 }
 
-/* This structure represents one parsed argument in a macro call.
-   `raw' points to the argument text as written (`raw_length' is its length).
-   `expanded' points to the argument's macro-expansion
-   (its length is `expand_length').
-   `stringified_length' is the length the argument would have
-   if stringified.
-   `use_count' is the number of times this macro arg is substituted
-   into the macro.  If the actual use count exceeds 10,
-   the value stored is 10.  */
+/*
+** This structure represents one parsed argument in a macro call.
+** `raw' points to the argument text as written (`raw_length' is its length).
+** `expanded' points to the argument's macro-expansion
+** (its length is `expand_length').
+**  `stringified_length' is the length the argument would have
+** if stringified.
+**  `use_count' is the number of times this macro arg is substituted
+** into the macro.  If the actual use count exceeds 10,
+** the value stored is 10.  
+*/
 
 /* raw and expanded are relative to ARG_BASE */
 /*@notfunction@*/
@@ -2914,15 +2957,17 @@ struct argdata {
   int use_count;
 };
 
-/* Allocate a new cppBuffer for PFILE, and push it on the input buffer stack.
-   If BUFFER != NULL, then use the LENGTH characters in BUFFER
-   as the new input buffer.
-   Return the new buffer, or NULL on failure.  */
+/* 
+** Allocate a new cppBuffer for PFILE, and push it on the input buffer stack.
+**   If BUFFER != NULL, then use the LENGTH characters in BUFFER
+**   as the new input buffer.
+**   Return the new buffer, or NULL on failure.  
+*/
 
 /*@null@*/ /*@exposed@*/ cppBuffer *
 cppReader_pushBuffer (cppReader *pfile, char *buffer, size_t length)
 {
-  cppBuffer *buf = cppReader_getBuffer (pfile);
+  cppBuffer *buf = cppReader_getBufferSafe (pfile);
 
   if (buf == pfile->buffer_stack)
     {
@@ -2940,6 +2985,7 @@ cppReader_pushBuffer (cppReader *pfile, char *buffer, size_t length)
 
   buf--;
   memset ((char *) buf, 0, sizeof (*buf));
+  DPRINTF (("Pushing buffer: %s", cstring_copyLength (buffer, length)));
   CPPBUFFER (pfile) = buf;
 
   buf->if_stack = pfile->if_stack;
@@ -2971,8 +3017,10 @@ cppReader_popBuffer (cppReader *pfile)
   return ++CPPBUFFER (pfile);
 }
 
-/* Scan until CPPBUFFER (PFILE) is exhausted into PFILE->token_buffer.
-   Pop the buffer when done.  */
+/*
+** Scan until CPPBUFFER (PFILE) is exhausted into PFILE->token_buffer.
+** Pop the buffer when done.  
+*/
 
 void
 cppReader_scanBuffer (cppReader *pfile)
@@ -3013,6 +3061,8 @@ cpp_expand_to_buffer (cppReader *pfile, char *buf, size_t length)
   char *limit = buf + length;
   char *buf1, *p1, *p2;
 
+  DPRINTF (("Expand to buffer: %s", cstring_copyLength (buf, length)));
+
   /* evans - 2001-08-26
   ** length is unsigned - this doesn't make sense
   if (length < 0)
@@ -3086,8 +3136,8 @@ update_position (cppBuffer *pbuf)
 }
 
 void
-cppBuffer_lineAndColumn (/*@null@*/ cppBuffer *pbuf, /*@out@*/ int *linep,
-                        /*@null@*/ /*@out@*/ int *colp)
+cppBuffer_getLineAndColumn (/*@null@*/ cppBuffer *pbuf, /*@out@*/ int *linep,
+                           /*@null@*/ /*@out@*/ int *colp)
 {
   int dummy;
 
@@ -3208,8 +3258,7 @@ output_line_command (cppReader *pfile, bool conditional,
       }
   }
 
-  cpplib_reserve (pfile,
-                    size_fromInt (4 * cstring_length (ip->nominal_fname) + 50));
+  cpplib_reserve (pfile, 4 * cstring_length (ip->nominal_fname) + 50);
 
   {
 #ifdef OUTPUT_LINE_COMMANDS
@@ -3427,6 +3476,14 @@ special_symbol (hashNode hp, cppReader *pfile)
        quote_string (pfile, string);
        return;
       }
+    case T_FUNC: /* added in ISO C99 */
+      {
+       /* We don't know the actual name of the function, but it doesn't matter */
+       char *string = "** function-name **";
+       cpplib_reserve (pfile, 3 + 4 * strlen (string));
+       quote_string (pfile, string);
+       return;
+      }
 
     case T_INCLUDE_LEVEL:
       true_indepth = 0;
@@ -3519,7 +3576,7 @@ special_symbol (hashNode hp, cppReader *pfile)
     case T_SPEC_DEFINED:
       buf = cstring_makeLiteral (" 0 ");     /* Assume symbol is not defined */
       ip = cppReader_getBuffer (pfile);
-
+      llassert (ip != NULL);
       llassert (ip->cur != NULL);
       SKIP_WHITE_SPACE (ip->cur);
 
@@ -3567,7 +3624,7 @@ special_symbol (hashNode hp, cppReader *pfile)
       llfatalerror (message ("Pre-processing error: invalid special hash type"));
     }
 
-  len = size_fromInt (cstring_length (buf));
+  len = cstring_length (buf);
 
   cpplib_reserve (pfile, len + 1);
   cppReader_putStrN (pfile, cstring_toCharsSafe (buf), len);
@@ -3648,7 +3705,7 @@ cpplib_installBuiltinType (/*@observer@*/ char *name, ctype ctyp,
   if (!usymtab_existsTypeEither (sname))
     {
       uentry ue = uentry_makeDatatype (sname, ctyp,
-                                      NO, NO,
+                                      NO, qual_createConcrete (),
                                       fileloc_createBuiltin ());
       llassert (!usymtab_existsEither (sname));
       usymtab_addGlobalEntry (ue);
@@ -3664,6 +3721,7 @@ initialize_builtins (cppReader *pfile)
   cpplib_installBuiltin ("__DATE__", ctype_string, -1, T_DATE, 0, NULL, -1);
   cpplib_installBuiltin ("__FILE__", ctype_string, -1, T_FILE, 0, NULL, -1);
   cpplib_installBuiltin ("__BASE_FILE__", ctype_string, -1, T_BASE_FILE, 0, NULL, -1);
+  cpplib_installBuiltin ("__func__", ctype_string, -1, T_FUNC, 0, NULL, -1);
   cpplib_installBuiltin ("__INCLUDE_LEVEL__", ctype_int, -1, T_INCLUDE_LEVEL, 0, NULL, -1);
   cpplib_installBuiltin ("__VERSION__", ctype_string, -1, T_VERSION, 0, NULL, -1);
 #ifndef NO_BUILTIN_SIZE_TYPE
@@ -3677,18 +3735,11 @@ initialize_builtins (cppReader *pfile)
   cpplib_installBuiltin ("__REGISTER_PREFIX__", ctype_string, -1, T_REGISTER_PREFIX_TYPE, 0, NULL, -1);
   cpplib_installBuiltin ("__TIME__", ctype_string, -1, T_TIME, 0, NULL, -1);
 
-  /*
-  ** No, don't define __STDC__
-  **
-
   if (!cppReader_isTraditional (pfile))
     {
       cpplib_installBuiltin ("__STDC__", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
     }
 
-  **
-  */
-
 # ifdef WIN32
     cpplib_installBuiltin ("_WIN32", ctype_int, -1, T_CONST, STDC_VALUE, NULL, -1);
 # endif
@@ -3895,6 +3946,8 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
   char *oxbuf = NULL;
   int start_line;
   int start_column;
+  int end_line;
+  int end_column;
   size_t xbuf_len;
   size_t old_written = cpplib_getWritten (pfile);
   int rest_args;
@@ -3903,8 +3956,8 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
   struct argdata *args = NULL;
 
   pfile->output_escapes++;
-
-  cppBuffer_lineAndColumn (cppReader_fileBuffer (pfile), &start_line, &start_column);
+  cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile), &start_line, &start_column);
+  DPRINTF (("Expand macro: %d:%d", start_line, start_column));
 
   nargs = defn->nargs;
 
@@ -3951,7 +4004,7 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
 
              args[i].raw = size_toLong (cpplib_getWritten (pfile));
              token = macarg (pfile, rest_args);
-             args[i].raw_length = cpplib_getWritten (pfile) - args[i].raw;
+             args[i].raw_length = size_toInt (cpplib_getWritten (pfile) - args[i].raw);
              args[i].newlines = FALSE; /* FIXME */
            }
          else
@@ -4038,6 +4091,14 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
        }
     }
 
+  /*
+  ** If the agrument list was multiple lines, need to insert new lines to keep line
+  ** numbers accurate.
+  */
+
+  cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile), &end_line, &end_column);
+  DPRINTF (("Expand macro: %d:%d", end_line, end_column));
+  
   /* If macro wants zero args, we parsed the arglist for checking only.
      Read directly from the macro definition.  */
 
@@ -4166,9 +4227,8 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
            }
          else if (ap->raw_before || ap->raw_after || cppReader_isTraditional (pfile))
            {
-             /* Add 4 for two newline-space markers to prevent
-                token concatenation.  */
-             assertSet (args); /*@i534 shouldn't need this */
+             /* Add 4 for two newline-space markers to prevent token concatenation. */
+             assertSet (args); /* Splint shouldn't need this */
              xbuf_len += args[ap->argno].raw_length + 4;
            }
          else
@@ -4176,7 +4236,7 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
              /* We have an ordinary (expanded) occurrence of the arg.
                 So compute its expansion, if we have not already.  */
 
-             assertSet (args); /*@i534 shouldn't need this */
+             assertSet (args); /* shouldn't need this */
 
              if (args[ap->argno].expand_length < 0)
                {
@@ -4383,12 +4443,53 @@ cpplib_macroExpand (cppReader *pfile, /*@dependent@*/ hashNode hp)
 
   /* Now put the expansion on the input stack
      so our caller will commence reading from it.  */
+  DPRINTF (("Pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
+  
+  if (end_line != start_line)
+    {
+      /* xbuf must have enough newlines */
+      int newlines = end_line - start_line;
+      int foundnewlines = 0;
+      char *xbufptr = xbuf;
+
+      while ((xbufptr = strchr (xbufptr, '\n')) != NULL && foundnewlines <= newlines)
+       {
+         foundnewlines++;
+         xbufptr++;
+
+         if (*xbufptr == '\0') 
+           {
+             break;
+           }
+       }
+         
+      if (foundnewlines < newlines)
+       {
+         cstring newbuf = cstring_copyLength (xbuf, xbuf_len);
+         
+         while (foundnewlines < newlines)
+           {
+             newbuf = cstring_appendChar (newbuf, '\n');
+             foundnewlines++;
+           }
+
+         sfree (oxbuf);
+         xbuf = cstring_toCharsSafe (newbuf);
+         xbuf_len = cstring_length (newbuf);
+         /*@-branchstate@*/ 
+       } /*@=branchstate@*/ 
+    }
+  
+  DPRINTF (("Pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
+
   push_macro_expansion (pfile, xbuf, xbuf_len, hp);
-  cppReader_getBuffer (pfile)->has_escapes = 1;
+  DPRINTF (("After pushing expansion: %s", cstring_copyLength (xbuf, xbuf_len)));
+  cppReader_getBufferSafe (pfile)->has_escapes = 1;
 
   /* Pop the space we've used in the token_buffer for argument expansion.  */
   cppReader_setWritten (pfile, old_written);
-
+  DPRINTF (("Done set written"));
+  
   /* Recursive macro use sometimes works traditionally.
      #define foo(x,y) bar (x (y,0), y)
      foo (foo, baz)  */
@@ -4438,8 +4539,10 @@ push_macro_expansion (cppReader *pfile, char *xbuf, size_t xbuf_len,
          || xbuf[2] == '\"'))
   {
     llassert (mbuf->cur != NULL);
+    DPRINTF (("Eating: %c", xbuf[2]));
     mbuf->cur += 2;
   }
+  
 }
 
 
@@ -4500,8 +4603,7 @@ do_include (cppReader *pfile, struct directive *keyword,
   struct file_name_list dsp[1];        /* First in chain, if #include "..." */
   struct file_name_list *searchptr = NULL;
   size_t old_written = cpplib_getWritten (pfile);
-
-  int flen;
+  size_t flen;
 
   int f;                       /* file number */
   int angle_brackets = 0;      /* 0 for "...", 1 for <...> */
@@ -4569,8 +4671,8 @@ do_include (cppReader *pfile, struct directive *keyword,
                      /*@=onlytrans@*/
                      nam[n] = save;
 
-                     if (n + INCLUDE_LEN_FUDGE > pfile->max_include_len)
-                       pfile->max_include_len = n + INCLUDE_LEN_FUDGE;
+                     if (n + INCLUDE_LEN_FUDGE > size_toInt (pfile->max_include_len))
+                       pfile->max_include_len = size_fromInt (n + INCLUDE_LEN_FUDGE);
                    }
                  else
                    {
@@ -4664,10 +4766,10 @@ do_include (cppReader *pfile, struct directive *keyword,
            }
        }
     }
-
+  
   cppReader_setWritten (pfile, old_written);
 
-  flen = fend - fbeg;
+  flen = size_fromInt (fend - fbeg);
 
   DPRINTF (("fbeg: %s", fbeg));
 
@@ -4781,7 +4883,7 @@ do_include (cppReader *pfile, struct directive *keyword,
          
          if (f == IMPORT_FOUND)
            {
-             return 0;                 /* Already included this file */
+             return 0; /* Already included this file */
            }
 #ifdef EACCES
          else if (f == IMPORT_NOT_FOUND && errno == EACCES)
@@ -4921,21 +5023,22 @@ is_system_include (cppReader *pfile, cstring filename)
        searchptr != NULL;
        searchptr = searchptr->next)
     {
-      if (!cstring_isEmpty (searchptr->fname)) {
-       cstring sys_dir = searchptr->fname;
-       int length = cstring_length (sys_dir);
-
-       if (cstring_equalLen (sys_dir, filename, length)
-           && osd_isConnectChar (cstring_getChar (filename, length)))
-         {
-           if (searchptr->c_system_include_path)
-             return 2;
-           else
-             return 1;
-         }
-      }
+      if (!cstring_isEmpty (searchptr->fname)) 
+       {
+         cstring sys_dir = searchptr->fname;
+         size_t length = cstring_length (sys_dir);
+         
+         if (cstring_equalLen (sys_dir, filename, length)
+             && osd_isConnectChar (cstring_getChar (filename, length)))
+           {
+             if (searchptr->c_system_include_path)
+               return 2;
+             else
+               return 1;
+           }
+       }
     }
-
+  
   return 0;
 }
 
@@ -5006,6 +5109,7 @@ do_line (cppReader *pfile, /*@unused@*/ struct directive *keyword)
   enum file_change_code file_change = same_file;
   enum cpp_token token;
 
+  llassert (ip != NULL);
   token = get_directive_token (pfile);
 
   if (token != CPP_NUMBER
@@ -5038,7 +5142,7 @@ do_line (cppReader *pfile, /*@unused@*/ struct directive *keyword)
     hashNode *hash_bucket;
     char *p;
     size_t num_start;
-    int fname_length;
+    size_t fname_length;
 
     /* Turn the file name, which is a character string literal,
        into a null-terminated string.  Do this in place.  */
@@ -5050,7 +5154,7 @@ do_line (cppReader *pfile, /*@unused@*/ struct directive *keyword)
        goto bad_line_directive;
       }
 
-    fname_length = end_name - fname;
+    fname_length = size_fromInt (end_name - fname);
     num_start = cpplib_getWritten (pfile);
 
     token = get_directive_token (pfile);
@@ -5092,15 +5196,21 @@ do_line (cppReader *pfile, /*@unused@*/ struct directive *keyword)
 
     hash_bucket =
       &fname_table[cpphash_hashCode (fname, fname_length, FNAME_HASHSIZE)];
+
     for (hp = *hash_bucket; hp != NULL; hp = hp->next)
       {
-       if (hp->length == fname_length &&
-           strncmp (hp->value.cpval, fname, size_fromInt (fname_length)) == 0) {
-         ip->nominal_fname = cstring_fromChars (hp->value.cpval);
-         break;
-       }
+       if (hp->length == fname_length)
+         {
+           llassert (hp->value.cpval != NULL);
+           
+           if (strncmp (hp->value.cpval, fname, fname_length) == 0) 
+             {
+               ip->nominal_fname = cstring_fromChars (hp->value.cpval);
+               break;
+             }
+         }
       }
-
+    
     if (hp == 0) {
       /* Didn't find it; cons up a new one.  */
       hp = (hashNode) dmalloc (sizeof (*hp));
@@ -5115,7 +5225,7 @@ do_line (cppReader *pfile, /*@unused@*/ struct directive *keyword)
 
       hp->length = fname_length;
       hp->value.cpval = dmalloc (sizeof (*hp->value.cpval) * (fname_length + 1));
-      memcpy (hp->value.cpval, fname, size_fromInt (fname_length));
+      memcpy (hp->value.cpval, fname, fname_length);
       hp->value.cpval[fname_length] = '\0';
       ip->nominal_fname = cstring_fromChars (hp->value.cpval);
     }
@@ -5149,7 +5259,7 @@ static int
 do_undef (cppReader *pfile, struct directive *keyword, char *buf, char *limit)
 {
 
-  int sym_length;
+  size_t sym_length;
   hashNode hp;
   char *orig_buf = buf;
 
@@ -5157,7 +5267,7 @@ do_undef (cppReader *pfile, struct directive *keyword, char *buf, char *limit)
 
   sym_length = cppReader_checkMacroName (pfile, buf, cstring_makeLiteralTemp ("macro"));
 
-  while ((hp = cpphash_lookup (buf, sym_length, -1)) != NULL)
+  while ((hp = cpphash_lookup (buf, size_toInt (sym_length), -1)) != NULL)
     {
       /* If we are generating additional info for debugging (with -g) we
         need to pass through all effective #undef commands.  */
@@ -5200,7 +5310,7 @@ static int
 do_error (cppReader *pfile, /*@unused@*/ struct directive *keyword,
          char *buf, char *limit)
 {
-  int length = limit - buf;
+  size_t length = size_fromInt (limit - buf);
   cstring copy = cstring_copyLength (buf, length);
   cstring adv = cstring_advanceWhiteSpace (copy);
 
@@ -5219,7 +5329,7 @@ static int
 do_warning (cppReader *pfile, /*@unused@*/ struct directive *keyword,
            char *buf, char *limit)
 {
-  int length = limit - buf;
+  size_t length = size_fromInt (limit - buf);
   cstring copy = cstring_copyLength (buf, length);
   cstring adv = cstring_advanceWhiteSpace (copy);
   cppReader_warning (pfile, message ("#warning %s", adv));
@@ -5235,7 +5345,8 @@ do_ident (cppReader *pfile, /*@unused@*/ struct directive *keyword,
          /*@unused@*/ char *buf, /*@unused@*/ char *limit)
 {
   /* Allow #ident in system headers, since that's not user's fault.  */
-  if (cppReader_isPedantic (pfile) && !cppReader_getBuffer (pfile)->system_header_p)
+  if (cppReader_isPedantic (pfile) 
+      && !cppReader_getBufferSafe (pfile)->system_header_p)
     cppReader_pedwarnLit (pfile,
                    cstring_makeLiteralTemp ("ANSI C does not allow `#ident'"));
 
@@ -5261,14 +5372,14 @@ do_pragma (cppReader *pfile, /*@unused@*/ struct directive *keyword,
        been included yet.  */
     struct file_name_list *ptr;
     char *p = buf + 14, *fname, *inc_fname;
-    int fname_len;
+    size_t fname_len;
     SKIP_WHITE_SPACE (p);
     if (*p == '\n' || *p != '\"')
       return 0;
 
     fname = p + 1;
     p = (char *) strchr (fname, '\"');
-    fname_len = p != NULL ? p - fname : mstring_length (fname);
+    fname_len = p != NULL ? size_fromInt (p - fname) : mstring_length (fname);
 
     for (ptr = pfile->all_include_files; ptr != NULL; ptr = ptr->next)
       {
@@ -5277,7 +5388,7 @@ do_pragma (cppReader *pfile, /*@unused@*/ struct directive *keyword,
          ? inc_fname + 1 : cstring_toCharsSafe (ptr->fname);
 
        if ((inc_fname != NULL)
-           && (strncmp (inc_fname, fname, size_fromInt (fname_len)) == 0))
+           && (strncmp (inc_fname, fname, fname_len) == 0))
          {
            cpp_setLocation (pfile);
 
@@ -5323,7 +5434,7 @@ do_if (cppReader *pfile, /*@unused@*/ struct directive *keyword,
 static int do_elif (cppReader *pfile, /*@unused@*/ struct directive *keyword,
                    char *buf, char *limit)
 {
-  if (pfile->if_stack == cppReader_getBuffer (pfile)->if_stack)
+  if (pfile->if_stack == cppReader_getBufferSafe (pfile)->if_stack)
     {
       cppReader_errorLit (pfile,
                    cstring_makeLiteralTemp ("Preprocessor command #elif is not within a conditional"));
@@ -5339,9 +5450,9 @@ static int do_elif (cppReader *pfile, /*@unused@*/ struct directive *keyword,
                        cstring_makeLiteralTemp ("`#elif' after `#else'"));
 
          if (pfile->if_stack->fname != NULL
-             && cppReader_getBuffer (pfile)->fname != NULL
+             && cppReader_getBufferSafe (pfile)->fname != NULL
              && !cstring_equal (pfile->if_stack->fname,
-                                cppReader_getBuffer (pfile)->nominal_fname))
+                                cppReader_getBufferSafe (pfile)->nominal_fname))
            fprintf (stderr, ", file %s", cstring_toCharsSafe (pfile->if_stack->fname));
          fprintf (stderr, ")\n");
        }
@@ -5407,9 +5518,9 @@ do_xifdef (cppReader *pfile, struct directive *keyword,
           /*@unused@*/ char *unused1, /*@unused@*/ char *unused2)
 {
   int skip;
-  cppBuffer *ip = cppReader_getBuffer (pfile);
+  cppBuffer *ip = cppReader_getBufferSafe (pfile);
   char *ident;
-  int ident_length;
+  size_t ident_length;
   enum cpp_token token;
   int start_of_file = 0;
   char *control_macro = 0;
@@ -5431,7 +5542,7 @@ do_xifdef (cppReader *pfile, struct directive *keyword,
   ident = pfile->token_buffer + old_written;
   DPRINTF (("Ident: %s", ident));
 
-  ident_length = size_toInt (cpplib_getWritten (pfile) - old_written);
+  ident_length = cpplib_getWritten (pfile) - old_written;
   cppReader_setWritten (pfile, old_written); /* Pop */
 
   if (token == CPP_VSPACE || token == CPP_POP || token == CPP_EOF)
@@ -5445,23 +5556,17 @@ do_xifdef (cppReader *pfile, struct directive *keyword,
     }
   else if (token == CPP_NAME)
     {
-      hashNode hp = cpphash_lookup (ident, ident_length, -1);
-
-      DPRINTF (("Lookup: %s %d", ident, ident_length));
+      hashNode hp = cpphash_lookup (ident, size_toInt (ident_length), -1);
 
-      skip = (keyword->type == T_IFDEF) 
-       ? (hp == NULL) : (hp != NULL);
+      skip = (keyword->type == T_IFDEF) ? (hp == NULL) : (hp != NULL);
       
-      DPRINTF (("hp null: %d / %d / %d",
-               (hp == NULL),
-               (keyword->type == T_IFNDEF),
-               skip));
+      DPRINTF (("hp null: %d / %d / %d", hp == NULL, keyword->type == T_IFNDEF, skip));
       
       if (start_of_file && !skip)
        {
          DPRINTF (("Not skipping!"));
-         control_macro = (char *) dmalloc (size_fromInt (ident_length + 1));
-         memcpy (control_macro, ident, size_fromInt (ident_length + 1));
+         control_macro = (char *) dmalloc (ident_length + 1);
+         memcpy (control_macro, ident, ident_length + 1);
        }
     }
   else
@@ -5505,7 +5610,7 @@ conditional_skip (cppReader *pfile, int skip,
 {
   cppIfStackFrame *temp = (cppIfStackFrame *) dmalloc (sizeof (*temp));
 
-  temp->fname = cppReader_getBuffer (pfile)->nominal_fname;
+  temp->fname = cppReader_getBufferSafe (pfile)->nominal_fname;
   temp->next = pfile->if_stack;
   temp->control_macro = control_macro;
   temp->lineno = 0;
@@ -5554,7 +5659,7 @@ skip_if_group (cppReader *pfile, int any)
 beg_of_line:
   if (CPPOPTIONS (pfile)->output_conditionals)
     {
-      cppBuffer *pbuf = cppReader_getBuffer (pfile);
+      cppBuffer *pbuf = cppReader_getBufferSafe (pfile);
       char *start_line;
 
       llassert (pbuf->buf != NULL);
@@ -5600,7 +5705,7 @@ beg_of_line:
                case T_IFNDEF:
                  temp = (cppIfStackFrame *) dmalloc (sizeof (*temp));
                  temp->next = pfile->if_stack;
-                 temp->fname = cppReader_getBuffer (pfile)->nominal_fname;
+                 temp->fname = cppReader_getBufferSafe (pfile)->nominal_fname;
                  temp->type = kt->type;
                  temp->lineno = 0;
                  temp->if_succeeded = 0;
@@ -5615,7 +5720,7 @@ beg_of_line:
                                   cstring_makeLiteralTemp (kt->type == T_ELSE ? "#else" : "#endif"));
                  /*@fallthrough@*/
                case T_ELIF:
-                 if (pfile->if_stack == cppReader_getBuffer (pfile)->if_stack)
+                 if (pfile->if_stack == cppReader_getBufferSafe (pfile)->if_stack)
                    {
                      cppReader_error (pfile,
                                 message ("Preprocessor command #%s is not within a conditional", kt->name));
@@ -5736,7 +5841,7 @@ do_else (cppReader *pfile, /*@unused@*/ struct directive *keyword,
 
   cppReader_skipRestOfLine (pfile);
 
-  if (pfile->if_stack == cppReader_getBuffer (pfile)->if_stack) {
+  if (pfile->if_stack == cppReader_getBufferSafe (pfile)->if_stack) {
     cppReader_errorLit (pfile,
                  cstring_makeLiteralTemp ("Preprocessor command #else is not within a conditional"));
     return 0;
@@ -5786,7 +5891,7 @@ do_endif (cppReader *pfile, /*@unused@*/ struct directive *keyword,
 
   cppReader_skipRestOfLine (pfile);
 
-  if (pfile->if_stack == cppReader_getBuffer (pfile)->if_stack)
+  if (pfile->if_stack == cppReader_getBufferSafe (pfile)->if_stack)
     {
       cppReader_errorLit (pfile, cstring_makeLiteralTemp ("Unbalanced #endif"));
     }
@@ -5831,7 +5936,7 @@ do_endif (cppReader *pfile, /*@unused@*/ struct directive *keyword,
 
              for ( ; ifile != NULL; ifile = ifile->next)
                {
-                 if (cstring_equal (ifile->fname, cppReader_getBuffer (pfile)->fname))
+                 if (cstring_equal (ifile->fname, cppReader_getBufferSafe (pfile)->fname))
                    {
                      ifile->control_macro = temp->control_macro;
                      break;
@@ -5888,7 +5993,7 @@ cpplib_getTokenAux (cppReader *pfile, bool forceExpand)
   int start_line, start_column;
   enum cpp_token token;
   struct cppOptions *opts = CPPOPTIONS (pfile);
-  cppReader_getBuffer (pfile)->prev = cppReader_getBuffer (pfile)->cur;
+  cppReader_getBufferSafe (pfile)->prev = cppReader_getBufferSafe (pfile)->cur;
 
 get_next:
   c = cppReader_getC (pfile);
@@ -5897,7 +6002,7 @@ get_next:
   if (c == EOF)
     {
     handle_eof:
-      if (cppReader_getBuffer (pfile)->seen_eof)
+      if (cppReader_getBufferSafe (pfile)->seen_eof)
        {
          cppBuffer *buf = cppReader_popBuffer (pfile);
 
@@ -5912,10 +6017,10 @@ get_next:
        }
       else
        {
-         cppBuffer *next_buf = cppBuffer_prevBuffer (cppReader_getBuffer (pfile));
-         cppReader_getBuffer (pfile)->seen_eof = 1;
+         cppBuffer *next_buf = cppBuffer_prevBuffer (cppReader_getBufferSafe (pfile));
+         cppReader_getBufferSafe (pfile)->seen_eof = 1;
 
-         if (cstring_isDefined (cppReader_getBuffer (pfile)->nominal_fname)
+         if (cstring_isDefined (cppReader_getBufferSafe (pfile)->nominal_fname)
              && next_buf != cppReader_nullBuffer (pfile))
            {
              /* We're about to return from an #include file.
@@ -5949,10 +6054,10 @@ get_next:
            }
 
          newlines = 0;
-         cppBuffer_lineAndColumn (cppReader_fileBuffer (pfile),
+         cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile),
                                   &start_line, &start_column);
          c = skip_comment (pfile, &newlines);
-
+         DPRINTF (("c = %c", c));
          if (opts->put_out_comments && (c == '/' || c == EOF))
            {
              assertSet (&start_mark);
@@ -6010,16 +6115,22 @@ get_next:
        case '\'':
          /* A single quoted string is treated like a double -- some
             programs (e.g., troff) are perverse this way */
-         cppBuffer_lineAndColumn (cppReader_fileBuffer (pfile),
-                                  &start_line, &start_column);
+         cppBuffer_getLineAndColumn (cppReader_fileBuffer (pfile),
+                                     &start_line, &start_column);
          old_written = cpplib_getWritten (pfile);
        string:
+         DPRINTF (("Reading string: %c", c));
          cppReader_putChar (pfile, c);
          while (TRUE)
            {
-             int cc = cppReader_getC (pfile);
-             if (cc == EOF)
+             /* evans-2003-06-07
+             ** Because of ISO8859-1 characters in string literals, we need a special test here.
+             */
+
+             if (cppReader_reachedEOF (pfile)) 
                {
+                 
+                 DPRINTF (("Matches EOF!"));
                  if (cppBuffer_isMacro (CPPBUFFER (pfile)))
                    {
                      /* try harder: this string crosses a macro expansion
@@ -6027,19 +6138,20 @@ get_next:
                         Otherwise, only -D can make a macro with an unmatched
                         quote.  */
                      cppBuffer *next_buf
-                       = cppBuffer_prevBuffer (cppReader_getBuffer (pfile));
-                     (*cppReader_getBuffer (pfile)->cleanup)
-                       (cppReader_getBuffer (pfile), pfile);
+                       = cppBuffer_prevBuffer (cppReader_getBufferSafe (pfile));
+                     (*cppReader_getBufferSafe (pfile)->cleanup)
+                       (cppReader_getBufferSafe (pfile), pfile);
                      CPPBUFFER (pfile) = next_buf;
                      continue;
                    }
+                 
                  if (!cppReader_isTraditional (pfile))
                    {
                      cpp_setLocation (pfile);
 
                      setLine (long_toInt (start_line));
                      setColumn (long_toInt (start_column));
-
+                     
                      if (pfile->multiline_string_line != long_toInt (start_line)
                          && pfile->multiline_string_line != 0)
                        {
@@ -6059,58 +6171,64 @@ get_next:
                             message ("Unterminated string or character constant"));
                        }
                    }
-                 /*@loopbreak@*/ break;
-               }
-             cppReader_putChar (pfile, cc);
-             switch (cc)
+                 /*@loopbreak@*/ break;                  
+               } 
+             else
                {
-               case '\n':
-                 /* Traditionally, end of line ends a string constant with
-                    no error.  So exit the loop and record the new line.  */
-                 if (cppReader_isTraditional (pfile))
-                   goto while2end;
-                 if (c == '\'')
-                   {
-                     goto while2end;
-                   }
-                 if (cppReader_isPedantic (pfile)
-                     && pfile->multiline_string_line == 0)
-                   {
-                     cppReader_pedwarnWithLine
-                       (pfile, long_toInt (start_line),
-                        long_toInt (start_column),
-                        cstring_makeLiteral ("String constant runs past end of line"));
-                   }
-                 if (pfile->multiline_string_line == 0)
+                 int cc = cppReader_getC (pfile); 
+                 DPRINTF (("cc: %c [%d] [%d]", cc, cc, EOF));
+                 DPRINTF (("putting char: %c", cc));
+                 cppReader_putChar (pfile, cc);
+                 switch (cc)
                    {
-                     pfile->multiline_string_line = start_line;
-                   }
-
-                 /*@switchbreak@*/ break;
-
-               case '\\':
-                 cc = cppReader_getC (pfile);
-                 if (cc == '\n')
-                   {
-                     /* Backslash newline is replaced by nothing at all.  */
-                     cppReader_adjustWritten (pfile, -1);
-                     pfile->lineno++;
-                   }
-                 else
-                   {
-                     /* ANSI stupidly requires that in \\ the second \
-                        is *not* prevented from combining with a newline.  */
-                     NEWLINE_FIX1(cc);
-                     if (cc != EOF)
-                       cppReader_putChar (pfile, cc);
+                   case '\n':
+                     /* Traditionally, end of line ends a string constant with
+                        no error.  So exit the loop and record the new line.  */
+                     if (cppReader_isTraditional (pfile))
+                       goto while2end;
+                     if (c == '\'')
+                       {
+                         goto while2end;
+                       }
+                     if (cppReader_isPedantic (pfile)
+                         && pfile->multiline_string_line == 0)
+                       {
+                         cppReader_pedwarnWithLine
+                           (pfile, long_toInt (start_line),
+                            long_toInt (start_column),
+                            cstring_makeLiteral ("String constant runs past end of line"));
+                       }
+                     if (pfile->multiline_string_line == 0)
+                       {
+                         pfile->multiline_string_line = start_line;
+                       }
+                     
+                     /*@switchbreak@*/ break;
+                     
+                   case '\\':
+                     cc = cppReader_getC (pfile);
+                     if (cc == '\n')
+                       {
+                         /* Backslash newline is replaced by nothing at all.  */
+                         cppReader_adjustWritten (pfile, -1);
+                         pfile->lineno++;
+                       }
+                     else
+                       {
+                         /* ANSI stupidly requires that in \\ the second \
+                            is *not* prevented from combining with a newline.  */
+                         NEWLINE_FIX1(cc);
+                         if (cc != EOF)
+                           cppReader_putChar (pfile, cc);
+                       }
+                     /*@switchbreak@*/ break;
+                     
+                   case '\"':
+                   case '\'':
+                     if (cc == c)
+                       goto while2end;
+                     /*@switchbreak@*/ break;
                    }
-                 /*@switchbreak@*/ break;
-
-               case '\"':
-               case '\'':
-                 if (cc == c)
-                   goto while2end;
-                 /*@switchbreak@*/ break;
                }
            }
        while2end:
@@ -6220,9 +6338,11 @@ get_next:
          return CPP_OTHER;
 
        case '@':
-         if (cppReader_getBuffer (pfile)->has_escapes)
+         DPRINTF (("Macro @!"));
+         if (cppReader_getBufferSafe (pfile)->has_escapes)
            {
              c = cppReader_getC (pfile);
+             DPRINTF (("got c: %c", c));
              if (c == '-')
                {
                  if (pfile->output_escapes)
@@ -6276,10 +6396,20 @@ get_next:
        op2:
          token = CPP_OTHER;
          pfile->only_seen_white = 0;
-        op2any:
+        op2any: /* jumped to for \ continuations */
          cpplib_reserve(pfile, 3);
          cppReader_putCharQ (pfile, c);
-         cppReader_putCharQ (pfile, cppReader_getC (pfile));
+
+         /* evans 2003-08-24: This is a hack to fix line output for \
+            continuations.  Someday I really should get a decent pre-processor! 
+         */
+
+         if (c == '\\') {
+           (void) cppReader_getC (pfile); /* skip the newline to avoid extra lines */
+         } else {
+           cppReader_putCharQ (pfile, cppReader_getC (pfile)); 
+         }
+
          cppReader_nullTerminateQ (pfile);
          return token;
 
@@ -6375,7 +6505,7 @@ get_next:
            hashNode hp;
            char *ident;
            size_t before_name_written = cpplib_getWritten (pfile);
-           int ident_len;
+           size_t ident_len;
            parse_name (pfile, c);
            pfile->only_seen_white = 0;
 
@@ -6388,9 +6518,9 @@ get_next:
            ident = pfile->token_buffer + before_name_written;
            DPRINTF (("Ident: %s", ident));
 
-           ident_len = (cpplib_getPWritten (pfile)) - ident;
+           ident_len = size_fromInt ((cpplib_getPWritten (pfile)) - ident);
 
-           hp = cpphash_lookupExpand (ident, ident_len, -1, forceExpand);
+           hp = cpphash_lookupExpand (ident, size_toInt (ident_len), -1, forceExpand);
 
            if (hp == NULL)
              {
@@ -6409,7 +6539,7 @@ get_next:
                    ident = pfile->token_buffer + before_name_written;
                    cppReader_adjustWritten (pfile, 2);
 
-                   for (i = ident_len; i >= 0; i--)
+                   for (i = size_toInt (ident_len); i >= 0; i--)
                      {
                        ident[i+2] = ident[i];
                      }
@@ -6432,26 +6562,38 @@ get_next:
                struct parse_marker macro_mark;
                int is_macro_call;
 
+               DPRINTF (("Arglist macro!"));
+
+               /*
+               ** evans 2002-07-03: Moved this here (from below).
+               **   This bug caused necessary whitespace to be lost
+               **   when parsing parameterized macros without parameters.
+               */
+
+               parseSetMark (&macro_mark, pfile); 
+
                while (cppBuffer_isMacro (CPPBUFFER (pfile)))
                  {
                    cppBuffer *next_buf;
                    cppSkipHspace (pfile);
                    if (cppReader_peekC (pfile) != EOF)
                      {
+                       DPRINTF (("Peeking!"));
                        /*@loopbreak@*/ break;
                      }
 
-                 next_buf = cppBuffer_prevBuffer (cppReader_getBuffer (pfile));
-                 (*cppReader_getBuffer (pfile)->cleanup) (cppReader_getBuffer (pfile), pfile);
+                 next_buf = cppBuffer_prevBuffer (cppReader_getBufferSafe (pfile));
+                 (*cppReader_getBufferSafe (pfile)->cleanup) (cppReader_getBufferSafe (pfile), pfile);
                  CPPBUFFER (pfile) = next_buf;
                  }
 
-               parseSetMark (&macro_mark, pfile);
+               /* parseSetMark (&macro_mark, pfile); */
 
                for (;;)
                  {
                    cppSkipHspace (pfile);
                    c = cppReader_peekC (pfile);
+                   DPRINTF (("c: %c", c));
                    is_macro_call = c == '(';
                    if (c != '\n')
                      /*@loopbreak@*/ break;
@@ -6467,9 +6609,11 @@ get_next:
 
                if (!is_macro_call)
                  {
+                   DPRINTF (("not macro call!"));
                    return CPP_NAME;
                  }
              }
+
            /* This is now known to be a macro call.  */
 
            /* it might not actually be a macro.  */
@@ -6531,6 +6675,8 @@ get_next:
 
         case '\\':
          c2 = cppReader_peekC (pfile);
+         /* allow other stuff here if a flag is set? */
+         DPRINTF (("Got continuation!"));
          if (c2 != '\n')
            goto randomchar;
          token = CPP_HSPACE;
@@ -6655,9 +6801,9 @@ static cstring read_filename_string (int ch, /*:open:*/ FILE *f)
 
 struct file_name_map_list
 {
-  struct file_name_map_list *map_list_next;
-  cstring map_list_name;
-  struct file_name_map *map_list_map;
+  /*@only@*/ struct file_name_map_list *map_list_next;
+  /*@only@*/ cstring map_list_name;
+  /*@null@*/ struct file_name_map *map_list_map;
 };
 
 /* Read the file name map file for DIRNAME.  */
@@ -6692,7 +6838,7 @@ read_name_map (cppReader *pfile, cstring dirname)
 
   name = cstring_concatFree1 (name, cstring_makeLiteralTemp (FILE_NAME_MAP_FILE));
 
-  f = fileTable_openFile (context_fileTable (), name, "r");
+  f = fileTable_openReadFile (context_fileTable (), name);
   cstring_free (name);
 
   if (f == NULL)
@@ -6845,7 +6991,7 @@ open_include_file (cppReader *pfile,
 
   if ((searchptr != NULL)
       && (cstring_isDefined (searchptr->fname))
-      && (cstring_length (searchptr->fname) == p - filename)
+      && (size_toInt (cstring_length (searchptr->fname)) == p - filename)
       && !strncmp (cstring_toCharsSafe (searchptr->fname),
                   filename,
                   size_fromInt (p - filename)))
@@ -6939,7 +7085,7 @@ finclude (cppReader *pfile, int f,
       /*@=mustfree@*/
     }
 
-  fp = cppReader_getBuffer (pfile);
+  fp = cppReader_getBufferSafe (pfile);
 
   /*@-temptrans@*/ /* fname shouldn't really be temp */
   fp->nominal_fname = fp->fname = fname;
@@ -6967,7 +7113,7 @@ finclude (cppReader *pfile, int f,
   else if (S_ISDIR (st_mode))
     {
       cppReader_error (pfile,
-                      message ("Directory specified in #include: %s", fname));
+                      message ("Directory specified where file is expected: %s", fname));
       check (close (f) == 0);
       return 0;
     }
@@ -7064,8 +7210,12 @@ cppReader_finish (/*@unused@*/ cppReader *pfile)
    This is the cppReader 'finalizer' or 'destructor' (in C++ terminology).  */
 
 void
-cppCleanup (cppReader *pfile)
+cppCleanup (/*@special@*/ cppReader *pfile) 
+     /*@uses pfile@*/
+     /*@releases pfile@*/
 {
+  DPRINTF (("cppCleanup!"));
+
   while (CPPBUFFER (pfile) != cppReader_nullBuffer (pfile))
     {
       (void) cppReader_popBuffer (pfile);
@@ -7094,6 +7244,25 @@ cppCleanup (cppReader *pfile)
       sfree (temp);
     }
 
+  /* evans 2002-07-12 */
+  while (pfile->opts->map_list != NULL)
+    {
+      struct file_name_map_list *temp = pfile->opts->map_list;
+      pfile->opts->map_list = pfile->opts->map_list->map_list_next;
+      cstring_free (temp->map_list_name);
+      sfree (temp);
+    }
+
+  while (pfile->opts->include != NULL)
+    {
+      struct file_name_list *temp = pfile->opts->include;
+      pfile->opts->include = pfile->opts->include->next;
+      /* cstring_free (temp->fname); */
+      sfree (temp);
+    }
+
+  sfree (pfile->opts);
+  pfile->opts = NULL;
   cppReader_hashCleanup ();
 }
 
@@ -7170,7 +7339,7 @@ static int safe_read (int desc, char *ptr, int len)
 void
 parseSetMark (struct parse_marker *pmark, cppReader *pfile)
 {
-  cppBuffer *pbuf = cppReader_getBuffer (pfile);
+  cppBuffer *pbuf = cppReader_getBufferSafe (pfile);
 
   pmark->next = pbuf->marks;
   /*@-temptrans@*/
@@ -7179,6 +7348,7 @@ parseSetMark (struct parse_marker *pmark, cppReader *pfile)
 
   pmark->buf = pbuf;
   pmark->position = pbuf->cur - pbuf->buf;
+  DPRINTF (("set mark: %d / %s", pmark->position, pbuf->cur));
 }
 
 /* Cleanup PMARK - we no longer need it.  */
@@ -7201,7 +7371,7 @@ void parseClearMark (struct parse_marker *pmark)
 void
 parseGotoMark (struct parse_marker *pmark, cppReader *pfile)
 {
-  cppBuffer *pbuf = cppReader_getBuffer (pfile);
+  cppBuffer *pbuf = cppReader_getBufferSafe (pfile);
 
   if (pbuf != pmark->buf)
     {
@@ -7211,6 +7381,7 @@ parseGotoMark (struct parse_marker *pmark, cppReader *pfile)
 
   llassert (pbuf->buf != NULL);
   pbuf->cur = pbuf->buf + pmark->position;
+  DPRINTF (("goto mark: %d / %s", pmark->position, pbuf->cur));
 }
 
 /* Reset PMARK to point to the current position of PFILE.  (Same
@@ -7219,7 +7390,7 @@ parseGotoMark (struct parse_marker *pmark, cppReader *pfile)
 void
 parseMoveMark (struct parse_marker *pmark, cppReader *pfile)
 {
-  cppBuffer *pbuf = cppReader_getBuffer (pfile);
+  cppBuffer *pbuf = cppReader_getBufferSafe (pfile);
 
   if (pbuf != pmark->buf)
     {
@@ -7228,6 +7399,7 @@ parseMoveMark (struct parse_marker *pmark, cppReader *pfile)
     }
 
   pmark->position = pbuf->cur - pbuf->buf;
+  DPRINTF (("move mark: %s", pmark->position));
 }
 
 void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is loaded. */
@@ -7410,24 +7582,26 @@ void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is
 
   cppReader_appendIncludeChain (pfile, opts->before_system,
                                opts->last_before_system);
+
   opts->first_system_include = opts->before_system;
 
   /* Unless -fnostdinc,
      tack on the standard include file dirs to the specified list */
+
   if (!opts->no_standard_includes) {
     struct default_include *p = include_defaults;
     char *specd_prefix = opts->include_prefix;
     char *default_prefix = mstring_copy (GCC_INCLUDE_DIR);
-    int default_len = 0;
-
-       /* Remove the `include' from /usr/local/lib/gcc.../include.  */
-       if (default_prefix != NULL) {
-    if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
-      default_len = strlen (default_prefix) - 7;
-      default_prefix[default_len] = 0;
+    size_t default_len = 0;
+    
+    /* Remove the `include' from /usr/local/lib/gcc.../include.  */
+    if (default_prefix != NULL) {
+      if (!strcmp (default_prefix + strlen (default_prefix) - 8, "/include")) {
+       default_len = strlen (default_prefix) - 7;
+       default_prefix[default_len] = 0;
+      }
     }
-       }
-
+    
     /* Search "translated" versions of GNU directories.
        These have /usr/local/lib/gcc... replaced by specd_prefix.  */
     if (specd_prefix != 0 && default_len != 0)
@@ -7436,8 +7610,9 @@ void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is
        if (!p->cplusplus
            || (opts->cplusplus && !opts->no_standard_cplusplus_includes)) {
          /* Does this dir start with the prefix?  */
-         if (!strncmp (cstring_toCharsSafe (p->fname), default_prefix,
-                       size_fromInt (default_len)))
+         llassert (default_prefix != NULL);
+
+         if (!strncmp (cstring_toCharsSafe (p->fname), default_prefix, default_len))
            {
              /* Yes; change prefix and add to search list.  */
              struct file_name_list *nlist
@@ -7453,15 +7628,16 @@ void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is
              nlist->c_system_include_path = !p->cxx_aware;
              nlist->got_name_map = 0;
 
-             cppReader_addIncludeChain (pfile, nlist);
              if (opts->first_system_include == 0)
                {
                  opts->first_system_include = nlist;
                }
+         
+             cppReader_addIncludeChain (pfile, nlist);
            }
        }
       }
-
+    
     /* Search ordinary names for GNU include directories.  */
 
     for (p = include_defaults; p->fname != NULL; p++)
@@ -7478,12 +7654,14 @@ void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is
            nlist->got_name_map = 0;
            nlist->next = NULL;
 
-           cppReader_addIncludeChain (pfile, nlist);
-
-           if (opts->first_system_include == 0)
+           /* Spurious warning reported for opts->first_system_include */
+           /*@-usereleased@*/ if (opts->first_system_include == NULL) 
              {
                opts->first_system_include = nlist;
              }
+           /*@=usereleased@*/
+
+           cppReader_addIncludeChain (pfile, nlist);
          }
       }
     sfree (default_prefix);
@@ -7493,11 +7671,14 @@ void cpplib_initializeReader (cppReader *pfile) /* Must be done after library is
   cppReader_appendIncludeChain (pfile, opts->after_include,
                                opts->last_after_include);
 
-  if (opts->first_system_include == 0)
+  /* Spurious warnings for opts->first_system_include */
+  /*@-usereleased@*/
+  if (opts->first_system_include == NULL)
     {
       opts->first_system_include = opts->after_include;
     }
-
+  /*@=usereleased@*/
+  
   /* With -v, print the list of dirs to search.  */
   if (opts->verbose) {
     struct file_name_list *p;
@@ -7624,9 +7805,9 @@ static void cpp_setLocation (cppReader *pfile)
 
   if (pfile->buffer != NULL)
     {
-      if (cstring_isDefined (cppReader_getBuffer (pfile)->nominal_fname))
+      if (cstring_isDefined (cppReader_getBufferSafe (pfile)->nominal_fname))
        {
-         cstring fname = cppReader_getBuffer (pfile)->nominal_fname;
+         cstring fname = cppReader_getBufferSafe (pfile)->nominal_fname;
          
          DPRINTF (("Looking up: %s", fname));
          
@@ -7639,16 +7820,16 @@ static void cpp_setLocation (cppReader *pfile)
              DPRINTF (("Trying %s", cppReader_getBuffer (pfile)->fname));
 
              fid = fileTable_lookup (context_fileTable (),
-                                     cppReader_getBuffer (pfile)->fname);
+                                     cppReader_getBufferSafe (pfile)->fname);
            }
        }
       else
        {
          fid = fileTable_lookup (context_fileTable (),
-                                 cppReader_getBuffer (pfile)->fname);
+                                 cppReader_getBufferSafe (pfile)->fname);
        }
       
-      line = cppReader_getBuffer (pfile)->lineno;
+      line = cppReader_getBufferSafe (pfile)->lineno;
       fileloc_free (g_currentloc);
 
       if (fileId_isValid (fid))
@@ -7946,9 +8127,10 @@ static bool cpp_shouldCheckMacro (cppReader *pfile, char *p) /*@modifies p*/
 static enum cpp_token
 cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
 {
-  cppBuffer *pbuf = cppReader_getBuffer (pfile);
+  cppBuffer *pbuf = cppReader_getBufferSafe (pfile);
   char *start;
   int len;
+  fileloc loc;
   bool eliminateComment = FALSE;
 
   llassert (pbuf->buf != NULL);
@@ -7965,6 +8147,9 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
       char c = ' ';
       char *scomment = start + 2;
       char savec = start[len];
+      
+      cpp_setLocation (pfile);
+      loc = fileloc_copy (g_currentloc);
 
       start[0] = BEFORE_COMMENT_MARKER[0];
       start[1] = BEFORE_COMMENT_MARKER[1];
@@ -7997,14 +8182,14 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
        {
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
-             context_enterSuppressRegion ();
+             context_enterSuppressRegion (loc);
            }
        }
       else if (mstring_equalPrefix (scomment, "end"))
        {
          if (!context_getFlag (FLG_NOCOMMENTS))
            {
-             context_exitSuppressRegion ();
+             context_exitSuppressRegion (loc);
            }
        }
       else if (mstring_equalPrefix (scomment, "notparseable"))
@@ -8084,27 +8269,32 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
                {
                  /* fix from Mike Miller <MikeM@xata.com> */
                  context_fileSetFlag (FLG_NESTCOMMENT,
-                                      ynm_fromCodeChar (sChar));
+                                      ynm_fromCodeChar (sChar),
+                                      loc);
                }
              else if (mstring_equalPrefix (rest, "namechecks"))
                {
                  context_fileSetFlag (FLG_NAMECHECKS,
-                                      ynm_fromCodeChar (sChar));
+                                      ynm_fromCodeChar (sChar),
+                                      loc);
                }
              else if (mstring_equalPrefix (rest, "macroredef"))
                {
                  context_fileSetFlag (FLG_MACROREDEF,
-                                      ynm_fromCodeChar (sChar));
+                                      ynm_fromCodeChar (sChar),
+                                      loc);
                }
              else if (mstring_equalPrefix (rest, "usevarargs"))
                {
                  context_fileSetFlag (FLG_USEVARARGS,
-                                      ynm_fromCodeChar (sChar));
+                                      ynm_fromCodeChar (sChar),
+                                      loc);
                }
              else if (mstring_equalPrefix (rest, "nextlinemacros"))
                {
                  context_fileSetFlag (FLG_MACRONEXTLINE,
-                                      ynm_fromCodeChar (sChar));
+                                      ynm_fromCodeChar (sChar),
+                                      loc);
                }
              else if (mstring_equalPrefix (rest, "allmacros")
                       || mstring_equalPrefix (rest, "fcnmacros")
@@ -8126,8 +8316,7 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
                      fl = FLG_CONSTMACROS;
                    }
 
-
-                 context_fileSetFlag (fl, ynm_fromCodeChar (sChar));
+                 context_fileSetFlag (fl, ynm_fromCodeChar (sChar), loc);
                  notfunction = FALSE;
                }
              else
@@ -8213,11 +8402,11 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
            c = BEFORE_COMMENT_MARKER[0];
            start[0] = BEFORE_COMMENT_MARKER[1];
 
-           llassert (cstring_length (lintcomment) == len - 3);
+           llassert (size_toLong (cstring_length (lintcomment)) == len - 3);
 
            for (i = 1; i < len - 2; i++)
              {
-               start[i] = cstring_getChar (lintcomment, i);
+               start[i] = cstring_getChar (lintcomment, size_fromInt (i));
              }
            
            start[len - 2] = AFTER_COMMENT_MARKER[0];
@@ -8231,9 +8420,10 @@ cpp_handleComment (cppReader *pfile, struct parse_marker *smark)
                if (start[i] == '/'
                    && i < len - 1
                    && start[i + 1] == '*') {
-                 (void) cppoptgenerror (FLG_NESTCOMMENT,
-                                        message ("Comment starts inside comment"),
-                                        pfile);
+                 (void) cppoptgenerror 
+                   (FLG_NESTCOMMENT,
+                    message ("Comment starts inside comment"),
+                    pfile);
                }
                
                if (start[i] != '\n')
@@ -8300,8 +8490,27 @@ static bool cpp_skipIncludeFile (cstring fname)
       
       if (context_getFlag (FLG_SKIPSYSHEADERS))
        {
-         DPRINTF (("Skip include TRUE: %s", fname));
-         return TRUE;
+         /*
+         ** 2003-04-18: Patch from Randal Parsons
+         */
+
+         /*
+         ** Don't skip include file unless the file actually exists.  
+         ** It may be in a different directory.
+         */
+
+         int f = open (cstring_toCharsSafe (fname), O_RDONLY, 0666);
+
+         if (f >= 0)
+           {
+             check (close (f) == 0);
+             DPRINTF (("Skip include TRUE: %s", fname));
+             return TRUE;
+           }
+         else
+           {
+             /* Keep looking... */
+           }
        }
     }
 
@@ -8326,7 +8535,7 @@ static bool cpp_skipIncludeFile (cstring fname)
 
 static int cpp_peekN (cppReader *pfile, int n)
 {
-  cppBuffer *buf = cppReader_getBuffer (pfile);
+  cppBuffer *buf = cppReader_getBufferSafe (pfile);
 
   llassert (buf->cur != NULL);
 
@@ -8345,3 +8554,6 @@ void cppBuffer_forward (cppBuffer *buf, int n)
   llassert (buf->cur != NULL);
   buf->cur += n;
 }
+
+/*@=bufferoverflowhigh@*/
+/*@=bounds@*/
This page took 0.182783 seconds and 4 git commands to generate.