Skip to content

Commit

Permalink
kernel: fix bug in LtTrans24 in trans.c
Browse files Browse the repository at this point in the history
This commit fixes a bug in LtTrans24, a for loop was incorrectly nested.
In order to increase the test coverage to include this part of the code
(and a number of other parts of the code in trans.c that were previously
unreachable) IdentityTrans is altered to be a T_TRANS4. Tests are added
for this part of the code, and the other previously unreachable parts.
  • Loading branch information
James Mitchell committed Feb 8, 2017
1 parent c5272cb commit 5be5f2a
Show file tree
Hide file tree
Showing 2 changed files with 213 additions and 57 deletions.
118 changes: 61 additions & 57 deletions src/trans.c
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ extern UInt INIT_TRANS4 (Obj f) {
if (deg == 0) {
// Special case for degree 0.

// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

img = NEW_PLIST(T_PLIST_EMPTY + IMMUTABLE, 0);
SET_LEN_PLIST(img, 0);
Expand Down Expand Up @@ -1866,9 +1866,9 @@ Obj FuncPermLeftQuoTransformationNC (Obj self, Obj f, Obj g) {
ptp[i] = ptg4[i];
}
for (; i < def; i++) {
// This can't happen with transformations created within this file since
// a transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
ptp[ptf2[i]] = i;
}
} else if (TNUM_OBJ(f) == T_TRANS4 && TNUM_OBJ(g) == T_TRANS2) {
Expand All @@ -1882,9 +1882,9 @@ Obj FuncPermLeftQuoTransformationNC (Obj self, Obj f, Obj g) {
ptp[ptf4[i]] = ptg2[i];
}
for (; i < deg; i++) {
// This can't happen with transformations created within this file since
// a transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
ptp[i] = ptg2[i];
}
for (; i < def; i++) {
Expand Down Expand Up @@ -3145,9 +3145,9 @@ Obj FuncTRANS_IMG_CONJ (Obj self, Obj f, Obj g) {

// if def = min, then this isn't executed
for (; i < def; i++) {
// This can't happen with transformations created within this file since
// a transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
ptsrc[ptf2[i]] = 1;
ptdst[i] = 1;
ptp[ptf2[i]] = i;
Expand All @@ -3164,9 +3164,9 @@ Obj FuncTRANS_IMG_CONJ (Obj self, Obj f, Obj g) {

// if deg = min, then this isn't executed
for (; i < deg; i++) {
// This can't happen with transformations created within this file since
// a transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
//ptsrc[i] = 1;
ptdst[ptg2[i]] = 1;
ptp[i] = ptg2[i];
Expand Down Expand Up @@ -3643,9 +3643,9 @@ Int EqTrans24 (Obj f, Obj g) {
}
}
} else {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < deg; i++) {
if (*(ptf++) != *(ptg++)) {
Expand Down Expand Up @@ -3673,9 +3673,9 @@ Int EqTrans42 (Obj f, Obj g) {
deg = DEG_TRANS2(g);

if (def <= deg) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < def; i++) {
if (* (ptf++) != * (ptg++)) {
Expand Down Expand Up @@ -3789,9 +3789,9 @@ Int LtTrans24 (Obj f, Obj g) {
}
}
} else {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < deg; i++) {
if (ptf[i] != ptg[i]) {
Expand All @@ -3801,13 +3801,13 @@ Int LtTrans24 (Obj f, Obj g) {
return 0L;
}
}
for (; i < def; i++) {
if (ptf[i] != i) {
if (i > ptf[i]) {
return 1L;
} else {
return 0L;
}
}
for (; i < def; i++) {
if (ptf[i] != i) {
if (i > ptf[i]) {
return 1L;
} else {
return 0L;
}
}
}
Expand All @@ -3826,9 +3826,9 @@ Int LtTrans42 (Obj f, Obj g) {
deg = DEG_TRANS2(g);

if (def <= deg) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < def; i++) {
if (ptf[i] != ptg[i]) {
Expand Down Expand Up @@ -3977,9 +3977,9 @@ Obj ProdTrans24 (Obj f, Obj g) {
*ptfg++ = ptg[i];
}
} else {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < def; i++) {
*(ptfg++) = IMAGE(ptf[i], ptg, deg);
Expand All @@ -3998,16 +3998,16 @@ Obj ProdTrans42 (Obj f, Obj g) {
def = DEG_TRANS4(f);
deg = DEG_TRANS2(g);

fg = NEW_TRANS4(def);
fg = NEW_TRANS4(MAX(def, deg));

ptfg = ADDR_TRANS4(fg);
ptf = ADDR_TRANS4(f);
ptg = ADDR_TRANS2(g);

if (def <= deg) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.

for (i = 0; i < def; i++) {
*(ptfg++) = ptg[*(ptf++)];
Expand Down Expand Up @@ -4131,9 +4131,9 @@ Obj ProdTrans4Perm2 (Obj f, Obj p) {
ptp = ADDR_PERM2(p);

if (def <= dep) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
for (i = 0; i < def; i++) {
*(ptfp++) = ptp[*(ptf++)];
}
Expand Down Expand Up @@ -4230,9 +4230,9 @@ Obj ProdPerm2Trans4 (Obj p, Obj f) {
*(ptpf++) = ptf[i];
}
} else {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
for (i = 0; i < dep; i++) {
*(ptpf++) = IMAGE(ptp[i], ptf, def);
}
Expand Down Expand Up @@ -4376,9 +4376,9 @@ Obj PowTrans4Perm2 (Obj f, Obj p) {
ptp = ADDR_PERM2(p);

if (def == dep) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
for (i = 0; i < decnj; i++) {
ptcnj[ptp[i]] = ptp[ptf[i]];
}
Expand Down Expand Up @@ -4519,9 +4519,9 @@ Obj QuoTrans4Perm2 (Obj f, Obj p) {
ptquo = ADDR_TRANS4(quo);

if (def <= dep) {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
for (i = 0; i < def; i++) {
*(ptquo++) = pttmp[*(ptf++)];
}
Expand Down Expand Up @@ -4632,9 +4632,9 @@ Obj LQuoPerm2Trans4 (Obj opL, Obj opR) {
ptM[p] = *(ptR++);
}
} else {
// This can't happen with transformations created within this file since a
// transformation is of type T_TRANS4 if and only if it has (internal)
// degree 65537 or greater. It is included to make the code more robust.
// The only transformation created within this file that is of type
// T_TRANS4 and that does not have (internal) degree 65537 or greater
// is IdentityTrans.
for (p = 0; p < degR; p++) {
ptM[*(ptL++) ] = *(ptR++);
}
Expand Down Expand Up @@ -5338,7 +5338,11 @@ static Int InitLibrary ( StructInitInfo *module )
InitGVarFuncsFromTable( GVarFuncs );
InitGVarFiltsFromTable( GVarFilts );
TmpTrans = 0;
IdentityTrans = NEW_TRANS2(0);
// We make the next transformation a T_TRANS4 to allow testing of some
// parts of the code which would not otherwise be accessible, since no
// other transformation created in this file is a T_TRANS4 unless its
// internal degree is > 65536.
IdentityTrans = NEW_TRANS4(0);

/* return success */
return 0;
Expand Down
Loading

0 comments on commit 5be5f2a

Please sign in to comment.