Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/pcre2_jit_neon_inc.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@zherczeg I just wanted to point out this small change in the NEON code. I think it's correct.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Likely. diff is a value between 0 and 31

PCRE2_UCHAR char1a = ic.c.c1;
PCRE2_UCHAR char2a = ic.c.c3;

Expand Down
60 changes: 49 additions & 11 deletions src/pcre2grep.c
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,9 @@ POSSIBILITY OF SUCH DAMAGE.
#endif

#include <ctype.h>
#include <limits.h>
#include <locale.h>
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
Expand Down Expand Up @@ -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)
{
Expand All @@ -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

Expand All @@ -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;
}


Expand Down Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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;
}
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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;
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/pcre2test.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down