diff options
Diffstat (limited to 'src/tool_urlglob.c')
-rw-r--r-- | src/tool_urlglob.c | 30 |
1 files changed, 20 insertions, 10 deletions
diff --git a/src/tool_urlglob.c b/src/tool_urlglob.c index 69016179d..8ae28a3a6 100644 --- a/src/tool_urlglob.c +++ b/src/tool_urlglob.c @@ -66,13 +66,23 @@ static CURLcode glob_fixed(struct URLGlob *glob, char *fixed, size_t len) */ static int multiply(curl_off_t *amount, curl_off_t with) { - curl_off_t sum = *amount * with; - if(!with) { - *amount = 0; - return 0; + curl_off_t sum; + DEBUGASSERT(*amount >= 0); + DEBUGASSERT(with >= 0); + if((with <= 0) || (*amount <= 0)) { + sum = 0; + } + else { +#if defined(__GNUC__) && \ + ((__GNUC__ > 5) || ((__GNUC__ == 5) && (__GNUC_MINOR__ >= 1))) + if(__builtin_mul_overflow(*amount, with, &sum)) + return 1; +#else + sum = *amount * with; + if(sum/with != *amount) + return 1; /* didn't fit, bail out */ +#endif } - if(sum/with != *amount) - return 1; /* didn't fit, bail out */ *amount = sum; return 0; } @@ -117,7 +127,7 @@ static CURLcode glob_set(struct URLGlob *glob, char **patternp, if(multiply(amount, pat->content.Set.size + 1)) return GLOBERROR("range overflow", 0, CURLE_URL_MALFORMAT); - /* FALLTHROUGH */ + FALLTHROUGH(); case ',': *buf = '\0'; @@ -161,7 +171,7 @@ static CURLcode glob_set(struct URLGlob *glob, char **patternp, ++pattern; ++(*posp); } - /* FALLTHROUGH */ + FALLTHROUGH(); default: *buf++ = *pattern++; /* copy character to set element */ ++(*posp); @@ -692,7 +702,7 @@ CURLcode glob_match_url(char **result, char *filename, struct URLGlob *glob) if(curlx_dyn_addn(&dyn, "", 0)) return CURLE_OUT_OF_MEMORY; -#if defined(MSDOS) || defined(WIN32) +#if defined(_WIN32) || defined(MSDOS) { char *sanitized; SANITIZEcode sc = sanitize_file_name(&sanitized, curlx_dyn_ptr(&dyn), @@ -707,5 +717,5 @@ CURLcode glob_match_url(char **result, char *filename, struct URLGlob *glob) #else *result = curlx_dyn_ptr(&dyn); return CURLE_OK; -#endif /* MSDOS || WIN32 */ +#endif /* _WIN32 || MSDOS */ } |