A small fix to pcre2grep to avoid compiler warnings for -Wformat-overflow=2.

This commit is contained in:
Philip.Hazel 2018-02-25 12:12:48 +00:00
parent 04919e9d03
commit ee7e093af0
2 changed files with 17 additions and 8 deletions

View File

@ -28,6 +28,8 @@ repeating character classes were overlooked.
5. pcre2grep now supports the inclusion of binary zeros in patterns that are 5. pcre2grep now supports the inclusion of binary zeros in patterns that are
read from files via the -f option. read from files via the -f option.
6. A small fix to pcre2grep to avoid compiler warnings for -Wformat-overflow=2.
Version 10.31 12-February-2018 Version 10.31 12-February-2018
------------------------------ ------------------------------

View File

@ -3669,8 +3669,15 @@ for (i = 1; i < argc; i++)
int arglen = (argequals == NULL || equals == NULL)? int arglen = (argequals == NULL || equals == NULL)?
(int)strlen(arg) : (int)(argequals - arg); (int)strlen(arg) : (int)(argequals - arg);
sprintf(buff1, "%.*s", baselen, op->long_name); if (snprintf(buff1, sizeof(buff1), "%.*s", baselen, op->long_name) >
sprintf(buff2, "%s%.*s", buff1, fulllen - baselen - 2, opbra + 1); (int)sizeof(buff1) ||
snprintf(buff2, sizeof(buff2), "%s%.*s", buff1,
fulllen - baselen - 2, opbra + 1) > (int)sizeof(buff2))
{
fprintf(stderr, "pcre2grep: Buffer overflow when parsing %s option\n",
op->long_name);
pcre2grep_exit(2);
}
if (strncmp(arg, buff1, arglen) == 0 || if (strncmp(arg, buff1, arglen) == 0 ||
strncmp(arg, buff2, arglen) == 0) strncmp(arg, buff2, arglen) == 0)