]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
curl: make the etag load logic work without fseek
authorDaniel Stenberg <daniel@haxx.se>
Fri, 6 Dec 2019 16:24:52 +0000 (17:24 +0100)
committerDaniel Stenberg <daniel@haxx.se>
Fri, 6 Dec 2019 22:02:24 +0000 (23:02 +0100)
The fseek()s were unnecessary and caused Coverity warning CID 1456554

Closes #4681

src/tool_operate.c

index e78cc4fd207c8a84b202df37fe84bfb2a50397b0..4c9b07e392469ed011437dc5f2629a0ff339728d 100644 (file)
@@ -922,7 +922,6 @@ static CURLcode single_transfer(struct GlobalConfig *global,
         if(config->etag_compare_file) {
           char *etag_from_file = NULL;
           char *header = NULL;
-          size_t file_size = 0;
 
           /* open file for reading: */
           FILE *file = fopen(config->etag_compare_file, FOPEN_READTEXT);
@@ -935,23 +934,11 @@ static CURLcode single_transfer(struct GlobalConfig *global,
             break;
           }
 
-          /* get file size */
-          fseek(file, 0, SEEK_END);
-          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);
-
+          if((PARAM_OK == file2string(&etag_from_file, file)) &&
+             etag_from_file)
             header = aprintf("If-None-Match: \"%s\"", etag_from_file);
-          }
-          else {
+          else
             header = aprintf("If-None-Match: \"\"");
-          }
 
           if(!header) {
             warnf(