coverity/68610: Out-of-bounds access: FP.

Diagnostic : False positive.
Rationale  : Coverity thinks we are forgetting to add more char to hold
             NULL, but it's not taking into account that two chars from
             cntxformat will no be present in the result. In fact, we
             can even allocate one byte less than currently done.
Resolution : Add explanatory comment and allocate one less byte.
             Marked as "Intentional" at coverity's database.
This commit is contained in:
Eliseo Martínez 2015-01-27 15:22:36 +01:00 committed by Justin M. Keyes
parent 828a18722c
commit ab86da74c4

View File

@ -1646,7 +1646,6 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
char *fname, *lno, *extra, *tbuf;
int i, idx, num;
char *globalcntx = "GLOBAL";
char *cntxformat = " <<%s>>";
char *context;
char *cstag_msg = _("Cscope tag: %s");
@ -1706,7 +1705,11 @@ static void cs_print_tags_priv(char **matches, char **cntxts, int num_matches)
context = cntxts[idx];
else
context = globalcntx;
newsize = strlen(context) + strlen(cntxformat);
const char *cntxformat = " <<%s>>";
// '%s' won't appear in result string, so:
// newsize = len(cntxformat) - 2 + len(context) + 1 (for NUL).
newsize = strlen(context) + strlen(cntxformat) - 1;
if (bufsize < newsize) {
buf = xrealloc(buf, newsize);