1
0
mirror of https://github.com/moparisthebest/curl synced 2024-12-24 09:08:49 -05:00

curl: make the etag load logic work without fseek

The fseek()s were unnecessary and caused Coverity warning CID 1456554

Closes #4681
This commit is contained in:
Daniel Stenberg 2019-12-06 17:24:52 +01:00
parent b62038bfa6
commit 147fa06891
No known key found for this signature in database
GPG Key ID: 5CC908FDB71E12C2

View File

@ -922,7 +922,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
if(config->etag_compare_file) { if(config->etag_compare_file) {
char *etag_from_file = NULL; char *etag_from_file = NULL;
char *header = NULL; char *header = NULL;
size_t file_size = 0;
/* open file for reading: */ /* open file for reading: */
FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT); FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
@ -935,23 +934,11 @@ static CURLcode single_transfer(struct GlobalConfig *global,
break; break;
} }
/* get file size */ if((PARAM_OK == file2string(&etag_from_file, file)) &&
fseek(file, 0, SEEK_END); etag_from_file)
file_size = ftell(file);
/*
* check if file is empty, if it's not load etag
* else continue with empty etag
*/
if(file_size != 0) {
fseek(file, 0, SEEK_SET);
file2string(&etag_from_file, file);
header = aprintf("If-None-Match: \"%s\"", etag_from_file); header = aprintf("If-None-Match: \"%s\"", etag_from_file);
} else
else {
header = aprintf("If-None-Match: \"\""); header = aprintf("If-None-Match: \"\"");
}
if(!header) { if(!header) {
warnf( warnf(