diff --git a/Modules/_csv.c b/Modules/_csv.c index 5e03635..6e7d51e 100644 --- a/Modules/_csv.c +++ b/Modules/_csv.c @@ -968,7 +968,8 @@ join_append_data(WriterObj *self, char *field, int quote_empty, int *quoted, int copy_phase) { DialectObj *dialect = self->dialect; - int i, rec_len; + unsigned int i; + int rec_len; char *lineterm; #define ADDCH(c) \ diff --git a/Modules/_heapqmodule.c b/Modules/_heapqmodule.c index f970cae..9957ea6 100644 --- a/Modules/_heapqmodule.c +++ b/Modules/_heapqmodule.c @@ -124,7 +124,7 @@ static PyObject * heappop(PyObject *self, PyObject *heap) { PyObject *lastelt, *returnitem; - Py_ssize_t n; + size_t n; if (!PyList_Check(heap)) { PyErr_SetString(PyExc_TypeError, "heap argument must be a list"); diff --git a/Modules/_hotshot.c b/Modules/_hotshot.c index 21bd383..e6fc3fc 100644 --- a/Modules/_hotshot.c +++ b/Modules/_hotshot.c @@ -75,7 +75,7 @@ typedef struct { PyObject_HEAD PyObject *filemap; PyObject *logfilename; - Py_ssize_t index; + size_t index; unsigned char buffer[BUFFERSIZE]; FILE *logfp; int lineevents; diff --git a/Modules/_sre.c b/Modules/_sre.c index 3542100..6a4bd47 100644 --- a/Modules/_sre.c +++ b/Modules/_sre.c @@ -672,7 +672,7 @@ SRE_INFO(SRE_STATE* state, SRE_CODE* pattern) #define RETURN_SUCCESS do { ret = 1; goto exit; } while(0) #define RETURN_ON_ERROR(i) \ - do { if (i < 0) RETURN_ERROR(i); } while (0) + do { if (i + i < i) RETURN_ERROR(i); } while (0) #define RETURN_ON_SUCCESS(i) \ do { RETURN_ON_ERROR(i); if (i > 0) RETURN_SUCCESS; } while (0) #define RETURN_ON_FAILURE(i) \ diff --git a/Modules/audioop.c b/Modules/audioop.c index 8f5d30c..6ea71c6 100644 --- a/Modules/audioop.c +++ b/Modules/audioop.c @@ -1147,7 +1147,8 @@ audioop_ratecv(PyObject *self, PyObject *args) ceiling = (q+1) * outrate; nbytes = ceiling * bytes_per_frame; /* See whether anything overflowed; if not, get the space. */ - if (q+1 < 0 || + int p = (unsigned)q + 1; + if (p < 0 || ceiling / outrate != q+1 || nbytes / bytes_per_frame != ceiling) str = NULL; diff --git a/Modules/binascii.c b/Modules/binascii.c index 00f950d..053fdb7 100644 --- a/Modules/binascii.c +++ b/Modules/binascii.c @@ -284,7 +284,7 @@ binascii_b2a_uu(PyObject *self, PyObject *args) /* Store the length */ *ascii_data++ = ' ' + (bin_len & 077); - for( ; bin_len > 0 || leftbits != 0 ; bin_len--, bin_data++ ) { + for( ; bin_len > 0 || leftbits != 0 ; bin_len = (unsigned)bin_len - 1, bin_data++ ) { /* Shift the data (or padding) into our buffer */ if ( bin_len > 0 ) /* Data */ leftchar = (leftchar << 8) | *bin_data; @@ -327,7 +327,7 @@ binascii_find_valid(unsigned char *s, Py_ssize_t slen, int num) } s++; - slen--; + slen = (unsigned)slen - 1; } return ret; } diff --git a/Modules/cPickle.c b/Modules/cPickle.c index b552a40..9a2cb14 100644 --- a/Modules/cPickle.c +++ b/Modules/cPickle.c @@ -4252,7 +4252,7 @@ do_setitems(Unpicklerobject *self, int x) static int load_setitem(Unpicklerobject *self) { - return do_setitems(self, self->stack->length - 2); + return do_setitems(self, (unsigned)self->stack->length - 2); } static int @@ -4748,7 +4748,7 @@ noload_obj(Unpicklerobject *self) int i; if ((i = marker(self)) < 0) return -1; - return Pdata_clear(self->stack, i+1); + return Pdata_clear(self->stack, (unsigned)i+1); } @@ -4799,7 +4799,7 @@ noload_reduce(Unpicklerobject *self) { if (self->stack->length < 2) return stackUnderflow(); - Pdata_clear(self->stack, self->stack->length-2); + Pdata_clear(self->stack, (unsigned)self->stack->length-2); PDATA_APPEND(self->stack, Py_None,-1); return 0; } @@ -4808,7 +4808,7 @@ static int noload_build(Unpicklerobject *self) { if (self->stack->length < 1) return stackUnderflow(); - Pdata_clear(self->stack, self->stack->length-1); + Pdata_clear(self->stack, (unsigned)self->stack->length-1); return 0; } diff --git a/Modules/dlmodule.c b/Modules/dlmodule.c index 5622ed9..1068679 100644 --- a/Modules/dlmodule.c +++ b/Modules/dlmodule.c @@ -82,7 +82,7 @@ dl_call(dlobject *xp, PyObject *args) long alist[10]; long res; Py_ssize_t i; - Py_ssize_t n = PyTuple_Size(args); + size_t n = PyTuple_Size(args); if (n < 1) { PyErr_SetString(PyExc_TypeError, "at least a name is needed"); return NULL; diff --git a/Modules/expat/xmlparse.c b/Modules/expat/xmlparse.c index e04426d..9f9c336 100644 --- a/Modules/expat/xmlparse.c +++ b/Modules/expat/xmlparse.c @@ -5333,7 +5333,7 @@ getAttributeId(XML_Parser parser, const ENCODING *enc, for (i = 0; name[i]; i++) { /* attributes without prefix are *not* in the default namespace */ if (name[i] == XML_T(':')) { - int j; + unsigned int j; for (j = 0; j < i; j++) { if (!poolAppendChar(&dtd->pool, name[j])) return NULL; diff --git a/Modules/gcmodule.c b/Modules/gcmodule.c index 6c5011c..9c248d1 100644 --- a/Modules/gcmodule.c +++ b/Modules/gcmodule.c @@ -725,7 +725,7 @@ delete_garbage(PyGC_Head *collectable, PyGC_Head *old) /* This is the main function. Read this to understand how the * collection process works. */ static Py_ssize_t -collect(int generation) +collect(unsigned int generation) { int i; Py_ssize_t m = 0; /* # objects collected */ diff --git a/Modules/imageop.c b/Modules/imageop.c index 92f805a..7af7c2a 100644 --- a/Modules/imageop.c +++ b/Modules/imageop.c @@ -397,7 +397,7 @@ imageop_dither2grey2(PyObject *self, PyObject *args) unsigned char ovalue; PyObject *rv; int i; - int pos; + unsigned int pos; int sum = 0, nvalue; diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c index e33197e..9f179cb 100644 --- a/Modules/parsermodule.c +++ b/Modules/parsermodule.c @@ -2801,7 +2801,7 @@ validate_subscript(node *tree) if (res) res = validate_colon(CHILD(tree, offset)); if (res) { - int rem = nch - ++offset; + unsigned int rem = nch - ++offset; if (rem) { if (TYPE(CHILD(tree, offset)) == test) { res = validate_test(CHILD(tree, offset)); diff --git a/Modules/stropmodule.c b/Modules/stropmodule.c index 8b00fed..2b6f670 100644 --- a/Modules/stropmodule.c +++ b/Modules/stropmodule.c @@ -1065,7 +1065,7 @@ static char * mymemreplace(const char *str, Py_ssize_t len, /* input string */ const char *pat, Py_ssize_t pat_len, /* pattern string to find */ const char *sub, Py_ssize_t sub_len, /* substitution string */ - Py_ssize_t count, /* number of replacements */ + size_t count, /* number of replacements */ Py_ssize_t *out_len) { char *out_s; diff --git a/Objects/abstract.c b/Objects/abstract.c index fb123db..8763b40 100644 --- a/Objects/abstract.c +++ b/Objects/abstract.c @@ -2033,7 +2033,7 @@ objargs_mktuple(va_list va) #endif while (((PyObject *)va_arg(countva, PyObject *)) != NULL) - ++n; + n = (unsigned)n + 1; result = PyTuple_New(n); if (result != NULL && n > 0) { for (i = 0; i < n; ++i) { diff --git a/Objects/intobject.c b/Objects/intobject.c index 2f5c124..4b09072 100644 --- a/Objects/intobject.c +++ b/Objects/intobject.c @@ -391,7 +391,7 @@ PyObject * PyInt_FromUnicode(Py_UNICODE *s, Py_ssize_t length, int base) { PyObject *result; - char *buffer = (char *)PyMem_MALLOC(length+1); + char *buffer = (char *)PyMem_MALLOC((unsigned)length+1); if (buffer == NULL) return PyErr_NoMemory(); diff --git a/Objects/listobject.c b/Objects/listobject.c index c0d0e09..5d4249e 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -1456,7 +1456,7 @@ merge_lo(MergeState *ms, PyObject **pa, Py_ssize_t na, ++min_gallop; do { assert(na > 1 && nb > 0); - min_gallop -= min_gallop > 1; + if (min_gallop > 1) min_gallop = (unsigned)min_gallop - 1; ms->min_gallop = min_gallop; k = gallop_right(*pb, pa, na, 0, compare); acount = k; @@ -1592,7 +1592,7 @@ merge_hi(MergeState *ms, PyObject **pa, Py_ssize_t na, PyObject **pb, Py_ssize_t ++min_gallop; do { assert(na > 0 && nb > 1); - min_gallop -= min_gallop > 1; + if (min_gallop > 1) min_gallop = (unsigned)min_gallop - 1; ms->min_gallop = min_gallop; k = gallop_right(*pb, basea, na, na-1, compare); if (k < 0) diff --git a/Objects/longobject.c b/Objects/longobject.c index e51517f..b372a8e 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -701,9 +701,9 @@ _PyLong_AsScaledDouble(PyObject *vv, int *exponent) nbitsneeded = NBITS_WANTED - 1; /* Invariant: i Python digits remain unaccounted for. */ while (i > 0 && nbitsneeded > 0) { - --i; + i = (unsigned)i - 1; x = x * multiplier + (double)v->ob_digit[i]; - nbitsneeded -= SHIFT; + nbitsneeded = (unsigned)nbitsneeded - SHIFT; } /* There are i digits we didn't shift in. Pretending they're all zeroes, the true value is x * 2**(i*SHIFT). */ @@ -1698,7 +1698,7 @@ PyObject * PyLong_FromUnicode(Py_UNICODE *u, Py_ssize_t length, int base) { PyObject *result; - char *buffer = (char *)PyMem_MALLOC(length+1); + char *buffer = (char *)PyMem_MALLOC((unsigned)length+1); if (buffer == NULL) return NULL; @@ -1799,7 +1799,7 @@ x_divrem(PyLongObject *v1, PyLongObject *w1, PyLongObject **prem) k = size_v - size_w; a = _PyLong_New(k + 1); - for (j = size_v; a != NULL && k >= 0; --j, --k) { + for (j = size_v; a != NULL && k >= 0; j = (unsigned)j - 1 , k = (unsigned)k - 1) { digit vj = (j >= size_v) ? 0 : v->ob_digit[j]; twodigits q; stwodigits carry = 0; @@ -1957,7 +1957,7 @@ x_add(PyLongObject *a, PyLongObject *b) { Py_ssize_t size_a = ABS(a->ob_size), size_b = ABS(b->ob_size); PyLongObject *z; - int i; + unsigned int i; digit carry = 0; /* Ensure a is the larger of the two: */ diff --git a/Objects/stringlib/fastsearch.h b/Objects/stringlib/fastsearch.h index 8f79c36..a3ee628 100644 --- a/Objects/stringlib/fastsearch.h +++ b/Objects/stringlib/fastsearch.h @@ -23,7 +23,7 @@ fastsearch(const STRINGLIB_CHAR* s, Py_ssize_t n, int mode) { long mask; - Py_ssize_t skip, count = 0; + size_t skip, count = 0; Py_ssize_t i, j, mlast, w; w = n - m; diff --git a/Objects/stringobject.c b/Objects/stringobject.c index 6673f67..05f4763 100644 --- a/Objects/stringobject.c +++ b/Objects/stringobject.c @@ -2474,10 +2474,10 @@ return_self(PyStringObject *self) PyString_GET_SIZE(self)); } -Py_LOCAL_INLINE(Py_ssize_t) +Py_LOCAL_INLINE(size_t) countchar(const char *target, int target_len, char c, Py_ssize_t maxcount) { - Py_ssize_t count=0; + size_t count=0; const char *start=target; const char *end=target+target_len; @@ -2505,7 +2505,7 @@ findstring(const char *target, Py_ssize_t target_len, if (end > target_len) { end = target_len; } else if (end < 0) { - end += target_len; + end = (unsigned)end + (unsigned)target_len; if (end < 0) end = 0; } @@ -2669,13 +2669,14 @@ replace_delete_single_character(PyStringObject *self, start = self_s; end = self_s + self_len; - while (count-- > 0) { + while (count > 0) { next = findchar(start, end-start, from_c); if (next == NULL) break; Py_MEMCPY(result_s, start, next-start); result_s += (next-start); start = next+1; + count = (unsigned)count -1; } Py_MEMCPY(result_s, start, end-start); @@ -3326,7 +3327,7 @@ string_expandtabs(PyStringObject *self, PyObject *args) else { j++; if (*p == '\n' || *p == '\r') { - i += j; + i = (unsigned)i + (unsigned)j; old_j = j = 0; if (i < 0) { PyErr_SetString(PyExc_OverflowError, diff --git a/Objects/typeobject.c b/Objects/typeobject.c index fd33fa4..a4f5b8d 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -1145,7 +1145,8 @@ consistent method resolution\norder (MRO) for bases"); static int pmerge(PyObject *acc, PyObject* to_merge) { - Py_ssize_t i, j, to_merge_size, empty_cnt; + Py_ssize_t i, j, empty_cnt; + size_t to_merge_size; int *remain; int ok; diff --git a/Objects/unicodeobject.c b/Objects/unicodeobject.c index 7f676a9..c8831e6 100644 --- a/Objects/unicodeobject.c +++ b/Objects/unicodeobject.c @@ -4655,7 +4655,7 @@ PyUnicode_Join(PyObject *separator, PyObject *seq) if (new_res_used > res_alloc) { /* double allocated size until it's big enough */ do { - res_alloc += res_alloc; + res_alloc = 2*(unsigned)res_alloc; if (res_alloc <= 0) goto Overflow; } while (new_res_used > res_alloc); @@ -5382,7 +5382,8 @@ unicode_compare(PyUnicodeObject *str1, PyUnicodeObject *str2) if (c1 != c2) return (c1 < c2) ? -1 : 1; - len1--; len2--; + len1 = (unsigned)len1 - 1; + len2 = (unsigned)len2 - 1; } return (len1 < len2) ? -1 : (len1 != len2); @@ -5714,7 +5715,7 @@ unicode_expandtabs(PyUnicodeObject *self, PyObject *args) else { j++; if (*p == '\n' || *p == '\r') { - i += j; + i = (unsigned)i + (unsigned)j; old_j = j = 0; if (i < 0) { PyErr_SetString(PyExc_OverflowError, diff --git a/Parser/acceler.c b/Parser/acceler.c index b41b265..86a917c 100644 --- a/Parser/acceler.c +++ b/Parser/acceler.c @@ -79,7 +79,7 @@ fixstate(grammar *g, state *s) for (k = s->s_narcs; --k >= 0; a++) { int lbl = a->a_lbl; label *l = &g->g_ll.ll_label[lbl]; - int type = l->lb_type; + unsigned int type = l->lb_type; if (a->a_arrow >= (1 << 7)) { printf("XXX too many states!\n"); continue; diff --git a/Parser/firstsets.c b/Parser/firstsets.c index 00467b3..29818f3 100644 --- a/Parser/firstsets.c +++ b/Parser/firstsets.c @@ -28,7 +28,8 @@ addfirstsets(grammar *g) static void calcfirstset(grammar *g, dfa *d) { - int i, j; + int i; + unsigned int j; state *s; arc *a; int nsyms; diff --git a/Parser/node.c b/Parser/node.c index d133a0d..45133d2 100644 --- a/Parser/node.c +++ b/Parser/node.c @@ -78,7 +78,7 @@ fancy_roundup(int n) int PyNode_AddChild(register node *n1, int type, char *str, int lineno, int col_offset) { - const int nch = n1->n_nchildren; + const unsigned int nch = n1->n_nchildren; int current_capacity; int required_capacity; node *n; diff --git a/Parser/pgen.c b/Parser/pgen.c index dfe7cac..05a4614 100644 --- a/Parser/pgen.c +++ b/Parser/pgen.c @@ -265,7 +265,8 @@ compile_item(labellist *ll, nfa *nf, node *n, int *pa, int *pb) } else { compile_atom(ll, nf, n, pa, pb); - if (--i <= 0) + i = (unsigned)i - 1; + if (i <= 0) return; n++; addnfaarc(nf, *pb, *pa, EMPTY); @@ -389,7 +390,8 @@ makedfa(nfagrammar *gr, nfa *nf, dfa *d) int xx_nstates; ss_state *xx_state, *yy; ss_arc *zz; - int istate, jstate, iarc, jarc, ibit; + int istate, iarc, jarc, ibit; + unsigned int jstate; nfastate *st; nfaarc *ar; @@ -549,7 +551,7 @@ samestate(ss_state *s1, ss_state *s2) static void renamestates(int xx_nstates, ss_state *xx_state, int from, int to) { - int i, j; + unsigned int i, j; if (Py_DebugFlag) printf("Rename state %d to %d.\n", from, to); @@ -597,7 +599,7 @@ simplify(int xx_nstates, ss_state *xx_state) static void convert(dfa *d, int xx_nstates, ss_state *xx_state) { - int i, j; + unsigned int i, j; ss_state *yy; ss_arc *zz; diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c index f2c80eb..7073d7b 100644 --- a/Parser/tokenizer.c +++ b/Parser/tokenizer.c @@ -172,7 +172,7 @@ error_ret(struct tok_state *tok) /* XXX */ static char * new_string(const char *s, Py_ssize_t len) { - char* result = (char *)PyMem_MALLOC(len + 1); + char* result = (char *)PyMem_MALLOC((unsigned)len + 1); if (result != NULL) { memcpy(result, s, len); result[len] = '\0'; @@ -585,7 +585,7 @@ decode_str(const char *str, struct tok_state *tok) { PyObject* utf8 = NULL; const char *s; - int lineno = 0; + unsigned int lineno = 0; tok->enc = NULL; tok->str = str; if (!check_bom(buf_getc, buf_ungetc, buf_setreadl, tok)) @@ -1409,7 +1409,7 @@ tok_get(register struct tok_state *tok, char **p_start, char **p_end) Py_ssize_t quote2 = tok->cur - tok->start + 1; int quote = c; int triple = 0; - int tripcount = 0; + unsigned int tripcount = 0; for (;;) { c = tok_nextc(tok); if (c == '\n') { diff --git a/Parser/tokenizer.h b/Parser/tokenizer.h index 8482cdd..8056eef 100644 --- a/Parser/tokenizer.h +++ b/Parser/tokenizer.h @@ -25,7 +25,7 @@ struct tok_state { /* NB If done != E_OK, cur must be == inp!!! */ FILE *fp; /* Rest of input; NULL if tokenizing a string */ int tabsize; /* Tab spacing */ - int indent; /* Current indentation index */ + unsigned int indent; /* Current indentation index */ int indstack[MAXINDENT]; /* Stack of indents */ int atbol; /* Nonzero if at begin of new line */ int pendin; /* Pending indents (if > 0) or dedents (if < 0) */ diff --git a/Python/ast.c b/Python/ast.c index 2c03ad6..f5e93ba 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -957,7 +957,7 @@ count_list_fors(const node *n) static int count_list_ifs(const node *n) { - int n_ifs = 0; + unsigned int n_ifs = 0; count_list_iter: REQ(n, list_iter); @@ -983,7 +983,8 @@ ast_for_listcomp(struct compiling *c, const node *n) */ expr_ty elt; asdl_seq *listcomps; - int i, n_fors; + unsigned int i; + int n_fors; node *ch; REQ(n, listmaker); @@ -1115,7 +1116,7 @@ count_gen_fors(const node *n) static int count_gen_ifs(const node *n) { - int n_ifs = 0; + unsigned int n_ifs = 0; while (1) { REQ(n, gen_iter); @@ -1138,7 +1139,8 @@ ast_for_genexp(struct compiling *c, const node *n) argument: [test '='] test [gen_for] # Really [keyword '='] test */ expr_ty elt; asdl_seq *genexps; - int i, n_fors; + unsigned int i; + int n_fors; node *ch; assert(TYPE(n) == (testlist_gexp) || TYPE(n) == (argument)); diff --git a/Python/bltinmodule.c b/Python/bltinmodule.c index ceb2fc7..1ec3557 100644 --- a/Python/bltinmodule.c +++ b/Python/bltinmodule.c @@ -831,7 +831,7 @@ builtin_map(PyObject *self, PyObject *args) PyObject *func, *result; sequence *seqs = NULL, *sqp; - Py_ssize_t n, len; + size_t n, len; register int i, j; n = PyTuple_Size(args); diff --git a/Python/getargs.c b/Python/getargs.c index d94edce..47612cd 100644 --- a/Python/getargs.c +++ b/Python/getargs.c @@ -339,7 +339,7 @@ seterror(int iarg, const char *msg, int *levels, const char *fname, const char *message) { char buf[512]; - int i; + unsigned int i; char *p = buf; if (PyErr_Occurred()) @@ -991,7 +991,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, arg, msgbuf, bufsize); } if (*buffer == NULL) { - *buffer = PyMem_NEW(char, size + 1); + *buffer = PyMem_NEW(char, (unsigned)size + 1); if (*buffer == NULL) { Py_DECREF(s); return converterr( @@ -1037,7 +1037,7 @@ convertsimple(PyObject *arg, const char **p_format, va_list *p_va, int flags, "(encoded string without NULL bytes)", arg, msgbuf, bufsize); } - *buffer = PyMem_NEW(char, size + 1); + *buffer = PyMem_NEW(char, (unsigned)size + 1); if (*buffer == NULL) { Py_DECREF(s); return converterr("(memory error)", diff --git a/Python/import.c b/Python/import.c index 4311352..43bd21a 100644 --- a/Python/import.c +++ b/Python/import.c @@ -3121,7 +3121,8 @@ PyImport_ExtendInittab(struct _inittab *newtab) { static struct _inittab *our_copy = NULL; struct _inittab *p; - int i, n; + int i; + unsigned int n; /* Count the number of entries in both tables */ for (n = 0; newtab[n].name != NULL; n++) diff --git a/Python/modsupport.c b/Python/modsupport.c index 1aa3df2..b069cf4 100644 --- a/Python/modsupport.c +++ b/Python/modsupport.c @@ -105,11 +105,11 @@ Py_InitModule4(const char *name, PyMethodDef *methods, const char *doc, /* Helper for mkvalue() to scan the length of a format */ -static int +static unsigned int countformat(const char *format, int endchar) { - int count = 0; - int level = 0; + unsigned int count = 0; + unsigned int level = 0; while (level > 0 || *format != endchar) { switch (*format) { case '\0': diff --git a/Python/sysmodule.c b/Python/sysmodule.c index 4598a3c..3ae7903 100644 --- a/Python/sysmodule.c +++ b/Python/sysmodule.c @@ -649,7 +649,7 @@ sys_getframe(PyObject *self, PyObject *args) while (depth > 0 && f != NULL) { f = f->f_back; - --depth; + depth = (unsigned)depth - 1; } if (f == NULL) { PyErr_SetString(PyExc_ValueError,