The lineInfo array is memset to 0 on allocation and reallocation, so
we can be sure lineInfo[n].search is NULL by default.

safe_realloc() handles the initial allocation too, so there is no need
for an if/else branch.

Thanks to Alejandro Colomar for the suggestion.
---
 pager.c | 8 +++-----
 1 file changed, 3 insertions(+), 5 deletions(-)

diff --git a/pager.c b/pager.c
index 201dad91..6398afa3 100644
--- a/pager.c
+++ b/pager.c
@@ -1288,11 +1288,9 @@ static void resolve_search(struct line_t *lineInfo, int 
n, char *fmt,
   lineInfo[n].search_cnt = 0;
   while (regexec(SearchRE, fmt + offset, 1, pmatch, (offset ? REG_NOTBOL : 0)) 
== 0)
   {
-    if (++(lineInfo[n].search_cnt) > 1)
-      safe_realloc(&(lineInfo[n].search),
-                   (lineInfo[n].search_cnt) * sizeof(struct syntax_t));
-    else
-      lineInfo[n].search = safe_malloc(sizeof(struct syntax_t));
+    lineInfo[n].search_cnt++;
+    safe_realloc(&(lineInfo[n].search),
+                 (lineInfo[n].search_cnt) * sizeof(struct syntax_t));
     pmatch[0].rm_so += offset;
     pmatch[0].rm_eo += offset;
     (lineInfo[n].search)[lineInfo[n].search_cnt - 1].first = pmatch[0].rm_so;
-- 
2.54.0

Reply via email to