🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: gnu.gcc.bug
Article #1589

GCC 2.3.3 cpp violates array bounds when given chars with top bit on

#1589
From: Paul Eggert
Date: Wed, 06 Jan 1993 02:25
89 lines
2877 bytes
When given the program

	#if \377
	#endif

where the `\377' stands for a single character with all bits on,
the preprocessor for GCC 2.3.3 (sparc, SunOS 4.1.2) addresses
outside the bounds of an array due to signed character extension.
Here is a patch.

Wed Jan  6 02:16:48 1993  Paul Eggert  (eggert@twinsun.com)

	* cexp.y (yylex): Don't use signed chars to index into arrays;
	they might be negative.

===================================================================
RCS file: cexp.y,v
retrieving revision 2.3
diff -c -r2.3 cexp.y
*** cexp.y	1992/10/21 06:53:52	2.3
--- cexp.y	1993/01/06 02:10:19
***************
*** 467,473 ****
   retry:
  
    tokstart = lexptr;
!   c = *tokstart;
    /* See if it is a special token of length 2.  */
    if (! keyword_parsing)
      for (toktab = tokentab2; toktab->operator != NULL; toktab++)
--- 467,473 ----
   retry:
  
    tokstart = lexptr;
!   c = (unsigned char) *tokstart;
    /* See if it is a special token of length 2.  */
    if (! keyword_parsing)
      for (toktab = tokentab2; toktab->operator != NULL; toktab++)
***************
*** 688,694 ****
    if (c >= '0' && c <= '9' && !keyword_parsing) {
      /* It's a number */
      for (namelen = 0;
! 	 c = tokstart[namelen], is_idchar[c] || c == '.'; 
  	 namelen++)
        ;
      return parse_number (namelen);
--- 688,694 ----
    if (c >= '0' && c <= '9' && !keyword_parsing) {
      /* It's a number */
      for (namelen = 0;
! 	 c = (unsigned char) tokstart[namelen], is_idchar[c] || c == '.'; 
  	 namelen++)
        ;
      return parse_number (namelen);
***************
*** 698,704 ****
  
    if (keyword_parsing) {
      for (namelen = 0;; namelen++) {
!       if (is_hor_space[tokstart[namelen]])
  	break;
        if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
  	break;
--- 698,704 ----
  
    if (keyword_parsing) {
      for (namelen = 0;; namelen++) {
!       if (is_hor_space[(unsigned char) tokstart[namelen]])
  	break;
        if (tokstart[namelen] == '(' || tokstart[namelen] == ')')
  	break;
***************
*** 711,717 ****
        return ERROR;
      }
  
!     for (namelen = 0; is_idchar[tokstart[namelen]]; namelen++)
        ;
    }
    
--- 711,717 ----
        return ERROR;
      }
  
!     for (namelen = 0; is_idchar[(unsigned char) tokstart[namelen]]; namelen++)
        ;
    }
    
Technical Details
Message-ID: <9301060225.AA11612@farside.twinsun.com>
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert

Show Full Headers
Complete Article Headers
Newsgroups: gnu.gcc.bug
Path: arc1-ca.pugleaf.net!sparky!uunet!zaphod.mps.ohio-state.edu!cis.ohio-state.edu!twinsun.COM!eggert
From: eggert@twinsun.COM (Paul Eggert)
Subject: GCC 2.3.3 cpp violates array bounds when given chars with top bit on
Message-ID: <9301060225.AA11612@farside.twinsun.com>
Sender: gnulists@ai.mit.edu
Organization: GNUs Not Usenet
Distribution: gnu
Date: Wed, 6 Jan 1993 02:25:47 GMT
Approved: bug-gcc@prep.ai.mit.edu
Lines: 90