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:
parent
b387e664a3
commit
07976f410e
1 changed files with 48 additions and 16 deletions
64
Lib/swig.swg
64
Lib/swig.swg
|
|
@ -100,40 +100,72 @@ namespace std {
|
|||
#ifdef __cplusplus
|
||||
%typemap(memberin) char * {
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(globalin) char * {
|
||||
if ($1) delete [] $1;
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) (new char[strlen($input)+1]);
|
||||
strcpy((char *) $1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
#else
|
||||
%typemap(memberin) char * {
|
||||
if ($1) free((char*)$1);
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(memberin,warning="451:Setting const char * member may leak memory.") const char * {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(globalin) char * {
|
||||
if ($1) free((char*)$1);
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
%typemap(globalin,warning="451:Setting const char * variable may leak memory.") const char * {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
if ($input) {
|
||||
$1 = ($1_type) malloc(strlen($input)+1);
|
||||
strcpy((char*)$1,$input);
|
||||
} else {
|
||||
$1 = 0;
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue