diff options
author | Tobias Stoeckmann <stoeckmann@users.noreply.github.com> | 2022-04-13 03:01:02 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-04-13 03:01:02 (GMT) |
commit | 0859368335d470b9ff33fc53ed9a85ec2654b278 (patch) | |
tree | 51a39bc30ccbf02ba40f80ff6e0bced6ac47702c /Objects/unicodeobject.c | |
parent | ac6c3de03c5bb06a9a463701fb297148f5a5746f (diff) | |
download | cpython-0859368335d470b9ff33fc53ed9a85ec2654b278.zip cpython-0859368335d470b9ff33fc53ed9a85ec2654b278.tar.gz cpython-0859368335d470b9ff33fc53ed9a85ec2654b278.tar.bz2 |
gh-91421: Use constant value check during runtime (GH-91422)
The left-hand side expression of the if-check can be converted to a
constant by the compiler, but the addition on the right-hand side is
performed during runtime.
Move the addition from the right-hand side to the left-hand side by
turning it into a subtraction there. Since the values are known to
be large enough to not turn negative, this is a safe operation.
Prevents a very unlikely integer overflow on 32 bit systems.
Fixes GH-91421.
Diffstat (limited to 'Objects/unicodeobject.c')
-rw-r--r-- | Objects/unicodeobject.c | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index c665f57..d35a671 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -5296,7 +5296,7 @@ _Py_DecodeUTF8Ex(const char *s, Py_ssize_t size, wchar_t **wstr, size_t *wlen, /* Note: size will always be longer than the resulting Unicode character count */ - if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) < (size + 1)) { + if (PY_SSIZE_T_MAX / (Py_ssize_t)sizeof(wchar_t) - 1 < size) { return -1; } |