tlibregexp: various fixes - plan9port - [fork] Plan 9 from user space
git clone git://src.adamsgaard.dk/plan9port
Log
Files
Refs
README
LICENSE
---
commit 1b68dbef7b7dd7c4aa2b5755c1399cf66d2ea6fa
parent 2d82ef9d98aeae7592e9e4036722468a1dc53acb
Author: David du Colombier <0intro@gmail.com>
Date:   Sun,  9 Aug 2015 21:18:41 +0200

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 
Reviewed-by: Russ Cox 

Diffstat:
  M src/libregexp/regexec.c             |       2 +-
  M src/libregexp/rregexec.c            |       1 -
  M src/libregexp/rregsub.c             |       7 +++----

3 files changed, 4 insertions(+), 6 deletions(-)
---
diff --git a/src/libregexp/regexec.c b/src/libregexp/regexec.c
t@@ -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;
diff --git a/src/libregexp/rregexec.c b/src/libregexp/rregexec.c
t@@ -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) {
diff --git a/src/libregexp/rregsub.c b/src/libregexp/rregsub.c
t@@ -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++)
t@@ -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)