swig/swig — pull request #70 by vigsterkr (2013-08-07 10:54:30+00:00)
Title: Fix possible integer overflow in python.cxx

When compiling SWIG generated cxx file in c++11 mode ('-std=c++11') with '-Wc++11-narrowing' flag one will get an error (see the example below) since the 'tp_dictoffset' is basically 'unsigned long' to 'long', which could lead to integer overflow. Using 'static_cast(...)' can prevent this.

error example (with clang -std=c++11):
non-constant-expression cannot be narrowed from type 'size_t'
(aka 'unsigned long') to 'Py_ssize_t' (aka 'long') in initializer list
[-Wc++11-narrowing]
(size_t)(((char*)&((SwigPyObject *) 64L)->dict) - (char*) 64L), /*...
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~