Remove redundant NULL checks before free()/delete (#2184)
Remove redundant NULL checks before free()/delete The ISO C and C++ standards guarantee that it's safe to call these on a NULL pointer, so it's not necessary for the calling code to also check. Fixes https://sourceforge.net/p/swig/feature-requests/70/
This commit is contained in:
parent
5a10e10399
commit
7ec2f89fe2
17 changed files with 44 additions and 51 deletions
|
|
@ -78,7 +78,7 @@ extern int count(char *bytes, int len, char c);
|
|||
|
||||
%typemap(argout) (char *str, int len) {
|
||||
SWIG_APPEND_VALUE(scm_from_locale_stringn($1,$2));
|
||||
if ($1) SWIG_free($1);
|
||||
SWIG_free($1);
|
||||
}
|
||||
|
||||
extern void capitalize(char *str, int len);
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ namespace test {
|
|||
strcpy(data,s);
|
||||
}
|
||||
~string_class() {
|
||||
if (data) delete [] data;
|
||||
delete [] data;
|
||||
}
|
||||
char *c_str() {
|
||||
return data;
|
||||
|
|
|
|||
|
|
@ -409,7 +409,7 @@ static void _ptrset(SV *_PTRVALUE, SV *value, int index, char *type) {
|
|||
} else if (strcmp(type,"char *") == 0) {
|
||||
char *c = SvPV(value,PL_na);
|
||||
char **ca = (char **) ptr;
|
||||
if (ca[index]) free(ca[index]);
|
||||
free(ca[index]);
|
||||
if (strcmp(c,"NULL") == 0) {
|
||||
ca[index] = 0;
|
||||
} else {
|
||||
|
|
@ -500,8 +500,7 @@ void _ptrfree(SV *_PTRVALUE) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (ptr)
|
||||
free((char *) ptr);
|
||||
free((char *) ptr);
|
||||
}
|
||||
|
||||
</swigxml:code>
|
||||
|
|
|
|||
|
|
@ -441,7 +441,7 @@ static void _ptrset(SV *_PTRVALUE, SV *value, int index, char *type) {
|
|||
} else if (strcmp(type,"char *") == 0) {
|
||||
char *c = SvPV(value,PL_na);
|
||||
char **ca = (char **) ptr;
|
||||
if (ca[index]) free(ca[index]);
|
||||
free(ca[index]);
|
||||
if (strcmp(c,"NULL") == 0) {
|
||||
ca[index] = 0;
|
||||
} else {
|
||||
|
|
@ -532,8 +532,7 @@ void _ptrfree(SV *_PTRVALUE) {
|
|||
}
|
||||
}
|
||||
}
|
||||
if (ptr)
|
||||
free((char *) ptr);
|
||||
free((char *) ptr);
|
||||
}
|
||||
|
||||
</swigxml:code>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue