Some "lex" cleanups and bug fixes
Guy Harris
guy at sun.uucp
Sat Aug 10 08:24:13 AEST 1985
Index: usr.bin/lex/lmain.c usr.bin/lex/sub1.c 4.2BSD
(The same bug exists in the S5 "lex" and probably exists
in the V7 "lex" as well).
Description:
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.
Repeat-By:
Try "lex -Q anything.l" if your machine dumps core when dereferencing
null pointers.
Fix:
See following context diffs. Line numbers and exact code
will be different for S3/S5/V7.
diff -c /arch/4.2/usr/src/usr.bin/lex/lmain.c ./lmain.c
*** /arch/4.2/usr/src/usr.bin/lex/lmain.c Thu Aug 11 20:51:24 1983
--- ./lmain.c Tue Aug 6 11:43:35 1985
***************
*** 129,135
dp = dchar = myalloc(DEFCHAR,sizeof(*dchar));
sname = 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(){
--- 129,135 -----
dp = dchar = myalloc(DEFCHAR,sizeof(*dchar));
sname = 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(){
***************
*** 193,199
# endif
char *myalloc(a,b)
int a,b; {
! register int i;
i = calloc(a, b);
if(i==0)
warning("OOPS - calloc returns a 0");
--- 193,199 -----
# endif
char *myalloc(a,b)
int a,b; {
! register char *i;
i = calloc(a, b);
# ifdef DEBUG
if(i==0)
***************
*** 195,200
int a,b; {
register int i;
i = calloc(a, b);
if(i==0)
warning("OOPS - calloc returns a 0");
else if(i == -1){
--- 195,201 -----
int a,b; {
register char *i;
i = calloc(a, b);
+ # ifdef DEBUG
if(i==0)
warning("OOPS - calloc returns a 0");
# endif
***************
*** 197,205
i = 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);
}
--- 198,203 -----
# ifdef DEBUG
if(i==0)
warning("OOPS - calloc returns a 0");
# endif
return(i);
}
***************
*** 201,208
# ifdef DEBUG
warning("calloc returns a -1");
# endif
- return(0);
- }
return(i);
}
# ifdef DEBUG
--- 199,204 -----
if(i==0)
warning("OOPS - calloc returns a 0");
# endif
return(i);
}
# ifdef DEBUG
***************
*** 208,214
# ifdef DEBUG
buserr(){
fflush(errorf);
! fflush(fout);
fflush(stdout);
fprintf(errorf,"Bus error\n");
if(report == 1)statistics();
--- 204,211 -----
# ifdef DEBUG
buserr(){
fflush(errorf);
! if(fout != NULL)
! fflush(fout);
fflush(stdout);
fprintf(errorf,"Bus error\n");
if(report == 1)statistics();
***************
*** 216,222
}
segviol(){
fflush(errorf);
! fflush(fout);
fflush(stdout);
fprintf(errorf,"Segmentation violation\n");
if(report == 1)statistics();
--- 213,220 -----
}
segviol(){
fflush(errorf);
! if(fout != NULL)
! fflush(fout);
fflush(stdout);
fprintf(errorf,"Segmentation violation\n");
if(report == 1)statistics();
diff -c /arch/4.2/usr/src/usr.bin/lex/sub1.c ./sub1.c
*** /arch/4.2/usr/src/usr.bin/lex/sub1.c Thu Aug 11 20:51:25 1983
--- ./sub1.c Tue Aug 6 11:35:17 1985
***************
*** 62,68
fprintf(errorf,s,p,d);
putc('\n',errorf);
fflush(errorf);
! fflush(fout);
fflush(stdout);
}
index(a,s)
--- 62,69 -----
fprintf(errorf,s,p,d);
putc('\n',errorf);
fflush(errorf);
! if(fout != NULL)
! fflush(fout);
fflush(stdout);
}
index(a,s)
More information about the Net.bugs.usg
mailing list