This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: fixincl recently broken, char_macro_def/char_macro_use don't work


 > From: Bruce Korb <bkorb@sco.COM>
 > > 
 > > Okay, thanks for agreeing to take a look.  If you can't figure it out,
 > > I think it would be reasonable to revert this stuff back to a working
 > > state until we understand what's wrong.  At the moment, probably any
 > > platform needing the char macro fixes retains its traditional style
 > > definitions.
 > 
 > Too late.  I fixed it last night and just checked it in.

Of course, fixing it is preferable to reverting. :-)  Thanks!


 > The problem was that the "IO" and "CTRL" strings get
 > passed in as p_fixd->patch_args[1] and the code was indexing
 > with zero  :-(.  Also, after focusing on the code for too
 > long, my itchy fingers rewrote it to use a regex to parse
 > the #define-s.

I think I found two problems, one is that you rely on the return value
of sprintf which is char* on older systems like sunos4 and returns the
buffer pointer.  This causes every call to fail because you check
whether the number of characters written overwrites a max capacity,
but of course we are getting some high pointer address instead.  Since
you are linking with libiberty, I switched it to use asprintf.  Patch
is below.

The second problem is that I'm getting some failures which look like
this:

 > Applying io_quotes_def            to sys/ioccom.h
 > Match error 1:
 > ^#[ 	]*define[ 	]+[_A-Z][A-Z0-9_]*IO[A-Z]*\(([a-zA-Z])[^a-zA-Z0-9_][^)]*\)[ 	]+\([ 	(]*'([a-zA-Z])'
 > Applying ctrl_quotes_use          to sys/termios.h
 > Match error 1:
 > ^#[ 	]*define[ 	]+[_A-Z][A-Z0-9_]*CTRL[A-Z]*\(([a-zA-Z])[^a-zA-Z0-9_][^)]*\)[ 	]+\([ 	(]*'([a-zA-Z])'
 > Applying ctrl_quotes_use          to termios.h
 > Match error 1:
 > ^#[ 	]*define[ 	]+[_A-Z][A-Z0-9_]*CTRL[A-Z]*\(([a-zA-Z])[^a-zA-Z0-9_][^)]*\)[ 	]+\([ 	(]*'([a-zA-Z])'

I think these occur because the regexps in fixfixes.c are too tight
and make some assumptions which are not true.  Unfortunately my head
hurts from looking at them, so I'm not 100% sure what it is.  However
I think the problem lies with where you expect the first single quote
to appear.  I.e. the replacement macro is expected to have only open
parens and whitespace before the first '.

Here are some of the _IO* definitions from sys/iocccom.h:
(Would they make good test_text?)

#define _IO(x,y)        (_IOC_VOID|('x'<<8)|y)
#define _IOR(x,y,t)     (_IOC_OUT|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
#define _IORN(x,y,t)    (_IOC_OUT|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
#define _IOW(x,y,t)     (_IOC_IN|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
#define _IOWN(x,y,t)    (_IOC_IN|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
/* this should be _IORW, but stdio got there first */
#define _IOWR(x,y,t)    (_IOC_INOUT|((sizeof(t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)
#define _IOWRN(x,y,t)   (_IOC_INOUT|(((t)&_IOCPARM_MASK)<<16)|('x'<<8)|y)

as you can see, there are many other permutations of allowable
characters in the macro replacement between the first open paren and
the single quote.


Anyway, I'd like your input on the second issue, but here is the patch
for eliminating sprintf return value checks.



diff -rup orig/egcs-CVS20000516/gcc/fixinc/fixfixes.c egcs-CVS20000516/gcc/fixinc/fixfixes.c
--- orig/egcs-CVS20000516/gcc/fixinc/fixfixes.c	Tue May 16 10:54:22 2000
+++ egcs-CVS20000516/gcc/fixinc/fixfixes.c	Tue May 16 12:24:15 2000
@@ -296,7 +296,7 @@ FIX_PROC_HEAD( char_macro_use_fix )
 #endif
     ;
 
-  char zPat[ sizeof( zPatFmt ) + 32 ];
+  char *zPat;
 
   static regex_t re;
 
@@ -309,13 +309,15 @@ FIX_PROC_HEAD( char_macro_use_fix )
       exit(3);
     }
 
-  if (sprintf( zPat, zPatFmt, p_fixd->patch_args[1] ) >= sizeof( zPat ))
+  asprintf (&zPat, zPatFmt, p_fixd->patch_args[1]);
+  if (!zPat)
     {
-      fprintf( stderr, "Oversize format:  %s\n", zPat );
+      fprintf( stderr, "Virtual memory exhausted\n" );
       exit(3);
     }
 
   compile_re (zPat, &re, 2, "macro pattern", "char_macro_use_fix");
+  free (zPat);
 
   while (regexec (&re, text, 3, rm, 0) == 0)
     {
@@ -378,7 +380,7 @@ FIX_PROC_HEAD( char_macro_def_fix )
 #endif
     ;
 
-  char zPat[ sizeof( zPatFmt ) + 32 ];
+  char *zPat;
 
   static regex_t re;
 
@@ -393,9 +395,10 @@ FIX_PROC_HEAD( char_macro_def_fix )
       exit(3);
     }
 
-  if (sprintf( zPat, zPatFmt, p_fixd->patch_args[1] ) >= sizeof( zPat ))
+  asprintf (&zPat, zPatFmt, p_fixd->patch_args[1]);
+  if (!zPat)
     {
-      fprintf( stderr, "Oversize format:  %s\n", zPat );
+      fprintf (stderr, "Virtual memory exhausted\n");
       exit(3);
     }
 
@@ -407,6 +410,8 @@ FIX_PROC_HEAD( char_macro_def_fix )
       exit(3);
     }
 
+  free (zPat);
+  
   while ((rerr = regexec (&re, text, 3, rm, 0)) == 0)
     {
       const char* pz = text + rm[2].rm_so;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]