From 9ce62e5c8ea0157619b698a0243b54236aa8f986 Mon Sep 17 00:00:00 2001 From: Oswald Buddenhagen Date: Tue, 6 Dec 2016 14:17:22 +0100 Subject: [PATCH] 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 --- src/libs/utils/process_stub_unix.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libs/utils/process_stub_unix.c b/src/libs/utils/process_stub_unix.c index 302f8212a08..b24868cd85a 100644 --- a/src/libs/utils/process_stub_unix.c +++ b/src/libs/utils/process_stub_unix.c @@ -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 *));