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.
This commit is contained in:
Damien George 2018-05-11 13:44:50 +10:00
parent b208aa189e
commit 095d397017

View File

@ -24,6 +24,7 @@
* THE SOFTWARE. * THE SOFTWARE.
*/ */
#include <unistd.h> // for ssize_t
#include <string.h> #include <string.h>
#include "py/mpconfig.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: case MP_UNARY_OP_BOOL:
return mp_obj_new_bool(self->i_get != self->i_put); return mp_obj_new_bool(self->i_get != self->i_put);
case MP_UNARY_OP_LEN: { 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) { if (len < 0) {
len += self->alloc; len += self->alloc;
} }