From dd60f2826f131346509211ba3be533bbd669de63 Mon Sep 17 00:00:00 2001 From: James Mitchell Date: Thu, 5 Apr 2018 10:36:48 +0100 Subject: [PATCH] pperm: fix bug in PreImagePPermInt This occasionally caused incorrect values to be returned when i == deg and by coincidence ptf2[i] == cpt. When ptf2[deg] is beyond the end of the bag containing f, and so is not valid. For reference, this bug caused errors in: https://github.com/gap-packages/Semigroups/pull/296 https://github.com/gap-packages/Semigroups/pull/472 --- src/pperm.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/pperm.c b/src/pperm.c index b1a3248933..360d6f472b 100644 --- a/src/pperm.c +++ b/src/pperm.c @@ -316,17 +316,17 @@ static Obj PreImagePPermInt(Obj pt, Obj f) if (TNUM_OBJ(f) == T_PPERM2) { ptf2 = ADDR_PPERM2(f); deg = DEG_PPERM2(f); - while (ptf2[i] != cpt && i < deg) + while (i < deg && ptf2[i] != cpt) i++; - if (ptf2[i] != cpt) + if (i == deg || ptf2[i] != cpt) return Fail; } else { ptf4 = ADDR_PPERM4(f); deg = DEG_PPERM4(f); - while (ptf4[i] != cpt && i < deg) + while (i < deg && ptf4[i] != cpt) i++; - if (ptf4[i] != cpt) + if (i == deg || ptf4[i] != cpt) return Fail; } return INTOBJ_INT(i + 1);