]> git.ipfire.org Git - thirdparty/curl.git/commitdiff
file2memory: use a define instead of -1 unsigned value
authorDaniel Stenberg <daniel@haxx.se>
Wed, 15 Jul 2020 12:04:32 +0000 (14:04 +0200)
committerDaniel Stenberg <daniel@haxx.se>
Wed, 15 Jul 2020 22:34:05 +0000 (00:34 +0200)
... to use the maximum value for 'size_t' when detecting integer overflow.
Changed the limit to max/4 as already that seems unreasonably large.

Codacy didn't like the previous approach.

Closes #5683

src/tool_paramhlp.c

index c375bcc8249e49484389e962320f7382d2637af7..e57daa2e12e4c4c696f3bc3e08f875afbb8fa47a 100644 (file)
@@ -115,8 +115,8 @@ ParameterError file2memory(char **bufp, size_t *size, FILE *file)
     size_t alloc = 512;
     do {
       if(!buffer || (alloc == nused)) {
-        /* size_t overflow detection for huge files */
-        if(alloc + 1 > ((size_t)-1)/2) {
+        /* size_t overflow detection and avoiding huge files */
+        if(alloc >= (SIZE_T_MAX/4)) {
           Curl_safefree(buffer);
           return PARAM_NO_MEM;
         }