summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2014-01-13 21:39:39 -0800
committerKaz Kylheku <kaz@kylheku.com>2014-01-13 21:39:39 -0800
commitd198142b137ed30cb8a70abf2cd0c36600e1ddd8 (patch)
tree6cb40128807ac77afb9cdbff13b6bec3c2468f54
parentef04dd4101f7aa6af724466d1ded707861d2a57d (diff)
downloadtxr-d198142b137ed30cb8a70abf2cd0c36600e1ddd8.tar.gz
txr-d198142b137ed30cb8a70abf2cd0c36600e1ddd8.tar.bz2
txr-d198142b137ed30cb8a70abf2cd0c36600e1ddd8.zip
Bugfix in regex char ranges affecting ranges whose upper end
corresponds to the high bit of a bitmap cell: for instance the character \x7f when the cell size is 32 bits. * regex.c (BITCELL_ALL1): Unused macro removed. (BITCELL_BIT): New macro to replace occurrences of a repeated expression. (CHAR_SET_INDEX, CHAR_SET_BIT): Updated to use BITCELL_BIT. (L0_fill_range): Bugfix: the mask1 calculation was producing all-zero in the condition bt1 == BITCELL_BIT; it should produce an all-ones mask.
-rw-r--r--ChangeLog14
-rw-r--r--regex.c11
2 files changed, 21 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index a56288cf..d3191013 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,19 @@
2014-01-13 Kaz Kylheku <kaz@kylheku.com>
+ Bugfix in regex char ranges affecting ranges whose upper end
+ corresponds to the high bit of a bitmap cell: for instance
+ the character \x7f when the cell size is 32 bits.
+
+ * regex.c (BITCELL_ALL1): Unused macro removed.
+ (BITCELL_BIT): New macro to replace occurrences of a repeated
+ expression.
+ (CHAR_SET_INDEX, CHAR_SET_BIT): Updated to use BITCELL_BIT.
+ (L0_fill_range): Bugfix: the mask1 calculation was producing all-zero
+ in the condition bt1 == BITCELL_BIT; it should produce an all-ones
+ mask.
+
+2014-01-13 Kaz Kylheku <kaz@kylheku.com>
+
Version 74
* txr.c (version): Bumped.
diff --git a/regex.c b/regex.c
index dfe872a8..765112ce 100644
--- a/regex.c
+++ b/regex.c
@@ -62,11 +62,12 @@ typedef union regex_machine regex_machine_t;
typedef unsigned int bitcell_t;
-#define BITCELL_ALL1 UINT_MAX
#define CHAR_SET_SIZE (256 / (sizeof (bitcell_t) * CHAR_BIT))
-#define CHAR_SET_INDEX(CH) ((CH) / (sizeof (bitcell_t) * CHAR_BIT))
-#define CHAR_SET_BIT(CH) ((CH) % (sizeof (bitcell_t) * CHAR_BIT))
+#define BITCELL_BIT (sizeof (bitcell_t) * CHAR_BIT)
+
+#define CHAR_SET_INDEX(CH) ((CH) / BITCELL_BIT)
+#define CHAR_SET_BIT(CH) ((CH) % BITCELL_BIT)
#define CHAR_SET_L0(CH) ((CH) & 0xFF)
#define CHAR_SET_L1(CH) (((CH) >> 8) & 0xF)
@@ -236,7 +237,9 @@ static void L0_fill_range(cset_L0_t *L0, wchar_t ch0, wchar_t ch1)
bitcell_t mask0 = ~(((bitcell_t) 1 << bt0) - 1);
int bt1 = CHAR_SET_BIT(ch1);
int bc1 = CHAR_SET_INDEX(ch1);
- bitcell_t mask1 = (((bitcell_t) 1 << (bt1 + 1) % 32) - 1);
+ bitcell_t mask1 = (bt1 == (BITCELL_BIT - 1))
+ ? (bitcell_t) -1
+ : (((bitcell_t) 1 << (bt1 + 1)) - 1);
if (bc1 == bc0) {
(*L0)[bc0] |= (mask0 & mask1);