Skip to content

Commit 804b10a

Browse files
authored
Fix some Clang warnings (PCRE2Project#689)
1 parent 191a4fd commit 804b10a

File tree

3 files changed

+52
-14
lines changed

3 files changed

+52
-14
lines changed

src/pcre2_jit_neon_inc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ int_char ic;
101101
SLJIT_UNUSED_ARG(offs1);
102102
SLJIT_UNUSED_ARG(offs2);
103103

104-
ic.x = chars;
104+
ic.x = (int)chars; /* Cast is OK as chars come from an int_char in the first place. */
105105

106106
#if defined(FFCS)
107107
sljit_u8 c1 = ic.c.c1;
@@ -124,7 +124,7 @@ vect_t vmask = VDUPQ(mask);
124124
compare_type compare1_type = compare_match1;
125125
compare_type compare2_type = compare_match1;
126126
vect_t cmp1a, cmp1b, cmp2a, cmp2b;
127-
const sljit_u32 diff = IN_UCHARS(offs1 - offs2);
127+
const sljit_uw diff = IN_UCHARS(offs1 - offs2);
128128
PCRE2_UCHAR char1a = ic.c.c1;
129129
PCRE2_UCHAR char2a = ic.c.c3;
130130

src/pcre2grep.c

Lines changed: 49 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,9 @@ POSSIBILITY OF SUCH DAMAGE.
4949
#endif
5050

5151
#include <ctype.h>
52+
#include <limits.h>
5253
#include <locale.h>
54+
#include <stddef.h>
5355
#include <stdio.h>
5456
#include <string.h>
5557
#include <stdlib.h>
@@ -2586,7 +2588,7 @@ return result != 0;
25862588
* Read a portion of the file into buffer *
25872589
*************************************************/
25882590

2589-
static PCRE2_SIZE
2591+
static ptrdiff_t
25902592
fill_buffer(void *handle, int frtype, char *buffer, PCRE2_SIZE length,
25912593
BOOL input_line_buffered)
25922594
{
@@ -2595,13 +2597,15 @@ PCRE2_SIZE nread;
25952597

25962598
#ifdef SUPPORT_LIBZ
25972599
if (frtype == FR_LIBZ)
2598-
return gzread((gzFile)handle, buffer, length);
2600+
return gzread((gzFile)handle, buffer,
2601+
(length > UINT_MAX)? UINT_MAX : (unsigned)length);
25992602
else
26002603
#endif
26012604

26022605
#ifdef SUPPORT_LIBBZ2
26032606
if (frtype == FR_LIBBZ2)
2604-
return (PCRE2_SIZE)BZ2_bzread((BZFILE *)handle, buffer, length);
2607+
return BZ2_bzread((BZFILE *)handle, buffer,
2608+
(length > UINT_MAX)? UINT_MAX : (unsigned)length);
26052609
else
26062610
#endif
26072611

@@ -2614,7 +2618,7 @@ if (nread > 0) VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(buffer, nread);
26142618
if (nread < length) VALGRIND_MAKE_MEM_UNDEFINED(buffer + nread, length - nread);
26152619
#endif
26162620

2617-
return nread;
2621+
return (ptrdiff_t)nread;
26182622
}
26192623

26202624

@@ -2659,6 +2663,7 @@ char *lastmatchrestart = main_buffer;
26592663
char *ptr = main_buffer;
26602664
char *endptr;
26612665
PCRE2_SIZE bufflength;
2666+
ptrdiff_t buffrc;
26622667
BOOL binary = FALSE;
26632668
BOOL endhyphenpending = FALSE;
26642669
BOOL lines_printed = FALSE;
@@ -2684,13 +2689,17 @@ if (frtype != FR_LIBZ && frtype != FR_LIBBZ2)
26842689
}
26852690
else input_line_buffered = FALSE;
26862691

