diff --git a/Lib/python/pycomplex.swg b/Lib/python/pycomplex.swg index 9a58a8dbc..8b5d05906 100644 --- a/Lib/python/pycomplex.swg +++ b/Lib/python/pycomplex.swg @@ -34,7 +34,7 @@ SWIGINTERN int } else { double d; if (SWIG_AsVal(double)(o, &d)) { - if (val) *val = Constructor(d, 0); + if (val) *val = Constructor(d, 0.0); return 1; } else { PyErr_Clear(); @@ -73,7 +73,7 @@ SWIGINTERN int double re; if (SWIG_AsVal(double)(o, &re)) { if (SWIG_CheckDoubleInRange(re, -FLT_MAX, FLT_MAX, errmsg)) { - if (val) *val = Constructor(SWIG_numeric_cast(re,float), 0); + if (val) *val = Constructor(SWIG_numeric_cast(re,float), 0.0); return 1; } else { return 0; diff --git a/Lib/python/pycontainer.swg b/Lib/python/pycontainer.swg index f120f8fe7..0d5769881 100644 --- a/Lib/python/pycontainer.swg +++ b/Lib/python/pycontainer.swg @@ -140,7 +140,7 @@ namespace swig return swig::as(item, true); } catch (std::exception& e) { char msg[1024]; - sprintf(msg,"in sequence element %d ", _index); + PyOS_snprintf(msg, sizeof(msg), "in sequence element %d ", _index); if (!PyErr_Occurred()) { SWIG_type_error(swig::type_name(), item); } @@ -335,7 +335,7 @@ namespace swig if (!swig::check(item)) { if (set_err) { char msg[1024]; - sprintf(msg,"in sequence element %d", i); + PyOS_snprintf(msg, sizeof(msg), "in sequence element %d", i); SWIG_type_error(swig::type_name(), item); SWIG_append_errmsg(msg); } @@ -540,7 +540,7 @@ namespace swig %{ namespace swig { template - inline void + static inline void assign(const PySeq& pyseq, Seq* seq) { #ifdef SWIG_STD_NOASSIGN_STL typedef typename PySeq::value_type value_type; diff --git a/Lib/python/pyinit.swg b/Lib/python/pyinit.swg index c057cb5a7..4c9c0c44a 100644 --- a/Lib/python/pyinit.swg +++ b/Lib/python/pyinit.swg @@ -137,11 +137,14 @@ SWIG_Python_addvarlink(PyObject *p, char *name, PyObject *(*get_attr)(void), int swig_varlinkobject *v = (swig_varlinkobject *) p; swig_globalvar *gv = (swig_globalvar *) malloc(sizeof(swig_globalvar)); if (gv) { - gv->name = (char *) malloc(strlen(name)+1); - strcpy(gv->name,name); - gv->get_attr = get_attr; - gv->set_attr = set_attr; - gv->next = v->vars; + size_t size = strlen(name)+1; + gv->name = (char *)malloc(size); + if (gv->name) { + strncpy(gv->name,name,size); + gv->get_attr = get_attr; + gv->set_attr = set_attr; + gv->next = v->vars; + } } v->vars = gv; } @@ -155,7 +158,7 @@ SWIGINTERN void SWIG_Python_InstallConstants(PyObject *d, swig_const_info constants[]) { PyObject *obj = 0; size_t i; - for (i = 0; constants[i].type; i++) { + for (i = 0; constants[i].type; ++i) { switch(constants[i].type) { case SWIG_PY_INT: obj = PyInt_FromLong(constants[i].lvalue); @@ -204,7 +207,7 @@ SWIG_Python_FixMethods(PyMethodDef *methods, int j; swig_const_info *ci = 0; char *name = c + 10; - for (j = 0; const_table[j].type; j++) { + for (j = 0; const_table[j].type; ++j) { if (strncmp(const_table[j].name, name, strlen(const_table[j].name)) == 0) { ci = &(const_table[j]); @@ -217,14 +220,16 @@ SWIG_Python_FixMethods(PyMethodDef *methods, size_t ldoc = (c - methods[i].ml_doc); size_t lptr = strlen(ty->name)+2*sizeof(void*)+2; char *ndoc = (char*)malloc(ldoc + lptr + 10); - char *buff = ndoc; - void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue: (void *)(ci->lvalue); - strncpy(buff, methods[i].ml_doc, ldoc); - buff += ldoc; - strncpy(buff, "swig_ptr: ", 10); - buff += 10; - SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); - methods[i].ml_doc = ndoc; + if (ndoc) { + char *buff = ndoc; + void *ptr = (ci->type == SWIG_PY_POINTER) ? ci->pvalue: (void *)(ci->lvalue); + strncpy(buff, methods[i].ml_doc, ldoc); + buff += ldoc; + strncpy(buff, "swig_ptr: ", 10); + buff += 10; + SWIG_PackVoidPtr(buff, ptr, ty->name, lptr); + methods[i].ml_doc = ndoc; + } } } } diff --git a/Lib/python/pyrun.swg b/Lib/python/pyrun.swg index c7684a98d..be910835b 100644 --- a/Lib/python/pyrun.swg +++ b/Lib/python/pyrun.swg @@ -110,7 +110,7 @@ PySwigObject_oct(PySwigObject *v) char buf[100]; unsigned long x = (unsigned long)v->ptr; if (x == 0) - strcpy(buf, "0"); + strncpy(buf, "0",sizeof(buf)); else PyOS_snprintf(buf, sizeof(buf), "0%lo", x); return PyString_FromString(buf); @@ -392,11 +392,14 @@ PySwigPacked_FromDataAndDesc(void *ptr, size_t size, const char *desc) return NULL; } else { void *pack = malloc(size); - memcpy(pack, ptr, size); - self->pack = pack; - self->desc = desc; - self->size = size; - return (PyObject *) self; + if (pack) { + memcpy(pack, ptr, size); + self->pack = pack; + self->desc = desc; + self->size = size; + return (PyObject *) self; + } + return NULL; } } diff --git a/Lib/python/pyswigtype.swg b/Lib/python/pyswigtype.swg index a25c015fc..0769acb40 100644 --- a/Lib/python/pyswigtype.swg +++ b/Lib/python/pyswigtype.swg @@ -84,7 +84,7 @@ { $<ype resultptr; resultptr = ($<ype) malloc(sizeof($type)); - memmove(resultptr, &$1, sizeof($type)); + if (resultptr) memmove(resultptr, &$1, sizeof($type)); $result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1); } #endif diff --git a/Lib/python/std_map.i b/Lib/python/std_map.i index 4259b32ac..703e77373 100644 --- a/Lib/python/std_map.i +++ b/Lib/python/std_map.i @@ -6,7 +6,7 @@ { namespace swig { template - inline void + static inline void assign(const PySeq& pyseq, std::map *map) { typedef typename std::map::value_type value_type; typename PySeq::const_iterator it = pyseq.begin(); diff --git a/Lib/python/std_multimap.i b/Lib/python/std_multimap.i index 7b93f6434..2431925f8 100644 --- a/Lib/python/std_multimap.i +++ b/Lib/python/std_multimap.i @@ -7,7 +7,8 @@ { namespace swig { template - void assign(const PySeq& pyseq, std::multimap *multimap) { + static inline void + assign(const PySeq& pyseq, std::multimap *multimap) { typedef typename std::map::value_type value_type; typename PySeq::const_iterator it = pyseq.begin(); for (;it != pyseq.end(); ++it) { diff --git a/Lib/python/std_multiset.i b/Lib/python/std_multiset.i index b85f5bfb6..35e6e68a3 100644 --- a/Lib/python/std_multiset.i +++ b/Lib/python/std_multiset.i @@ -8,7 +8,8 @@ %{ namespace swig { template - void assign(const PySeq& pyseq, std::multiset* seq) { + static inline void + assign(const PySeq& pyseq, std::multiset* seq) { #ifdef SWIG_STD_NOINSERT_TEMPLATE_STL typedef typename PySeq::value_type value_type; typename PySeq::const_iterator it = pyseq.begin(); diff --git a/Lib/python/std_set.i b/Lib/python/std_set.i index 9129fe01b..20b990f1f 100644 --- a/Lib/python/std_set.i +++ b/Lib/python/std_set.i @@ -6,7 +6,8 @@ %{ namespace swig { template - void assign(const PySeq& pyseq, std::set* seq) { + static inline void + assign(const PySeq& pyseq, std::set* seq) { #ifdef SWIG_STD_NOINSERT_TEMPLATE_STL typedef typename PySeq::value_type value_type; typename PySeq::const_iterator it = pyseq.begin(); diff --git a/Lib/swigrun.swg b/Lib/swigrun.swg index 3c4e7646d..2adc925b7 100644 --- a/Lib/swigrun.swg +++ b/Lib/swigrun.swg @@ -157,9 +157,8 @@ SWIG_TypeCompare(const char *nb, const char *tb) { /* think of this as a c++ template<> or a scheme macro */ #define SWIG_TypeCheck_Template(comparison, ty) \ - do { \ + if (ty) { \ swig_cast_info *iter; \ - if (!ty) return 0; \ iter = ty->cast; \ while (iter) { \ if (comparison) { \ @@ -178,7 +177,7 @@ SWIG_TypeCompare(const char *nb, const char *tb) { } \ iter = iter->next; \ } \ - } while(0); \ + } \ return 0 /*