fix coverity complaint the right way

use an assert to document in a machine-readable form that the file is
expected to be null-terminated. this supersedes 5a58e962's approach of
appending a null char, which would just obfuscate a problem in the calling
code if it were to ever have an effect.

Change-Id: Iaedb575d20abb42d98e011949e792ecf4dde3e93
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
This commit is contained in:
Oswald Buddenhagen
2016-12-06 14:17:22 +01:00
parent b9a8bed037
commit 9ce62e5c8e

View File

@@ -224,13 +224,13 @@ int main(int argc, char *argv[])
fseek(envFd, 0, SEEK_END);
size = ftell(envFd);
rewind(envFd);
envdata = malloc(size + 1);
envdata = malloc(size);
if (fread(envdata, 1, size, envFd) != (size_t)size) {
perror("Failed to read env file");
doExit(1);
}
envdata[size] = '\0';
fclose(envFd);
assert(!size || !envdata[size - 1]);
for (count = 0, edp = envdata; edp < envdata + size; ++count)
edp += strlen(edp) + 1;
env = malloc((count + 2) * sizeof(char *));