From e0a66965720614972304e48ec9139cd1b9f17cf6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?F=C3=A9lix=20Richart?= Date: Tue, 1 Aug 2023 09:25:26 +0200 Subject: [PATCH] py/sequence.c: Add an early return. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: FĂ©lix Richart --- py/sequence.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/py/sequence.c b/py/sequence.c index be5d77e072..505bd1d005 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -36,7 +36,10 @@ // Implements backend of sequence * integer operation. Assumes elements are // memory-adjacent in sequence. void mp_seq_multiply(const void *items, size_t item_sz, size_t len, size_t times, void *dest) { - if (item_sz != 0 && len != 0 && times != 0 && (len > SIZE_MAX / item_sz || times > SIZE_MAX / (item_sz * len))) { + if (len == 0 || times == 0 || item_sz == 0) { + return; + } + if (len > SIZE_MAX / item_sz || times > SIZE_MAX / (item_sz * len)) { // dest couldn't be correctly allocated in memory because // item_sz * len * times overflows SIZE_MAX. m_malloc_fail(SIZE_MAX);