libregexp: various fixes

- Check before dereference.
- Fix memory leak
- Remove duplicate if statement.
- Remove trailing spaces.

Change-Id: I140a05c8f7006493dddae753aebfa5b4577c65ef
Reviewed-on: https://plan9port-review.googlesource.com/1301
Reviewed-by: Neven Sajko <nsajko@gmail.com>
Reviewed-by: Russ Cox <rsc@swtch.com>
This commit is contained in:
David du Colombier 2015-08-09 21:18:41 +02:00 committed by Russ Cox
parent 2d82ef9d98
commit 1b68dbef7b
3 changed files with 4 additions and 6 deletions

View file

@ -171,7 +171,7 @@ regexec2(Reprog *progp, /* program to run */
return -1;
relist1 = malloc(BIGLISTSIZE*sizeof(Relist));
if(relist1 == nil){
free(relist1);
free(relist0);
return -1;
}
j->relist[0] = relist0;

View file

@ -40,7 +40,6 @@ rregexec1(Reprog *progp, /* program to run */
/* Execute machine once for each character, including terminal NUL */
s = j->rstarts;
do{
/* fast check for first char */
if(checkstart) {
switch(j->starttype) {

View file

@ -27,7 +27,7 @@ rregsub(Rune *sp, /* source string */
case '8':
case '9':
i = *sp-'0';
if(mp[i].s.rsp != 0 && mp!=0 && ms>i)
if(mp!=0 && mp[i].s.rsp != 0 && ms>i)
for(ssp = mp[i].s.rsp;
ssp < mp[i].e.rep;
ssp++)
@ -46,9 +46,8 @@ rregsub(Rune *sp, /* source string */
*dp++ = *sp;
break;
}
}else if(*sp == '&'){
if(mp[0].s.rsp != 0 && mp!=0 && ms>0)
if(mp[0].s.rsp != 0)
}else if(*sp == '&'){
if(mp!=0 && mp[0].s.rsp != 0 && ms>0)
for(ssp = mp[0].s.rsp;
ssp < mp[0].e.rep; ssp++)
if(dp < ep)