Browse Source

py/objdeque: Fix sign extension bug when computing len of deque object.

For cases where size_t is smaller than mp_int_t (eg nan-boxing builds) the
difference between two size_t's is not sign extended into mp_int_t and so
the result is never negative.  This patch fixes this bug by using ssize_t
for the type of the result.
pull/3771/merge
Damien George 7 years ago
parent
commit
095d397017
  1. 3
      py/objdeque.c

3
py/objdeque.c

@ -24,6 +24,7 @@
* THE SOFTWARE.
*/
#include <unistd.h> // for ssize_t
#include <string.h>
#include "py/mpconfig.h"
@ -75,7 +76,7 @@ STATIC mp_obj_t deque_unary_op(mp_unary_op_t op, mp_obj_t self_in) {
case MP_UNARY_OP_BOOL:
return mp_obj_new_bool(self->i_get != self->i_put);
case MP_UNARY_OP_LEN: {
mp_int_t len = self->i_put - self->i_get;
ssize_t len = self->i_put - self->i_get;
if (len < 0) {
len += self->alloc;
}

Loading…
Cancel
Save