maint: indent cpp directives to reflect nesting
      pcre: avoid a nominal leak
      maint: add comments and split some long lines
From 354209b0cfc5402aa1ebd8835135e04e36a3a6f4 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Sat, 14 Dec 2013 10:09:46 -0800
Subject: [PATCH 1/3] maint: indent cpp directives to reflect nesting

* src/pcresearch.c: Insert spaces after a few "#", to indent
cpp directives to reflect their nesting.
---
 src/pcresearch.c | 21 +++++++++++----------
 1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/pcresearch.c b/src/pcresearch.c
index 9ba1227..67dee45 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -36,11 +36,11 @@ static pcre *cre;
 /* Additional information about the pattern.  */
 static pcre_extra *extra;

-#ifdef PCRE_STUDY_JIT_COMPILE
+# ifdef PCRE_STUDY_JIT_COMPILE
 static pcre_jit_stack *jit_stack;
-#else
-#define PCRE_STUDY_JIT_COMPILE 0
-#endif
+# else
+#  define PCRE_STUDY_JIT_COMPILE 0
+# endif
 #endif

 void
@@ -60,10 +60,10 @@ Pcompile (char const *pattern, size_t size)
   char const *p;
   char const *pnul;

-#if defined HAVE_LANGINFO_CODESET
+# if defined HAVE_LANGINFO_CODESET
   if (STREQ (nl_langinfo (CODESET), "UTF-8"))
     flags |= PCRE_UTF8;
-#endif
+# endif

   /* FIXME: Remove these restrictions.  */
   if (memchr (pattern, '\n', size))
@@ -111,7 +111,7 @@ Pcompile (char const *pattern, size_t size)
   if (ep)
     error (EXIT_TROUBLE, 0, "%s", ep);

-#if PCRE_STUDY_JIT_COMPILE
+# if PCRE_STUDY_JIT_COMPILE
   if (pcre_fullinfo (cre, extra, PCRE_INFO_JIT, &e))
     error (EXIT_TROUBLE, 0, _("internal error (should never happen)"));

@@ -122,12 +122,13 @@ Pcompile (char const *pattern, size_t size)
          than the interpreter, this should be enough in practice.  */
       jit_stack = pcre_jit_stack_alloc (32 * 1024, 512 * 1024);
       if (!jit_stack)
-        error (EXIT_TROUBLE, 0, _("cannot allocate memory for the JIT stack"));
+        error (EXIT_TROUBLE, 0,
+               _("failed to allocate memory for the PCRE JIT stack"));
       pcre_assign_jit_stack (extra, NULL, jit_stack);
     }
   free (re);
-#endif
-#endif
+# endif
+#endif /* HAVE_LIBPCRE */
 }

 size_t
-- 
1.8.5.rc2.6.gc6f1b92


From 6f20f5412ef66885ab3df08ad2b6f598ad36fe18 Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Sat, 14 Dec 2013 10:13:25 -0800
Subject: [PATCH 2/3] pcre: avoid a nominal leak

* src/pcresearch.c (Pcompile)[HAVE_LIBPCRE && !PCRE_STUDY_JIT_COMPILE]:
We would leak "re" if built with HAVE_LIBPCRE but without
PCRE_STUDY_JIT_COMPILE.  Move the free out one level.
---
 src/pcresearch.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/pcresearch.c b/src/pcresearch.c
index 67dee45..7e81a31 100644
--- a/src/pcresearch.c
+++ b/src/pcresearch.c
@@ -126,8 +126,8 @@ Pcompile (char const *pattern, size_t size)
                _("failed to allocate memory for the PCRE JIT stack"));
       pcre_assign_jit_stack (extra, NULL, jit_stack);
     }
-  free (re);
 # endif
+  free (re);
 #endif /* HAVE_LIBPCRE */
 }

-- 
1.8.5.rc2.6.gc6f1b92


From ba7ecab408cc5beafb93ecde7a9528a08df5afeb Mon Sep 17 00:00:00 2001
From: Jim Meyering <[email protected]>
Date: Mon, 16 Dec 2013 10:32:50 -0800
Subject: [PATCH 3/3] maint: add comments and split some long lines

* src/main.c (do_execute): Add a comment.
Split some lines longer than 80 bytes.
---
 src/main.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/src/main.c b/src/main.c
index 6ee1632..1dfbcb6 100644
--- a/src/main.c
+++ b/src/main.c
@@ -933,7 +933,7 @@ prline (char const *beg, char const *lim, int sep)
   if ((only_matching && matching)
       || (color_option  && (*line_color || *match_color)))
     {
-      /* We already know that non-matching lines have no match (to colorize).  
*/
+      /* We already know that non-matching lines have no match (to colorize). 
*/
       if (matching && (only_matching || *match_color))
         beg = print_line_middle (beg, lim, line_color, match_color);

@@ -1047,8 +1047,12 @@ prtext (char const *beg, char const *lim, intmax_t 
*nlinesp)
   used = 1;
 }

+/* Invoke the matcher, EXECUTE, on buffer BUF of SIZE bytes.  If there
+   is no match, return (size_t) -1.  Otherwise, set *MATCH_SIZE to the
+   length of the match and return the offset of the start of the match.  */
 static size_t
-do_execute (char const *buf, size_t size, size_t *match_size, char const 
*start_ptr)
+do_execute (char const *buf, size_t size, size_t *match_size,
+            char const *start_ptr)
 {
   size_t result;
   const char *line_next;
@@ -1071,7 +1075,8 @@ do_execute (char const *buf, size_t size, size_t 
*match_size, char const *start_
   for (line_next = buf; line_next < buf + size; )
     {
       const char *line_buf = line_next;
-      const char *line_end = memchr (line_buf, eolbyte, (buf + size) - 
line_buf);
+      const char *line_end = memchr (line_buf, eolbyte,
+                                     (buf + size) - line_buf);
       if (line_end == NULL)
         line_next = line_end = buf + size;
       else
@@ -1215,7 +1220,8 @@ grep (int fd, struct stat const *st)
             nlines += grepbuf (beg, lim);
           if (pending)
             prpending (lim);
-          if ((!outleft && !pending) || (nlines && done_on_match && 
!out_invert))
+          if ((!outleft && !pending)
+              || (nlines && done_on_match && !out_invert))
             goto finish_grep;
         }

-- 
1.8.5.rc2.6.gc6f1b92

Reply via email to