more fixes for security and warnings

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@7009 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Marcelo Matus 2005-02-26 20:25:10 +00:00
commit 5b74ab97a7
10 changed files with 44 additions and 34 deletions

View file

@ -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;

View file

@ -140,7 +140,7 @@ namespace swig
return swig::as<T>(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<T>(), item);
}
@ -335,7 +335,7 @@ namespace swig
if (!swig::check<value_type>(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<value_type>(), item);
SWIG_append_errmsg(msg);
}
@ -540,7 +540,7 @@ namespace swig
%{
namespace swig {
template <class PySeq, class Seq>
inline void
static inline void
assign(const PySeq& pyseq, Seq* seq) {
#ifdef SWIG_STD_NOASSIGN_STL
typedef typename PySeq::value_type value_type;

View file

@ -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;
}
}
}
}

View file

@ -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;
}
}

View file

@ -84,7 +84,7 @@
{
$&ltype resultptr;
resultptr = ($&ltype) malloc(sizeof($type));
memmove(resultptr, &$1, sizeof($type));
if (resultptr) memmove(resultptr, &$1, sizeof($type));
$result = SWIG_NewPointerObj((void *)(resultptr), $&descriptor, 1);
}
#endif

View file

@ -6,7 +6,7 @@
{
namespace swig {
template <class PySeq, class K, class T >
inline void
static inline void
assign(const PySeq& pyseq, std::map<K,T > *map) {
typedef typename std::map<K,T>::value_type value_type;
typename PySeq::const_iterator it = pyseq.begin();

View file

@ -7,7 +7,8 @@
{
namespace swig {
template <class PySeq, class K, class T >
void assign(const PySeq& pyseq, std::multimap<K,T > *multimap) {
static inline void
assign(const PySeq& pyseq, std::multimap<K,T > *multimap) {
typedef typename std::map<K,T>::value_type value_type;
typename PySeq::const_iterator it = pyseq.begin();
for (;it != pyseq.end(); ++it) {

View file

@ -8,7 +8,8 @@
%{
namespace swig {
template <class PySeq, class T>
void assign(const PySeq& pyseq, std::multiset<T>* seq) {
static inline void
assign(const PySeq& pyseq, std::multiset<T>* seq) {
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
typedef typename PySeq::value_type value_type;
typename PySeq::const_iterator it = pyseq.begin();

View file

@ -6,7 +6,8 @@
%{
namespace swig {
template <class PySeq, class T>
void assign(const PySeq& pyseq, std::set<T>* seq) {
static inline void
assign(const PySeq& pyseq, std::set<T>* seq) {
#ifdef SWIG_STD_NOINSERT_TEMPLATE_STL
typedef typename PySeq::value_type value_type;
typename PySeq::const_iterator it = pyseq.begin();

View file

@ -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
/*