forked from github/server
coverity scan CID 22504: argument cannot be negative
handle error cases for ftell, just because they could happen, I guess?
This commit is contained in:
parent
976b6aaea1
commit
4384183ab8
1 changed files with 7 additions and 5 deletions
|
@ -67,14 +67,16 @@ int config_read(const char *filename, const char * relpath)
|
||||||
if (F) {
|
if (F) {
|
||||||
int result;
|
int result;
|
||||||
char *data;
|
char *data;
|
||||||
size_t sz;
|
|
||||||
|
|
||||||
fseek(F, 0, SEEK_END);
|
fseek(F, 0, SEEK_END);
|
||||||
sz = ftell(F);
|
result = ftell(F);
|
||||||
rewind(F);
|
rewind(F);
|
||||||
|
if (result > 0) {
|
||||||
|
size_t sz = (size_t)result;
|
||||||
data = malloc(sz);
|
data = malloc(sz);
|
||||||
fread(data, 1, sz, F);
|
fread(data, 1, sz, F);
|
||||||
fclose(F);
|
fclose(F);
|
||||||
|
}
|
||||||
result = config_parse(data);
|
result = config_parse(data);
|
||||||
free(data);
|
free(data);
|
||||||
return result;
|
return result;
|
||||||
|
|
Loading…
Reference in a new issue