Skip to content

Commit

Permalink
kernel: tweak error handling in permutation parsing
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin authored and ChrisJefferson committed Nov 26, 2018
1 parent 271c7c8 commit 3527f26
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
9 changes: 5 additions & 4 deletions src/exprs.c
Original file line number Diff line number Diff line change
Expand Up @@ -849,10 +849,9 @@ Obj EvalPermExpr (
/* check that the cycles are disjoint */
ptr4 = ADDR_PERM4( perm );
if ( (p != 0 && p == c) || (ptr4[c-1] != c-1) ) {
return ErrorReturnObj(
ErrorMayQuit(
"Permutation: cycles must be disjoint and duplicate-free",
0L, 0L,
"you can replace the permutation <perm> via 'return <perm>;'" );
0, 0);
}

/* enter the previous entry at current location */
Expand All @@ -867,7 +866,9 @@ Obj EvalPermExpr (
/* enter first (last popped) entry at last (first popped) location */
ptr4 = ADDR_PERM4( perm );
if (ptr4[l-1] != l-1) {
ErrorQuit("Permutation: cycles must be disjoint and duplicate-free", 0L, 0L );
ErrorMayQuit(
"Permutation: cycles must be disjoint and duplicate-free", 0,
0);
}
ptr4[l-1] = p-1;

Expand Down
12 changes: 6 additions & 6 deletions src/permutat.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2308,8 +2308,7 @@ Obj Array2Perm (

/* get and check current entry for the cycle */
val = ELM_LIST( cycle, j );
RequirePositiveSmallInt("Permutation", val, "expr");
c = INT_INTOBJ(val);
c = GetPositiveSmallInt("Permutation", val, "expr");
if (c > MAX_DEG_PERM4)
ErrorMayQuit( "Permutation literal exceeds maximum permutation degree",
0, 0);
Expand All @@ -2329,10 +2328,9 @@ Obj Array2Perm (
/* check that the cycles are disjoint */
ptr4 = ADDR_PERM4( perm );
if ( (p != 0 && p == c) || (ptr4[c-1] != c-1) ) {
return ErrorReturnObj(
ErrorMayQuit(
"Permutation: cycles must be disjoint and duplicate-free",
0L, 0L,
"you can replace the permutation <perm> via 'return <perm>;'" );
0, 0);
}

/* enter the previous entry at current location */
Expand All @@ -2347,7 +2345,9 @@ Obj Array2Perm (
/* enter first (last popped) entry at last (first popped) location */
ptr4 = ADDR_PERM4( perm );
if (ptr4[l-1] != l-1) {
ErrorQuit("Permutation: cycles must be disjoint and duplicate-free", 0L, 0L );
ErrorMayQuit(
"Permutation: cycles must be disjoint and duplicate-free", 0,
0);
}
ptr4[l-1] = p-1;

Expand Down

0 comments on commit 3527f26

Please sign in to comment.