Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84 SMI; site sun.uucp Path: utzoo!linus!philabs!prls!amdimage!amdcad!decwrl!sun!guy From: guy@sun.uucp (Guy Harris) Newsgroups: net.bugs.usg Subject: Some "lex" cleanups and bug fixes (better than previous posting) Message-ID: <2594@sun.uucp> Date: Fri, 9-Aug-85 18:32:17 EDT Article-I.D.: sun.2594 Posted: Fri Aug 9 18:32:17 1985 Date-Received: Mon, 12-Aug-85 22:06:49 EDT Distribution: net Organization: Sun Microsystems, Inc. Lines: 233 Here's the version of the previous posting about "lex" problems for the S5 "lex". Line numbers may still differ... 1) A couple of bits of code here are really sloppy when it comes to pointers vs. integers. 2) Some other bits of code are sloppy when it comes to - surprise! - dereferencing NULL pointers. 3) They also use signal numbers instead of including. diff -c /arch/s5r2compat/src/lex/main.c ./main.c *** /arch/s5r2compat/src/lex/main.c Wed Jan 30 19:56:15 1985 --- ./main.c Tue Aug 6 11:45:52 1985 *************** *** 12,19 char **argv; { register int i; # ifdef DEBUG ! signal(10,buserr); ! signal(11,segviol); # endif while (argc > 1 && argv[1][0] == '-' ){ i = 0; --- 12,20 ----- char **argv; { register int i; # ifdef DEBUG ! #include ! signal(SIGBUS,buserr); ! signal(SIGSEGV,segviol); # endif while (argc > 1 && argv[1][0] == '-' ){ i = 0; *************** *** 127,133 dp = dchar = myalloc(DEFCHAR,sizeof(*dchar)); sname = (char **)myalloc(STARTSIZE,sizeof(*sname)); sp = schar = myalloc(STARTCHAR,sizeof(*schar)); ! if(ccl == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || schar == 0) error("Too little core to begin"); } free1core(){ --- 128,134 ----- dp = dchar = myalloc(DEFCHAR,sizeof(*dchar)); sname = (char **)myalloc(STARTSIZE,sizeof(*sname)); sp = schar = myalloc(STARTCHAR,sizeof(*schar)); ! if(ccl == 0 || pchar == 0 || def == 0 || subs == 0 || dchar == 0 || sname == 0 || schar == 0) error("Too little core to begin"); } free1core(){ *************** *** 191,198 # endif char *myalloc(a,b) int a,b; { ! register int i; ! i = (int)calloc(a, b); if(i==0) warning("OOPS - calloc returns a 0"); else if(i == -1){ --- 192,200 ----- # endif char *myalloc(a,b) int a,b; { ! register char *i; ! i = calloc(a, b); ! # ifdef DEBUG if(i==0) warning("OOPS - calloc returns a 0"); # endif *************** *** 195,203 i = (int)calloc(a, b); if(i==0) warning("OOPS - calloc returns a 0"); - else if(i == -1){ - # ifdef DEBUG - warning("calloc returns a -1"); # endif return(0); } --- 197,202 ----- # ifdef DEBUG if(i==0) warning("OOPS - calloc returns a 0"); # endif return(i); } *************** *** 199,207 # ifdef DEBUG warning("calloc returns a -1"); # endif ! return(0); ! } ! return((char *)i); } # ifdef DEBUG buserr(){ --- 198,204 ----- if(i==0) warning("OOPS - calloc returns a 0"); # endif ! return(i); } # ifdef DEBUG buserr(){ *************** *** 206,212 # ifdef DEBUG buserr(){ fflush(errorf); ! fflush(fout); fflush(stdout); fprintf(errorf,"Bus error\n"); if(report == 1)statistics(); --- 203,210 ----- # ifdef DEBUG buserr(){ fflush(errorf); ! if(fout != NULL) ! fflush(fout); fflush(stdout); fprintf(errorf,"Bus error\n"); if(report == 1)statistics(); *************** *** 214,220 } segviol(){ fflush(errorf); ! fflush(fout); fflush(stdout); fprintf(errorf,"Segmentation violation\n"); if(report == 1)statistics(); --- 212,219 ----- } segviol(){ fflush(errorf); ! if(fout != NULL) ! fflush(fout); fflush(stdout); fprintf(errorf,"Segmentation violation\n"); if(report == 1)statistics(); diff -c /arch/s5r2compat/src/lex/parser.y ./parser.y *** /arch/s5r2compat/src/lex/parser.y Wed Jan 30 19:56:16 1985 --- ./parser.y Tue Aug 6 11:12:37 1985 *************** *** 220,226 yylex(){ register char *p; register int c, i; ! char *t, *xp; int n, j, k, x; static int sectbegin; static char token[TOKENSIZE]; --- 220,226 ----- yylex(){ register char *p; register int c, i; ! register char *t, *xp; int n, j, k, x; static int sectbegin; static char token[TOKENSIZE]; *************** *** 245,252 sectbegin = TRUE; i = treesize*(sizeof(*name)+sizeof(*left)+ sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA; ! c = (int)myalloc(i,1); ! if(c == 0) error("Too little core for parse tree"); p = (char *)c; cfree((char *)p,i,1); --- 245,252 ----- sectbegin = TRUE; i = treesize*(sizeof(*name)+sizeof(*left)+ sizeof(*right)+sizeof(*nullstr)+sizeof(*parent))+ALITTLEEXTRA; ! xp = (char *)myalloc(i,1); ! if(xp == 0) error("Too little core for parse tree"); cfree((char *)xp,i,1); name = (int *)myalloc(treesize,sizeof(*name)); *************** *** 248,255 c = (int)myalloc(i,1); if(c == 0) error("Too little core for parse tree"); ! p = (char *)c; ! cfree((char *)p,i,1); name = (int *)myalloc(treesize,sizeof(*name)); left = (int *)myalloc(treesize,sizeof(*left)); right = (int *)myalloc(treesize,sizeof(*right)); --- 248,254 ----- xp = (char *)myalloc(i,1); if(xp == 0) error("Too little core for parse tree"); ! cfree((char *)xp,i,1); name = (int *)myalloc(treesize,sizeof(*name)); left = (int *)myalloc(treesize,sizeof(*left)); right = (int *)myalloc(treesize,sizeof(*right)); diff -c /arch/s5r2compat/src/lex/sub1.c ./sub1.c *** /arch/s5r2compat/src/lex/sub1.c Wed Jan 30 19:56:17 1985 --- ./sub1.c Tue Aug 6 11:23:46 1985 *************** *** 60,66 fprintf(errorf,s,p,d); putc('\n',errorf); fflush(errorf); ! fflush(fout); fflush(stdout); } index(a,s) --- 60,67 ----- fprintf(errorf,s,p,d); putc('\n',errorf); fflush(errorf); ! if(fout != NULL) ! fflush(fout); fflush(stdout); } index(a,s)