Skip to content

Commit

Permalink
code style: fix inconsistent NULL pointer comparisons
Browse files Browse the repository at this point in the history
git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@12137 626c5289-ae23-0410-ae9c-e8d60b6d4f22
  • Loading branch information
wsfulton committed Jun 17, 2010
1 parent 07ca3eb commit 95a3eb5
Show file tree
Hide file tree
Showing 12 changed files with 216 additions and 219 deletions.
365 changes: 181 additions & 184 deletions Source/Modules/go.cxx

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions Source/Modules/guile.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,7 @@ static String *memberfunction_name = 0;

extern "C" {
static int has_classname(Node *class_node) {
return Getattr(class_node, "guile:goopsclassname") != NULL;
return Getattr(class_node, "guile:goopsclassname") ? 1 : 0;
}
}

Expand Down Expand Up @@ -254,7 +254,7 @@ class GUILE:public Language {
}

// set default value for primsuffix
if (primsuffix == NULL)
if (!primsuffix)
primsuffix = NewString("primitive");

//goops support can only be enabled if passive or module linkage is used
Expand Down Expand Up @@ -628,7 +628,7 @@ class GUILE:public Language {
if (maybe_delimiter && Len(output) > 0 && Len(tm) > 0) {
Printv(output, maybe_delimiter, NIL);
}
const String *pn = (name == NULL) ? (const String *) Getattr(p, "name") : name;
const String *pn = !name ? (const String *) Getattr(p, "name") : name;
String *pt = Getattr(p, "type");
Replaceall(tm, "$name", pn); // legacy for $parmname
Replaceall(tm, "$type", SwigType_str(pt, 0));
Expand Down Expand Up @@ -781,7 +781,7 @@ class GUILE:public Language {
if (strcmp("void", Char(pt)) != 0) {
Node *class_node = Swig_symbol_clookup_check(pb, Getattr(n, "sym:symtab"),
has_classname);
String *goopsclassname = (class_node == NULL) ? NULL : Getattr(class_node, "guile:goopsclassname");
String *goopsclassname = !class_node ? NULL : Getattr(class_node, "guile:goopsclassname");
/* do input conversion */
if (goopsclassname) {
Printv(method_signature, " (", argname, " ", goopsclassname, ")", NIL);
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/lang.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2996,7 +2996,7 @@ void Language::dumpSymbols() {

Node *Language::symbolLookup(String *s, const_String_or_char_ptr scope) {
Hash *symbols = Getattr(symtabs, scope ? scope : "");
if (symbols == NULL) {
if (!symbols) {
return NULL;
}
return Getattr(symbols, s);
Expand Down
6 changes: 3 additions & 3 deletions Source/Modules/modula3.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1324,7 +1324,7 @@ MODULA3():
Parm *p;
attachParameterNames(n, "tmap:name", "c:wrapname", "m3arg%d");
bool gencomma = false;
for (p = skipIgnored(l, "in"); p != NULL; p = skipIgnored(p, "in")) {
for (p = skipIgnored(l, "in"); p; p = skipIgnored(p, "in")) {

String *arg = Getattr(p, "c:wrapname");
{
Expand Down Expand Up @@ -1545,7 +1545,7 @@ MODULA3():
Parm *p;
writeArgState state;
attachParameterNames(n, "tmap:rawinname", "modula3:rawname", "arg%d");
for (p = skipIgnored(l, "m3rawintype"); p != NULL; p = skipIgnored(p, "m3rawintype")) {
for (p = skipIgnored(l, "m3rawintype"); p; p = skipIgnored(p, "m3rawintype")) {

/* Get argument passing mode, should be one of VALUE, VAR, READONLY */
String *mode = Getattr(p, "tmap:m3rawinmode");
Expand Down Expand Up @@ -1928,7 +1928,7 @@ MODULA3():
} else if (Strcmp(code, "unsafe") == 0) {
unsafe_module = true;
} else if (Strcmp(code, "library") == 0) {
if (targetlibrary != NULL) {
if (targetlibrary) {
Delete(targetlibrary);
}
targetlibrary = Copy(strvalue);
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/ocaml.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ class OCAML:public Language {
tm = Getattr(n, "feature:director:except");
}
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Printf(w->code, "if (result == NULL) {\n");
Printf(w->code, "if (!result) {\n");
Printf(w->code, " CAML_VALUE error = *caml_named_value(\"director_except\");\n");
Replaceall(tm, "$error", "error");
Printv(w->code, Str(tm), "\n", NIL);
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/octave.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1244,7 +1244,7 @@ class OCTAVE:public Language {
idx = 0;
p = l;
int use_parse = 0;
while (p != NULL) {
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/perl5.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ class PERL5:public Language {
if (no_pmfile) {
f_pm = NewString(0);
} else {
if (pmfile == NULL) {
if (!pmfile) {
char *m = Char(module) + Len(module);
while (m != Char(module)) {
if (*m == ':') {
Expand Down
6 changes: 3 additions & 3 deletions Source/Modules/php.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1206,7 +1206,7 @@ class PHP : public Language {
}
if (!pname_cstr) {
// Unnamed parameter, e.g. int foo(int);
} else if (pname == NULL) {
} else if (!pname) {
pname = NewString(pname_cstr);
} else {
size_t len = strlen(pname_cstr);
Expand Down Expand Up @@ -1290,7 +1290,7 @@ class PHP : public Language {
if (errno || *p) {
Clear(value);
Append(value, "?");
} else if (strchr(Char(value), '.') == NULL) {
} else if (strchr(Char(value), '.') == 0) {
// Ensure value is a double constant, not an integer one.
Append(value, ".0");
double val2 = strtod(Char(value), &p);
Expand Down Expand Up @@ -2496,7 +2496,7 @@ class PHP : public Language {
idx = 0;
p = l;
int use_parse = 0;
while (p != NULL) {
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
Expand Down
26 changes: 13 additions & 13 deletions Source/Modules/python.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -1073,7 +1073,7 @@ class PYTHON:public Language {

bool have_docstring(Node *n) {
String *str = Getattr(n, "feature:docstring");
return (str != NULL && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
return (str && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
}

/* ------------------------------------------------------------
Expand All @@ -1085,7 +1085,7 @@ class PYTHON:public Language {

String *docstring(Node *n, autodoc_t ad_type, const String *indent, bool use_triple = true) {
String *str = Getattr(n, "feature:docstring");
bool have_ds = (str != NULL && Len(str) > 0);
bool have_ds = (str && Len(str) > 0);
bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
const char *triple_double = use_triple ? "\"\"\"" : "";
String *autodoc = NULL;
Expand All @@ -1101,7 +1101,7 @@ class PYTHON:public Language {

if (have_auto) {
autodoc = make_autodoc(n, ad_type);
have_auto = (autodoc != NULL && Len(autodoc) > 0);
have_auto = (autodoc && Len(autodoc) > 0);
}
// If there is more than one line then make docstrings like this:
//
Expand All @@ -1116,14 +1116,14 @@ class PYTHON:public Language {
doc = NewString("");
Printv(doc, triple_double, "\n", pythoncode(autodoc, indent), "\n", pythoncode(str, indent), indent, triple_double, NIL);
} else if (!have_auto && have_ds) { // only docstring
if (Strchr(str, '\n') == NULL) {
if (Strchr(str, '\n') == 0) {
doc = NewStringf("%s%s%s", triple_double, str, triple_double);
} else {
doc = NewString("");
Printv(doc, triple_double, "\n", pythoncode(str, indent), indent, triple_double, NIL);
}
} else if (have_auto && !have_ds) { // only autodoc
if (Strchr(autodoc, '\n') == NULL) {
if (Strchr(autodoc, '\n') == 0) {
doc = NewStringf("%s%s%s", triple_double, autodoc, triple_double);
} else {
doc = NewString("");
Expand Down Expand Up @@ -1361,7 +1361,7 @@ class PYTHON:public Language {
{
// Only do the autodoc if there isn't a docstring for the class
String *str = Getattr(n, "feature:docstring");
if (str == NULL || Len(str) == 0) {
if (!str || Len(str) == 0) {
if (CPlusPlus) {
Printf(doc, "Proxy of C++ %s class", real_classname);
} else {
Expand Down Expand Up @@ -1557,7 +1557,7 @@ class PYTHON:public Language {

bool have_pythonprepend(Node *n) {
String *str = Getattr(n, "feature:pythonprepend");
return (str != NULL && Len(str) > 0);
return (str && Len(str) > 0);
}

/* ------------------------------------------------------------
Expand All @@ -1584,7 +1584,7 @@ class PYTHON:public Language {
String *str = Getattr(n, "feature:pythonappend");
if (!str)
str = Getattr(n, "feature:addtofunc");
return (str != NULL && Len(str) > 0);
return (str && Len(str) > 0);
}

/* ------------------------------------------------------------
Expand Down Expand Up @@ -2741,7 +2741,7 @@ class PYTHON:public Language {
Printf(f_directors_h, " if (!method) {\n");
Printf(f_directors_h, " swig::SwigVar_PyObject name = SWIG_Python_str_FromChar(method_name);\n");
Printf(f_directors_h, " method = PyObject_GetAttr(swig_get_self(), name);\n");
Printf(f_directors_h, " if (method == NULL) {\n");
Printf(f_directors_h, " if (!method) {\n");
Printf(f_directors_h, " std::string msg = \"Method in class %s doesn't exist, undefined \";\n", classname);
Printf(f_directors_h, " msg += method_name;\n");
Printf(f_directors_h, " Swig::DirectorMethodException::raise(msg.c_str());\n");
Expand Down Expand Up @@ -2904,7 +2904,7 @@ class PYTHON:public Language {
Printf(f_shadow, ":\n");
if (have_docstring(n)) {
String *str = docstring(n, AUTODOC_CLASS, tab4);
if (str != NULL && Len(str))
if (str && Len(str))
Printv(f_shadow, tab4, str, "\n", NIL);
}
if (!modern) {
Expand Down Expand Up @@ -3723,7 +3723,7 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
idx = 0;
p = l;
int use_parse = 0;
while (p != NULL) {
while (p) {
if (checkAttribute(p, "tmap:in:numinputs", "0")) {
p = Getattr(p, "tmap:in:next");
continue;
Expand Down Expand Up @@ -3910,13 +3910,13 @@ int PYTHON::classDirectorMethod(Node *n, Node *parent, String *super) {
if (tm)
tm = Copy(tm);
}
Append(w->code, "if (result == NULL) {\n");
Append(w->code, "if (!result) {\n");
Append(w->code, " PyObject *error = PyErr_Occurred();\n");
if ((tm) && Len(tm) && (Strcmp(tm, "1") != 0)) {
Replaceall(tm, "$error", "error");
Printv(w->code, Str(tm), "\n", NIL);
} else {
Append(w->code, " if (error != NULL) {\n");
Append(w->code, " if (error) {\n");
Printf(w->code, " Swig::DirectorMethodException::raise(\"Error detected when calling '%s.%s'\");\n", classname, pyname);
Append(w->code, " }\n");
}
Expand Down
2 changes: 1 addition & 1 deletion Source/Modules/r.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -2514,7 +2514,7 @@ int R::membervariableHandler(Node *n) {

int status(Language::membervariableHandler(n));

if(opaqueClassDeclaration == NULL && debugMode)
if(!opaqueClassDeclaration && debugMode)
Printf(stderr, "<membervariableHandler> %s %s\n", Getattr(n, "name"), Getattr(n, "type"));

processing_member_access_function = 0;
Expand Down
12 changes: 6 additions & 6 deletions Source/Modules/ruby.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ class RUBY:public Language {

bool have_docstring(Node *n) {
String *str = Getattr(n, "feature:docstring");
return (str != NULL && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
return (str && Len(str) > 0) || (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
}

/* ------------------------------------------------------------
Expand All @@ -244,7 +244,7 @@ class RUBY:public Language {
String *docstring(Node *n, autodoc_t ad_type) {

String *str = Getattr(n, "feature:docstring");
bool have_ds = (str != NULL && Len(str) > 0);
bool have_ds = (str && Len(str) > 0);
bool have_auto = (Getattr(n, "feature:autodoc") && !GetFlag(n, "feature:noautodoc"));
String *autodoc = NULL;
String *doc = NULL;
Expand All @@ -259,7 +259,7 @@ class RUBY:public Language {

if (have_auto) {
autodoc = make_autodoc(n, ad_type);
have_auto = (autodoc != NULL && Len(autodoc) > 0);
have_auto = (autodoc && Len(autodoc) > 0);
}
// If there is more than one line then make docstrings like this:
//
Expand All @@ -272,14 +272,14 @@ class RUBY:public Language {
doc = NewString("");
Printv(doc, "\n", autodoc, "\n", str, NIL);
} else if (!have_auto && have_ds) { // only docstring
if (Strchr(str, '\n') == NULL) {
if (Strchr(str, '\n') == 0) {
doc = NewString(str);
} else {
doc = NewString("");
Printv(doc, str, NIL);
}
} else if (have_auto && !have_ds) { // only autodoc
if (Strchr(autodoc, '\n') == NULL) {
if (Strchr(autodoc, '\n') == 0) {
doc = NewStringf("%s", autodoc);
} else {
doc = NewString("");
Expand Down Expand Up @@ -618,7 +618,7 @@ class RUBY:public Language {
{
// Only do the autodoc if there isn't a docstring for the class
String *str = Getattr(n, "feature:docstring");
if (counter == 0 && (str == NULL || Len(str) == 0)) {
if (counter == 0 && (str == 0 || Len(str) == 0)) {
if (CPlusPlus) {
Printf(doc, " Proxy of C++ %s class", full_name);
} else {
Expand Down
2 changes: 1 addition & 1 deletion Source/Swig/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1092,7 +1092,7 @@ String *Swig_string_strip(String *s) {
} else {
const char *cs = Char(s);
const char *ce = Strchr(cs, ']');
if (*cs != '[' || ce == NULL) {
if (*cs != '[' || !ce) {
ns = NewString(s);
} else {
String *fmt = NewStringf("%%.%ds", ce-cs-1);
Expand Down

0 comments on commit 95a3eb5

Please sign in to comment.