2687-
bufflength = fill_buffer(handle, frtype, main_buffer, bufsize,
2692+
buffrc = fill_buffer(handle, frtype, main_buffer, bufsize,
26882693
input_line_buffered);
26892694

2695+
#if defined SUPPORT_LIBZ
2696+
if (frtype == FR_LIBZ && buffrc < 0) return 3;
2697+
#endif
26902698
#ifdef SUPPORT_LIBBZ2
2691-
if (frtype == FR_LIBBZ2 && (int)bufflength < 0) return 3; /* Gotcha: bufflength is PCRE2_SIZE */
2699+
if (frtype == FR_LIBBZ2 && buffrc < 0) return 3;
26922700
#endif
26932701

2702+
bufflength = (PCRE2_SIZE)buffrc;
26942703
endptr = main_buffer + bufflength;
26952704

26962705
/* Unless binary-files=text, see if we have a binary file. This uses the same
@@ -2788,8 +2797,17 @@ while (ptr < endptr)
27882797
/* Read more data into the buffer and then try to find the line ending
27892798
again. */
27902799

2791-
bufflength += fill_buffer(handle, frtype, main_buffer + bufflength,
2800+
buffrc = fill_buffer(handle, frtype, main_buffer + bufflength,
27922801
bufsize - bufflength, input_line_buffered);
2802+
2803+
#if defined SUPPORT_LIBZ
2804+
if (frtype == FR_LIBZ && buffrc < 0) return 3;
2805+
#endif
2806+
#ifdef SUPPORT_LIBBZ2
2807+
if (frtype == FR_LIBBZ2 && buffrc < 0) return 3;
2808+
#endif
2809+
2810+
bufflength += (PCRE2_SIZE)buffrc;
27932811
endptr = main_buffer + bufflength;
27942812
continue;
27952813
}
@@ -3260,8 +3278,17 @@ while (ptr < endptr)
32603278
(void)memmove(main_buffer, main_buffer + bufthird, 2*bufthird);
32613279
ptr -= bufthird;
32623280

3263-
bufflength = 2*bufthird + fill_buffer(handle, frtype,
3264-
main_buffer + 2*bufthird, bufthird, input_line_buffered);
3281+
buffrc = fill_buffer(handle, frtype, main_buffer + 2*bufthird, bufthird,
3282+
input_line_buffered);
3283+
3284+
#if defined SUPPORT_LIBZ
3285+
if (frtype == FR_LIBZ && buffrc < 0) return 3;
3286+
#endif
3287+
#ifdef SUPPORT_LIBBZ2
3288+
if (frtype == FR_LIBBZ2 && buffrc < 0) return 3;
3289+
#endif
3290+
3291+
bufflength = 2*bufthird + (PCRE2_SIZE)buffrc;
32653292
endptr = main_buffer + bufflength;
32663293

32673294
/* Adjust any last match point */
@@ -3625,7 +3652,18 @@ rc = pcre2grep(handle, frtype, pathname, (filenames > FN_DEFAULT ||
36253652

36263653
#ifdef SUPPORT_LIBZ
36273654
if (frtype == FR_LIBZ)
3655+
{
3656+
if (rc == 3)
3657+
{
3658+
int errnum;
3659+
const char *err = gzerror(ingz, &errnum);
3660+
if (!silent)
3661+
fprintf(stderr, "pcre2grep: Failed to read %s using zlib: %s\n",
3662+
pathname, err);
3663+
rc = 2; /* The normal "something went wrong" code */
3664+
}
36283665
gzclose(ingz);
3666+
}
36293667
else
36303668
#endif
36313669

@@ -4275,9 +4313,9 @@ for (i = 1; i < argc; i++)
42754313
else
42764314
{
42774315
unsigned long int n = decode_number(option_data, op, longop);
4278-
if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = n;
4316+
if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = (int)n;
42794317
else if (op->type == OP_SIZE) *((PCRE2_SIZE *)op->dataptr) = n;
4280-
else *((int *)op->dataptr) = n;
4318+
else *((int *)op->dataptr) = (int)n;
42814319
}
42824320
}
42834321

src/pcre2test.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9820,7 +9820,7 @@ least 128 code units, because it is used for retrieving error messages. */
98209820

98219821
for (;;)
98229822
{
9823-
errcode = strtol(arg_error, &endptr, 10);
9823+
errcode = (int)strtol(arg_error, &endptr, 10);
98249824
if (*endptr != 0 && *endptr != CHAR_COMMA)
98259825
{
98269826
fprintf(stderr, "** \"%s\" is not a valid error number list\n", arg_error);

0 commit comments

Comments
 (0)