py/sequence.c: Add an early return.

Signed-off-by: Félix Richart <felix.richart@numworks.com>
pull/12131/head
Félix Richart 2023-08-01 09:25:26 +02:00
rodzic df421e0125
commit e0a6696572
1 zmienionych plików z 4 dodań i 1 usunięć

Wyświetl plik

@ -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);