Tidies and minor bug fix resulting from Coverity Scan issues.

This commit is contained in:
Philip.Hazel 2017-04-16 16:49:11 +00:00
parent e21268b367
commit 41d1c6d6ce
6 changed files with 47 additions and 33 deletions

View File

@ -140,6 +140,15 @@ particular when it is serialized.
27. Update pcre2test, remove some unused code in pcre2_match(), and upgrade the
tests to improve coverage.
28. Some fixes/tidies as a result of looking at Coverity Scan output:
(a) Typo: ">" should be ">=" in opcode check in pcre2_auto_possess.c.
(b) Added some casts to avoid "suspicious implicit sign extension".
(c) Resource leaks in pcre2test in rare error cases.
(d) Avoid warning for never-use case OP_TABLE_LENGTH which is just a fudge
for checking at compile time that tables are the right size.
(e) Add missing "fall through" comment.
Version 10.23 14-February-2017
------------------------------

View File

@ -1075,7 +1075,7 @@ for (;;)
{
c = *code;
if (c > OP_TABLE_LENGTH) return -1; /* Something gone wrong */
if (c >= OP_TABLE_LENGTH) return -1; /* Something gone wrong */
if (c >= OP_STAR && c <= OP_TYPEPOSUPTO)
{

View File

@ -8440,6 +8440,7 @@ for (;; pptr++)
case META_BACKREF_BYNAME:
if ((cb->external_options & PCRE2_MATCH_UNSET_BACKREF) != 0)
goto ISNOTFIXED;
/* Fall through */
case META_RECURSE_BYNAME:
{
@ -9274,7 +9275,8 @@ possible because nowadays we limit the maximum value of cb.names_found and
cb.name_entry_size. */
re_blocksize = sizeof(pcre2_real_code) +
CU2BYTES(length + cb.names_found * cb.name_entry_size);
CU2BYTES(length +
(PCRE2_SIZE)cb.names_found * (PCRE2_SIZE)cb.name_entry_size);
re = (pcre2_real_code *)
ccontext->memctl.malloc(re_blocksize, ccontext->memctl.memory_data);
if (re == NULL)

View File

@ -697,7 +697,7 @@ for (;;)
case OP_TABLE_LENGTH +
((sizeof(coptable) == OP_TABLE_LENGTH) &&
(sizeof(poptable) == OP_TABLE_LENGTH)):
break;
return 0;
/* ========================================================================== */
/* Reached a closing bracket. If not at the end of the pattern, carry

View File

@ -340,7 +340,7 @@ for(;;)
case OP_TABLE_LENGTH +
((sizeof(OP_names)/sizeof(const char *) == OP_TABLE_LENGTH) &&
(sizeof(OP_lengths) == OP_TABLE_LENGTH)):
break;
return;
/* ========================================================================== */
case OP_END:

View File

@ -4434,7 +4434,7 @@ process_command(void)
FILE *f;
PCRE2_SIZE serial_size;
size_t i;
int rc, cmd, cmdlen;
int rc, cmd, cmdlen, yield;
uint16_t first_listed_newline;
const char *cmdname;
uint8_t *argptr, *serial;
@ -4445,6 +4445,7 @@ if (restrict_for_perl_test)
return PR_ABEND;
}
yield = PR_OK;
cmd = CMD_UNKNOWN;
cmdlen = 0;
@ -4568,8 +4569,8 @@ switch(cmd)
general_context);
if (rc < 0)
{
if (!serial_error(rc, "Serialization")) return PR_ABEND;
fclose(f);
if (!serial_error(rc, "Serialization")) return PR_ABEND;
break;
}
@ -4615,19 +4616,20 @@ switch(cmd)
return PR_ABEND;
}
if (fread(serial, 1, serial_size, f) != serial_size)
{
fprintf(outfile, "** Wrong return from fread()\n");
free(serial);
fclose(f);
return PR_ABEND;
}
i = fread(serial, 1, serial_size, f);
fclose(f);
if (i != serial_size)
{
fprintf(outfile, "** Wrong return from fread()\n");
yield = PR_ABEND;
}
else
{
PCRE2_SERIALIZE_GET_NUMBER_OF_CODES(rc, serial);
if (rc < 0)
{
if (!serial_error(rc, "Get number of codes")) return PR_ABEND;
if (!serial_error(rc, "Get number of codes")) yield = PR_ABEND;
}
else
{
@ -4643,16 +4645,17 @@ switch(cmd)
general_context);
if (rc < 0)
{
if (!serial_error(rc, "Deserialization")) return PR_ABEND;
if (!serial_error(rc, "Deserialization")) yield = PR_ABEND;
}
else patstacknext += rc;
}
}
free(serial);
break;
}
return PR_OK;
return yield;
}