summaryrefslogtreecommitdiffstats
path: root/Python
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-16 19:13:24 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-16 19:13:24 (GMT)
commit67559bf8f14bfdcda028fda720c62bd50d597c45 (patch)
treea7fc565bc560cbebc8f09da14bb5802bb60c57c1 /Python
parente9fc6699a5cdef659847b574e23f5eea86b6dde8 (diff)
downloadcpython-67559bf8f14bfdcda028fda720c62bd50d597c45.zip
cpython-67559bf8f14bfdcda028fda720c62bd50d597c45.tar.gz
cpython-67559bf8f14bfdcda028fda720c62bd50d597c45.tar.bz2
Issue #23450: Silenced compiler warnings and added asserts in peephole optimizer.
Diffstat (limited to 'Python')
-rw-r--r--Python/peephole.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/Python/peephole.c b/Python/peephole.c
index c56c8fc..2f8f0e5 100644
--- a/Python/peephole.c
+++ b/Python/peephole.c
@@ -18,7 +18,11 @@
|| op==JUMP_IF_FALSE_OR_POP || op==JUMP_IF_TRUE_OR_POP)
#define JUMPS_ON_TRUE(op) (op==POP_JUMP_IF_TRUE || op==JUMP_IF_TRUE_OR_POP)
#define GETJUMPTGT(arr, i) (GETARG(arr,i) + (ABSOLUTE_JUMP(arr[i]) ? 0 : i+3))
-#define SETARG(arr, i, val) arr[i+2] = val>>8; arr[i+1] = val & 255
+#define SETARG(arr, i, val) do { \
+ assert(0 <= val && val <= 0xffff); \
+ arr[i+2] = (unsigned char)(((unsigned int)val)>>8); \
+ arr[i+1] = (unsigned char)(((unsigned int)val) & 255); \
+} while(0)
#define CODESIZE(op) (HAS_ARG(op) ? 3 : 1)
#define ISBASICBLOCK(blocks, start, bytes) \
(blocks[start]==blocks[start+bytes-1])
@@ -355,7 +359,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
unsigned char *codestr = NULL;
unsigned char *lineno;
int *addrmap = NULL;
- int new_line, cum_orig_line, last_line, tabsiz;
+ int new_line, cum_orig_line, last_line;
+ Py_ssize_t tabsiz;
PyObject **const_stack = NULL;
Py_ssize_t *load_const_stack = NULL;
Py_ssize_t const_stack_top = -1;
@@ -660,7 +665,8 @@ PyCode_Optimize(PyObject *code, PyObject* consts, PyObject *names,
/* Fixup linenotab */
for (i=0, nops=0 ; i<codelen ; i += CODESIZE(codestr[i])) {
- addrmap[i] = i - nops;
+ assert(i - nops <= INT_MAX);
+ addrmap[i] = (int)(i - nops);
if (codestr[i] == NOP)
nops++;
}