From fb47dacb58a90604bb5006f23e7ddab9765e01a2 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 21 Jul 2017 11:37:06 +0200 Subject: [PATCH 1/2] Fix uninitialized value Valgrind report: ==10379== Conditional jump or move depends on uninitialised value(s) ==10379== at 0x125E62: agrep (sgrep.c:1161) ==10379== by 0x12344B: sgrep (sgrep.c:436) ==10379== by 0x119A29: exec (agrep.c:3430) ==10379== by 0x119258: agrep_search (agrep.c:3226) ==10379== by 0x119327: fileagrep_search (agrep.c:3262) ==10379== by 0x119460: fileagrep (agrep.c:3312) ==10379== by 0x11D136: main (main.c:79) ==10379== Uninitialised value was created by a stack allocation ==10379== at 0x125C24: agrep (sgrep.c:1105) Signed-off-by: Stefan Weil --- sgrep.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/sgrep.c b/sgrep.c index 9dce86c..3a60b8c 100644 --- a/sgrep.c +++ b/sgrep.c @@ -1120,7 +1120,9 @@ register CHARTYPE *text, *textend, *pat, *oldpat; CHARTYPE *lastout = text; int newlen; - Candidate[0][0] = Candidate[0][1] = 0; + Candidate[0][0] = 0; + Candidate[0][1] = 0; + Candidate[1][0] = 0; d1 = shift_1; cdx = 0; if(m < 3) r1 = m; From a7fe1151ce7700db90949f26dda00630e4fb36c5 Mon Sep 17 00:00:00 2001 From: Stefan Weil Date: Fri, 21 Jul 2017 17:02:35 +0200 Subject: [PATCH 2/2] Fix duplicate free There are calls of free_buf in all other code branches. Signed-off-by: Stefan Weil --- asearch.c | 1 - 1 file changed, 1 deletion(-) diff --git a/asearch.c b/asearch.c index 5a57e11..d3b19cf 100644 --- a/asearch.c +++ b/asearch.c @@ -234,7 +234,6 @@ register unsigned D; { if(FILENAMEONLY && (NEW_FILE || !POST_FILTER)) { num_of_matched++; - free_buf(text, buffer); if (agrep_finalfp != NULL) fprintf(agrep_finalfp, "%s\n", CurrentFileName); else {