diff options
author | Anatol Belski <ab@php.net> | 2014-09-14 16:37:38 +0200 |
---|---|---|
committer | Anatol Belski <ab@php.net> | 2014-09-14 16:39:25 +0200 |
commit | 29f8b21cd71bc4af1ead7b8a93cfe09338d2eff5 (patch) | |
tree | 417e23ddffafc61490d59bb31048cc245a038e43 /ext/standard/strnatcmp.c | |
parent | eda5ba1f8fa935b8d1b8bae9d189c6afbe833287 (diff) | |
download | php-git-29f8b21cd71bc4af1ead7b8a93cfe09338d2eff5.tar.gz |
fix int overflow preserving the old behavior
Diffstat (limited to 'ext/standard/strnatcmp.c')
-rw-r--r-- | ext/standard/strnatcmp.c | 21 |
1 files changed, 19 insertions, 2 deletions
diff --git a/ext/standard/strnatcmp.c b/ext/standard/strnatcmp.c index face191a6e..7b3826b5be 100644 --- a/ext/standard/strnatcmp.c +++ b/ext/standard/strnatcmp.c @@ -108,8 +108,25 @@ PHPAPI int strnatcmp_ex(char const *a, size_t a_len, char const *b, size_t b_len int fractional, result; short leading = 1; - if (a_len == 0 || b_len == 0) - return a_len - b_len; + if (a_len == 0 || b_len == 0) { + result = 0; + + if (a_len > b_len) { + if (a_len - b_len <= INT_MAX) { + result = (int)(a_len - b_len); + } else { + result = 1; + } + } else { + if (b_len - a_len <= (size_t)(-INT_MIN)) { + result = -(int)(b_len - a_len); + } else { + result = -1; + } + } + + return result; + } ap = a; bp = b; |