library: Remove dead branch in file2strvec

A while loop used n >=0
A branch inside the loop had a test for n<0
That's never going to happen!
So the branch must go. There is similiar code outside
the branch. Yes, I miss pythons while else here.

Also cleaned up the ***-awful indentation this function had.
No wonder that branch lived for so long there.

References:
 Coverity #99119

Signed-off-by: Craig Small <csmall@dropbear.xyz>
This commit is contained in:
Craig Small 2016-05-14 22:43:19 +10:00
parent 4f6b8c9c60
commit f85d9a2b95

View File

@ -624,7 +624,8 @@ static char** file2strvec(const char* directory, const char* what) {
sprintf(buf, "%s/%s", directory, what);
fd = open(buf, O_RDONLY, 0);
if(fd==-1) return NULL;
if(fd==-1)
return NULL;
/* read whole file into a memory buffer, allocating as we go */
while ((n = read(fd, buf, sizeof buf - 1)) >= 0) {
@ -634,12 +635,6 @@ static char** file2strvec(const char* directory, const char* what) {
close(fd);
return NULL; /* process died between our open and read */
}
if (n < 0) {
if (rbuf)
free(rbuf);
close(fd);
return NULL; /* read error */
}
if (end_of_file && (n == 0 || buf[n-1]))/* last read char not null */
buf[n++] = '\0'; /* so append null-terminator */
rbuf = xrealloc(rbuf, tot + n); /* allocate more memory */
@ -650,7 +645,8 @@ static char** file2strvec(const char* directory, const char* what) {
}
close(fd);
if (n <= 0 && !end_of_file) {
if (rbuf) free(rbuf);
if (rbuf)
free(rbuf);
return NULL; /* read error */
}
endbuf = rbuf + tot; /* count space for pointers */