coverity/15019: String not null terminated: FP.

Problem    : String not null terminated @ 1165.
Diagnostic : False positive.
Rationale  : Code below terminates string (with NUL or '\n').
Resolution : Add explanatory comment, and assert termination.
             Mark as Intentional at coverity's database.
This commit is contained in:
Eliseo Martínez 2015-01-27 15:51:52 +01:00 committed by Justin M. Keyes
parent ab86da74c4
commit 323f0488c2

View File

@ -13,6 +13,7 @@
* changed beyond recognition.
*/
#include <assert.h>
#include <errno.h>
#include <inttypes.h>
#include <stdbool.h>
@ -1162,6 +1163,8 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
len = ftell(fd); /* get size of temp file */
fseek(fd, 0L, SEEK_SET);
buffer = xmalloc(len + 1);
// fread() doesn't terminate buffer with NUL;
// appropiate termination (not always NUL) is done below.
i = fread((char *)buffer, 1, len, fd);
fclose(fd);
os_remove((char *)tempname);
@ -1174,8 +1177,6 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
}
free(tempname);
/* file names are separated with Space */
if (shell_style == STYLE_ECHO) {
buffer[len] = '\n'; /* make sure the buffer ends in NL */
@ -1235,6 +1236,8 @@ int mch_expand_wildcards(int num_pat, char_u **pat, int *num_file,
if (len)
++i; /* count last entry */
}
assert(buffer[len] == NUL || buffer[len] == '\n');
if (i == 0) {
/*
* Can happen when using /bin/sh and typing ":e $NO_SUCH_VAR^I".