From 235d969727de94be3aa7eff7195e9e694ec931be Mon Sep 17 00:00:00 2001 From: Ed J Date: Wed, 31 Jan 2024 21:02:49 +0000 Subject: [PATCH] getbroadcastid bounds-check for negative, add tests --- Basic/Core/Core.xs | 2 +- t/core.t | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Basic/Core/Core.xs b/Basic/Core/Core.xs index 1b19995a3..098dd827c 100644 --- a/Basic/Core/Core.xs +++ b/Basic/Core/Core.xs @@ -880,7 +880,7 @@ getbroadcastid(x,y) pdl *x PDL_Indx y CODE: - if (y >= x->nbroadcastids) barf("requested invalid broadcastid %"IND_FLAG", nbroadcastids=%"IND_FLAG, y, x->nbroadcastids); + if (y < 0 || y >= x->nbroadcastids) barf("requested invalid broadcastid %"IND_FLAG", nbroadcastids=%"IND_FLAG, y, x->nbroadcastids); RETVAL = x->broadcastids[y]; OUTPUT: RETVAL diff --git a/t/core.t b/t/core.t index 9cf8340cb..8e306eed8 100644 --- a/t/core.t +++ b/t/core.t @@ -587,4 +587,6 @@ is $@, '', 'setdims to same total size of set_donttouchdata should be fine'; eval { $notouch->setdims([3,2]); $notouch->make_physical; }; isnt $@, '', 'setdims/make_physical to different size of set_donttouchdata should fail'; +eval { pdl(3)->getbroadcastid($_) }, isnt $@, '', "getbroadcastid($_) out of range gives error" for -2, 5; + done_testing;