Add NULL pointer checks for char *

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk/SWIG@4164 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
Dave Beazley 2002-12-09 17:13:52 +00:00
commit 07976f410e

View file

@ -100,40 +100,72 @@ namespace std {
#ifdef __cplusplus #ifdef __cplusplus
%typemap(memberin) char * { %typemap(memberin) char * {
if ($1) delete [] $1; if ($1) delete [] $1;
if ($input) {
$1 = ($1_type) (new char[strlen($input)+1]); $1 = ($1_type) (new char[strlen($input)+1]);
strcpy((char *) $1,$input); strcpy((char *) $1,$input);
} else {
$1 = 0;
}
} }
%typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * { %typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * {
if ($input) {
$1 = ($1_type) (new char[strlen($input)+1]); $1 = ($1_type) (new char[strlen($input)+1]);
strcpy((char *) $1,$input); strcpy((char *) $1,$input);
} else {
$1 = 0;
}
} }
%typemap(globalin) char * { %typemap(globalin) char * {
if ($1) delete [] $1; if ($1) delete [] $1;
if ($input) {
$1 = ($1_type) (new char[strlen($input)+1]); $1 = ($1_type) (new char[strlen($input)+1]);
strcpy((char *) $1,$input); strcpy((char *) $1,$input);
} else {
$1 = 0;
}
} }
%typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * { %typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * {
if ($input) {
$1 = ($1_type) (new char[strlen($input)+1]); $1 = ($1_type) (new char[strlen($input)+1]);
strcpy((char *) $1,$input); strcpy((char *) $1,$input);
} else {
$1 = 0;
}
} }
#else #else
%typemap(memberin) char * { %typemap(memberin) char * {
if ($1) free((char*)$1); if ($1) free((char*)$1);
if ($input) {
$1 = ($1_type) malloc(strlen($input)+1); $1 = ($1_type) malloc(strlen($input)+1);
strcpy((char*)$1,$input); strcpy((char*)$1,$input);
} else {
$1 = 0;
}
} }
%typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * { %typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * {
if ($input) {
$1 = ($1_type) malloc(strlen($input)+1); $1 = ($1_type) malloc(strlen($input)+1);
strcpy((char*)$1,$input); strcpy((char*)$1,$input);
} else {
$1 = 0;
}
} }
%typemap(globalin) char * { %typemap(globalin) char * {
if ($1) free((char*)$1); if ($1) free((char*)$1);
if ($input) {
$1 = ($1_type) malloc(strlen($input)+1); $1 = ($1_type) malloc(strlen($input)+1);
strcpy((char*)$1,$input); strcpy((char*)$1,$input);
} else {
$1 = 0;
}
} }
%typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * { %typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * {
if ($input) {
$1 = ($1_type) malloc(strlen($input)+1); $1 = ($1_type) malloc(strlen($input)+1);
strcpy((char*)$1,$input); strcpy((char*)$1,$input);
} else {
$1 = 0;
}
} }
#endif #endif