grep-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

grep branch, master, updated. v2.15-7-gf8d6a5d


From: Jim Meyering
Subject: grep branch, master, updated. v2.15-7-gf8d6a5d
Date: Fri, 22 Nov 2013 05:00:59 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "grep".

The branch, master has been updated
       via  f8d6a5d3b5ea5d098f2973c66041613b68812ad2 (commit)
      from  9a9b4c59babc60e15a79cf7db8167d42e68e44b9 (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
http://git.savannah.gnu.org/cgit/grep.git/commit/?id=f8d6a5d3b5ea5d098f2973c66041613b68812ad2


commit f8d6a5d3b5ea5d098f2973c66041613b68812ad2
Author: Jim Meyering <address@hidden>
Date:   Mon Nov 18 17:53:33 2013 -0800

    dfa: avoid undefined behavior of "1 << 31"
    
    * src/dfa.c (charclass): Change type from "int" to "unsigned int".
    (tstbit): Rather than shifting "1" left to form a mask, shift the
    LHS bits the right and use "1" as the mask.  Also, return bool, rather
    than "int".
    (setbit, clrbit, dfastate): Don't shift "1" (aka (int)1) left by 31 bits.
    Instead, use "1U" as the operand, to avoid undefined behavior.
    Spotted by gcc's new -fsanitize=undefined.
    Co-authored-by: Paul Eggert <address@hidden>

diff --git a/src/dfa.c b/src/dfa.c
index 92c410e..f196b8a 100644
--- a/src/dfa.c
+++ b/src/dfa.c
@@ -88,7 +88,7 @@
 #define CHARCLASS_INTS ((NOTCHAR + INTBITS - 1) / INTBITS)
 
 /* Sets of unsigned characters are stored as bit vectors in arrays of ints.  */
-typedef int charclass[CHARCLASS_INTS];
+typedef unsigned int charclass[CHARCLASS_INTS];
 
 /* Convert a possibly-signed character to an unsigned character.  This is
    a bit safer than casting to unsigned char, since it catches some type
@@ -547,22 +547,22 @@ prtok (token t)
 
 /* Stuff pertaining to charclasses.  */
 
-static int
+static bool
 tstbit (unsigned int b, charclass const c)
 {
-  return c[b / INTBITS] & 1 << b % INTBITS;
+  return c[b / INTBITS] >> b % INTBITS & 1;
 }
 
 static void
 setbit (unsigned int b, charclass c)
 {
-  c[b / INTBITS] |= 1 << b % INTBITS;
+  c[b / INTBITS] |= 1U << b % INTBITS;
 }
 
 static void
 clrbit (unsigned int b, charclass c)
 {
-  c[b / INTBITS] &= ~(1 << b % INTBITS);
+  c[b / INTBITS] &= ~(1U << b % INTBITS);
 }
 
 static void
@@ -2738,7 +2738,7 @@ dfastate (state_num s, struct dfa *d, state_num trans[])
       /* Set the transitions for each character in the current label.  */
       for (j = 0; j < CHARCLASS_INTS; ++j)
         for (k = 0; k < INTBITS; ++k)
-          if (labels[i][j] & 1 << k)
+          if (labels[i][j] & 1U << k)
             {
               int c = j * INTBITS + k;
 

-----------------------------------------------------------------------

Summary of changes:
 src/dfa.c |   12 ++++++------
 1 files changed, 6 insertions(+), 6 deletions(-)


hooks/post-receive
-- 
grep



reply via email to

[Prev in Thread] Current Thread [Next in Thread]