Skip to content

Commit 93b1bdd

Browse files
committed
maint: build fix for ucptest and related code tyding up
Since 9a868b0 (Tidy up config.h management (task from README) (PCRE2Project#658), 2025-01-11), it fails to build with an "#error" because "config.h" is no longer included directly. Move the check and change some types in the utf8 tables it uses through pcre2_ord2utf() so it better matches its current use, and other changes in pcre2test. While at it fix a typo in ManyConfigTests that was introduced in 0d0ac3a (Update EBCDIC support to support testing on normal ASCII systems (PCRE2Project#656), 2025-02-12)
1 parent 5281d67 commit 93b1bdd

File tree

6 files changed

+21
-16
lines changed

6 files changed

+21
-16
lines changed

maint/ManyConfigTests

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ usemainvalgrind=1
4040
usetmp=1
4141
usetmpjit=1
4242
useebcdic=1
43-
usebcdicjit=1
43+
useebcdicjit=1
4444
usevalgrind=1
4545

4646
dummy=0

maint/ucptest.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,17 @@ characters, the list ends with ...
8282
The command "list" must be followed by one of property names script, bool,
8383
type, gbreak or bidi. The defined values for that property are listed. */
8484

85-
#ifndef SUPPORT_UNICODE
86-
#error "Unicode support not enabled"
87-
#endif
88-
8985
#include <ctype.h>
9086
#include <stdio.h>
9187
#include <stdlib.h>
9288
#include <string.h>
9389
#include "../src/pcre2_internal.h"
9490
#include "../src/pcre2_ucp.h"
9591

92+
#ifndef SUPPORT_UNICODE
93+
#error "Unicode support not enabled"
94+
#endif
95+
9696
#ifdef HAVE_UNISTD_H
9797
#include <unistd.h>
9898
#endif

src/pcre2_internal.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2233,7 +2233,7 @@ tables are needed only when compiling the 8-bit library. */
22332233

22342234
#if PCRE2_CODE_UNIT_WIDTH == 8
22352235
extern const int PRIV(utf8_table1)[];
2236-
extern const int PRIV(utf8_table1_size);
2236+
extern const unsigned PRIV(utf8_table1_size);
22372237
extern const int PRIV(utf8_table2)[];
22382238
extern const int PRIV(utf8_table3)[];
22392239
extern const uint8_t PRIV(utf8_table4)[];

src/pcre2_ord2utf.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,16 +80,17 @@ PRIV(ord2utf)(uint32_t cvalue, PCRE2_UCHAR *buffer)
8080
/* Convert to UTF-8 */
8181

8282
#if PCRE2_CODE_UNIT_WIDTH == 8
83-
int i, j;
83+
unsigned int i;
84+
8485
for (i = 0; i < PRIV(utf8_table1_size); i++)
8586
if ((int)cvalue <= PRIV(utf8_table1)[i]) break;
8687
buffer += i;
87-
for (j = i; j > 0; j--)
88+
for (unsigned int j = i; j != 0; j--)
8889
{
8990
*buffer-- = 0x80 | (cvalue & 0x3f);
9091
cvalue >>= 6;
9192
}
92-
*buffer = PRIV(utf8_table2)[i] | cvalue;
93+
*buffer = (PCRE2_UCHAR)(PRIV(utf8_table2)[i] | (int)cvalue);
9394
return i + 1;
9495

9596
/* Convert to UTF-16 */

src/pcre2_tables.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,8 @@ defined. */
5151
#endif
5252

5353

54+
/* Utility macros */
55+
#define ARR_SIZE(x) sizeof(x)/sizeof(x[0])
5456

5557
/* Table of sizes for the fixed-length opcodes. It's defined in a macro so that
5658
the definition is next to the definition of the opcodes in pcre2_internal.h.
@@ -100,15 +102,15 @@ handling wide characters. */
100102
character. */
101103

102104
const int PRIV(utf8_table1)[] =
103-
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff};
105+
{ 0x7f, 0x7ff, 0xffff, 0x1fffff, 0x3ffffff, 0x7fffffff };
104106

105-
const int PRIV(utf8_table1_size) = sizeof(PRIV(utf8_table1)) / sizeof(int);
107+
const unsigned PRIV(utf8_table1_size) = ARR_SIZE(PRIV(utf8_table1));
106108

107109
/* These are the indicator bits and the mask for the data bits to set in the
108110
first byte of a character, indexed by the number of additional bytes. */
109111

110-
const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc};
111-
const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01};
112+
const int PRIV(utf8_table2)[] = { 0, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc };
113+
const int PRIV(utf8_table3)[] = { 0xff, 0x1f, 0x0f, 0x07, 0x03, 0x01 };
112114

113115
/* Table of the number of extra bytes, indexed by the first byte masked with
114116
0x3f. The highest number for a valid UTF-8 first byte is in fact 0x3d. */

src/pcre2test.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3264,7 +3264,7 @@ for (j = 0; j < i; j++)
32643264

32653265
/* Check that encoding was the correct unique one */
32663266

3267-
for (j = 0; j < utf8_table1_size; j++)
3267+
for (j = 0; j < (int)utf8_table1_size; j++)
32683268
if (d <= (uint32_t)utf8_table1[j]) break;
32693269
if (j != i) return -(i+1);
32703270

@@ -3340,7 +3340,7 @@ ord_to_utf8(uint32_t cvalue, uint8_t *utf8bytes)
33403340
int i, j;
33413341
if (cvalue > 0x7fffffffu)
33423342
return -1;
3343-
for (i = 0; i < utf8_table1_size; i++)
3343+
for (i = 0; i < (int)utf8_table1_size; i++)
33443344
if (cvalue <= (uint32_t)utf8_table1[i]) break;
33453345
utf8bytes += i;
33463346
for (j = i; j > 0; j--)
@@ -4026,11 +4026,13 @@ Returns: < 0, = 0, or > 0, according to the comparison
40264026
static int
40274027
strncmpic(const uint8_t *s, const uint8_t *t, size_t n)
40284028
{
4029-
while (n--)
4029+
if (n > 0) do
40304030
{
40314031
int c = tolower(*s++) - tolower(*t++);
40324032
if (c != 0) return c;
40334033
}
4034+
while (--n > 0);
4035+
40344036
return 0;
40354037
}
40364038

0 commit comments

Comments
 (0)