From d43595e45f5c9d4eb84ed69d8211c7b701b26dad Mon Sep 17 00:00:00 2001 From: Nicholas Wilson Date: Thu, 6 Feb 2025 13:47:33 +0000 Subject: [PATCH] Fix some Clang warnings --- src/pcre2_jit_neon_inc.h | 4 +-- src/pcre2grep.c | 60 ++++++++++++++++++++++++++++++++-------- src/pcre2test.c | 2 +- 3 files changed, 52 insertions(+), 14 deletions(-) diff --git a/src/pcre2_jit_neon_inc.h b/src/pcre2_jit_neon_inc.h index 8baa337f1..7f9a8cc83 100644 --- a/src/pcre2_jit_neon_inc.h +++ b/src/pcre2_jit_neon_inc.h @@ -101,7 +101,7 @@ int_char ic; SLJIT_UNUSED_ARG(offs1); SLJIT_UNUSED_ARG(offs2); -ic.x = chars; +ic.x = (int)chars; /* Cast is OK as chars come from an int_char in the first place. */ #if defined(FFCS) sljit_u8 c1 = ic.c.c1; @@ -124,7 +124,7 @@ vect_t vmask = VDUPQ(mask); compare_type compare1_type = compare_match1; compare_type compare2_type = compare_match1; vect_t cmp1a, cmp1b, cmp2a, cmp2b; -const sljit_u32 diff = IN_UCHARS(offs1 - offs2); +const sljit_uw diff = IN_UCHARS(offs1 - offs2); PCRE2_UCHAR char1a = ic.c.c1; PCRE2_UCHAR char2a = ic.c.c3; diff --git a/src/pcre2grep.c b/src/pcre2grep.c index a437b8359..c24197bad 100644 --- a/src/pcre2grep.c +++ b/src/pcre2grep.c @@ -49,7 +49,9 @@ POSSIBILITY OF SUCH DAMAGE. #endif #include +#include #include +#include #include #include #include @@ -2586,7 +2588,7 @@ return result != 0; * Read a portion of the file into buffer * *************************************************/ -static PCRE2_SIZE +static ptrdiff_t fill_buffer(void *handle, int frtype, char *buffer, PCRE2_SIZE length, BOOL input_line_buffered) { @@ -2595,13 +2597,15 @@ PCRE2_SIZE nread; #ifdef SUPPORT_LIBZ if (frtype == FR_LIBZ) - return gzread((gzFile)handle, buffer, length); + return gzread((gzFile)handle, buffer, + (length > UINT_MAX)? UINT_MAX : (unsigned)length); else #endif #ifdef SUPPORT_LIBBZ2 if (frtype == FR_LIBBZ2) - return (PCRE2_SIZE)BZ2_bzread((BZFILE *)handle, buffer, length); + return BZ2_bzread((BZFILE *)handle, buffer, + (length > UINT_MAX)? UINT_MAX : (unsigned)length); else #endif @@ -2614,7 +2618,7 @@ if (nread > 0) VALGRIND_MAKE_MEM_DEFINED_IF_ADDRESSABLE(buffer, nread); if (nread < length) VALGRIND_MAKE_MEM_UNDEFINED(buffer + nread, length - nread); #endif -return nread; +return (ptrdiff_t)nread; } @@ -2659,6 +2663,7 @@ char *lastmatchrestart = main_buffer; char *ptr = main_buffer; char *endptr; PCRE2_SIZE bufflength; +ptrdiff_t buffrc; BOOL binary = FALSE; BOOL endhyphenpending = FALSE; BOOL lines_printed = FALSE; @@ -2684,13 +2689,17 @@ if (frtype != FR_LIBZ && frtype != FR_LIBBZ2) } else input_line_buffered = FALSE; -bufflength = fill_buffer(handle, frtype, main_buffer, bufsize, +buffrc = fill_buffer(handle, frtype, main_buffer, bufsize, input_line_buffered); +#if defined SUPPORT_LIBZ +if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif #ifdef SUPPORT_LIBBZ2 -if (frtype == FR_LIBBZ2 && (int)bufflength < 0) return 3; /* Gotcha: bufflength is PCRE2_SIZE */ +if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; #endif +bufflength = (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; /* Unless binary-files=text, see if we have a binary file. This uses the same @@ -2788,8 +2797,17 @@ while (ptr < endptr) /* Read more data into the buffer and then try to find the line ending again. */ - bufflength += fill_buffer(handle, frtype, main_buffer + bufflength, + buffrc = fill_buffer(handle, frtype, main_buffer + bufflength, bufsize - bufflength, input_line_buffered); + +#if defined SUPPORT_LIBZ + if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif +#ifdef SUPPORT_LIBBZ2 + if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; +#endif + + bufflength += (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; continue; } @@ -3260,8 +3278,17 @@ while (ptr < endptr) (void)memmove(main_buffer, main_buffer + bufthird, 2*bufthird); ptr -= bufthird; - bufflength = 2*bufthird + fill_buffer(handle, frtype, - main_buffer + 2*bufthird, bufthird, input_line_buffered); + buffrc = fill_buffer(handle, frtype, main_buffer + 2*bufthird, bufthird, + input_line_buffered); + +#if defined SUPPORT_LIBZ + if (frtype == FR_LIBZ && buffrc < 0) return 3; +#endif +#ifdef SUPPORT_LIBBZ2 + if (frtype == FR_LIBBZ2 && buffrc < 0) return 3; +#endif + + bufflength = 2*bufthird + (PCRE2_SIZE)buffrc; endptr = main_buffer + bufflength; /* Adjust any last match point */ @@ -3625,7 +3652,18 @@ rc = pcre2grep(handle, frtype, pathname, (filenames > FN_DEFAULT || #ifdef SUPPORT_LIBZ if (frtype == FR_LIBZ) + { + if (rc == 3) + { + int errnum; + const char *err = gzerror(ingz, &errnum); + if (!silent) + fprintf(stderr, "pcre2grep: Failed to read %s using zlib: %s\n", + pathname, err); + rc = 2; /* The normal "something went wrong" code */ + } gzclose(ingz); + } else #endif @@ -4275,9 +4313,9 @@ for (i = 1; i < argc; i++) else { unsigned long int n = decode_number(option_data, op, longop); - if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = n; + if (op->type == OP_U32NUMBER) *((uint32_t *)op->dataptr) = (int)n; else if (op->type == OP_SIZE) *((PCRE2_SIZE *)op->dataptr) = n; - else *((int *)op->dataptr) = n; + else *((int *)op->dataptr) = (int)n; } } diff --git a/src/pcre2test.c b/src/pcre2test.c index 9d76ea45c..b468c8556 100644 --- a/src/pcre2test.c +++ b/src/pcre2test.c @@ -9820,7 +9820,7 @@ least 128 code units, because it is used for retrieving error messages. */ for (;;) { - errcode = strtol(arg_error, &endptr, 10); + errcode = (int)strtol(arg_error, &endptr, 10); if (*endptr != 0 && *endptr != CHAR_COMMA) { fprintf(stderr, "** \"%s\" is not a valid error number list\n", arg_error);