Skip to content

Commit

Permalink
Fix #717
Browse files Browse the repository at this point in the history
`OnTuplesPerm` left negative integers invariant instead of giving an
error, which would be consistent with the manual.
  • Loading branch information
markuspf committed May 9, 2016
1 parent 3eafd4e commit 87eaad6
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/permutat.c
Original file line number Diff line number Diff line change
Expand Up @@ -4113,6 +4113,7 @@ Obj OnTuplesPerm (
UInt lmp; /* largest moved point */
UInt i, k; /* loop variables */

tmp = NULL; /* stop compiler from complaining */
/* make a bag for the result and initialize pointers */
res = NEW_PLIST( IS_MUTABLE_PLIST(tup) ? T_PLIST : T_PLIST + IMMUTABLE,
LEN_LIST(tup) );
Expand All @@ -4129,11 +4130,11 @@ Obj OnTuplesPerm (

/* loop over the entries of the tuple */
for ( i = LEN_LIST(tup); 1 <= i; i--, ptTup--, ptRes-- ) {
if (IS_INTOBJ(*ptTup)) {
if (IS_INTOBJ(*ptTup) && (0 < INT_INTOBJ(*ptTup))) {
k = INT_INTOBJ( *ptTup );
if ( k <= 0 || k > lmp )
if (k > lmp) {
tmp = *ptTup;
else
} else
tmp = INTOBJ_INT( ptPrm2[k-1] + 1 );
*ptRes = tmp;
}
Expand Down Expand Up @@ -4164,11 +4165,11 @@ Obj OnTuplesPerm (

/* loop over the entries of the tuple */
for ( i = LEN_LIST(tup); 1 <= i; i--, ptTup--, ptRes-- ) {
if (IS_INTOBJ(*ptTup)) {
if (IS_INTOBJ(*ptTup) && (0 < INT_INTOBJ(*ptTup))) {
k = INT_INTOBJ( *ptTup );
if ( k <= 0 || k > lmp )
if (k > lmp) {
tmp = *ptTup;
else
} else
tmp = INTOBJ_INT( ptPrm4[k-1] + 1 );
*ptRes = tmp;
}
Expand Down

0 comments on commit 87eaad6

Please sign in to comment.