Commit 095d3970 authored by Damien George's avatar Damien George

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.
parent b208aa18
......@@ -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;
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment