diff options
author | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-18 21:42:54 +0300 |
---|---|---|
committer | Paul Sokolovsky <pfalcon@users.sourceforge.net> | 2014-04-18 21:42:54 +0300 |
commit | 83eba5dec5b8ed7134a2a27a8824d271acee5711 (patch) | |
tree | 93fa2ecc03856424c37b43abc84e6b7b9fc3326b /py | |
parent | 7de5377ca7eeb7828031f83be417cda3a188069b (diff) | |
download | micropython-83eba5dec5b8ed7134a2a27a8824d271acee5711.tar.gz micropython-83eba5dec5b8ed7134a2a27a8824d271acee5711.zip |
sequence: Fix glaring bug in sequence comparison.
Diffstat (limited to 'py')
-rw-r--r-- | py/sequence.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/py/sequence.c b/py/sequence.c index 3a4d65d53b..7ea3f708f1 100644 --- a/py/sequence.c +++ b/py/sequence.c @@ -1,3 +1,4 @@ +#include <assert.h> #include <stdbool.h> #include <string.h> @@ -109,18 +110,24 @@ bool mp_seq_cmp_objs(int op, const mp_obj_t *items1, uint len1, const mp_obj_t * int len = len1 < len2 ? len1 : len2; bool eq_status = true; // empty lists are equal - bool rel_status; for (int i = 0; i < len; i++) { eq_status = mp_obj_equal(items1[i], items2[i]); - if (op == MP_BINARY_OP_EQUAL && !eq_status) { - return false; + // If current elements equal, can't decide anything - go on + if (eq_status) { + continue; } - rel_status = (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); - if (!eq_status && !rel_status) { + + // Othewise, if they are not equal, we can have final decision based on them + if (op == MP_BINARY_OP_EQUAL) { + // In particular, if we are checking for equality, here're the answer return false; } + + // Otherwise, application of relation op gives the answer + return (mp_binary_op(op, items1[i], items2[i]) == mp_const_true); } + assert(eq_status); // If we had tie in the last element... if (eq_status) { // ... and we have lists of different lengths... |