Remove unnecessary null checks or fix potential null dereferences

git-svn-id: https://swig.svn.sourceforge.net/svnroot/swig/trunk@13924 626c5289-ae23-0410-ae9c-e8d60b6d4f22
This commit is contained in:
William S Fulton 2012-11-20 23:29:35 +00:00
commit 2b8bfe410e
5 changed files with 60 additions and 53 deletions

View file

@ -2096,7 +2096,7 @@ MODULA3():
stem += Len(pat.prefix); stem += Len(pat.prefix);
} }
String *newname; String *newname;
if (Strcmp(srcstyle, "underscore") == 0) { if (srcstyle && Strcmp(srcstyle, "underscore") == 0) {
if (newprefix != NIL) { if (newprefix != NIL) {
String *newstem = nameToModula3(stem, true); String *newstem = nameToModula3(stem, true);
newname = NewStringf("%s%s", newprefix, newstem); newname = NewStringf("%s%s", newprefix, newstem);
@ -2214,6 +2214,7 @@ MODULA3():
List *baselist = Getattr(n, "bases"); List *baselist = Getattr(n, "bases");
if (baselist != NIL) { if (baselist != NIL) {
Iterator base = First(baselist); Iterator base = First(baselist);
if (base.item) {
c_baseclassname = Getattr(base.item, "name"); c_baseclassname = Getattr(base.item, "name");
baseclass = Copy(getProxyName(c_baseclassname)); baseclass = Copy(getProxyName(c_baseclassname));
if (baseclass) { if (baseclass) {
@ -2226,6 +2227,7 @@ MODULA3():
name, Getattr(base.item, "name")); name, Getattr(base.item, "name"));
} }
} }
}
bool derived = baseclass && getProxyName(c_baseclassname); bool derived = baseclass && getProxyName(c_baseclassname);
if (!baseclass) if (!baseclass)
@ -2460,15 +2462,17 @@ MODULA3():
/* Look for the first (principal?) base class - /* Look for the first (principal?) base class -
Modula 3 does not support multiple inheritance */ Modula 3 does not support multiple inheritance */
Iterator base = First(baselist); Iterator base = First(baselist);
if (base.item) {
Append(baseclassname, Getattr(base.item, "sym:name")); Append(baseclassname, Getattr(base.item, "sym:name"));
base = Next(base); base = Next(base);
if (base.item != NIL) { if (base.item) {
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name")); proxy_class_name, Getattr(base.item, "name"));
} }
} }
} }
}
/* the private class of the base class and only this /* the private class of the base class and only this
need a pointer to the C++ object */ need a pointer to the C++ object */

View file

@ -1256,12 +1256,11 @@ public:
Printv(qtype, name, NIL); Printv(qtype, name, NIL);
} }
if (const_enum && name && !Getattr(seen_enumvalues, name)) { if (const_enum && qtype && name && !Getattr(seen_enumvalues, name)) {
Setattr(seen_enumvalues, name, "true"); Setattr(seen_enumvalues, name, "true");
SetFlag(n, "feature:immutable"); SetFlag(n, "feature:immutable");
Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used Setattr(n, "feature:enumvalue", "1"); // this does not appear to be used
if (qtype)
Setattr(n, "qualified:name", SwigType_namestr(qtype)); Setattr(n, "qualified:name", SwigType_namestr(qtype));
String *evname = SwigType_manglestr(qtype); String *evname = SwigType_manglestr(qtype);

View file

@ -1638,9 +1638,9 @@ public:
while (fgets(buffer, 4095, f)) { while (fgets(buffer, 4095, f)) {
Printf(pragma_include, "%s", buffer); Printf(pragma_include, "%s", buffer);
} }
}
fclose(f); fclose(f);
} }
}
} else { } else {
Swig_error(input_file, line_number, "Unrecognized pragma.\n"); Swig_error(input_file, line_number, "Unrecognized pragma.\n");
} }

View file

@ -1163,9 +1163,9 @@ public:
autodoc_l autodoc_level(String *autodoc) { autodoc_l autodoc_level(String *autodoc) {
autodoc_l dlevel = NO_AUTODOC; autodoc_l dlevel = NO_AUTODOC;
if (autodoc) {
char *c = Char(autodoc); char *c = Char(autodoc);
if (c && isdigit(c[0])) { if (c) {
if (isdigit(c[0])) {
dlevel = (autodoc_l) atoi(c); dlevel = (autodoc_l) atoi(c);
} else { } else {
if (strcmp(c, "extended") == 0) { if (strcmp(c, "extended") == 0) {

View file

@ -1609,7 +1609,6 @@ void R::dispatchFunction(Node *n) {
String *tmcheck = Swig_typemap_lookup("rtypecheck", p, "", 0); String *tmcheck = Swig_typemap_lookup("rtypecheck", p, "", 0);
if (tmcheck) { if (tmcheck) {
String *tmp = NewString(""); String *tmp = NewString("");
Printf(tmp, "argv[[%d]]", j+1); Printf(tmp, "argv[[%d]]", j+1);
Replaceall(tmcheck, "$arg", tmp); Replaceall(tmcheck, "$arg", tmp);
@ -1627,17 +1626,18 @@ void R::dispatchFunction(Node *n) {
p = Getattr(p, "tmap:in:next"); p = Getattr(p, "tmap:in:next");
continue; continue;
} }
if (DohStrcmp(tm,"numeric")==0) { if (tm) {
if (Strcmp(tm,"numeric")==0) {
Printf(f->code, "%sis.numeric(argv[[%d]])", Printf(f->code, "%sis.numeric(argv[[%d]])",
j == 0 ? "" : " && ", j == 0 ? "" : " && ",
j+1); j+1);
} }
else if (DohStrcmp(tm,"integer")==0) { else if (Strcmp(tm,"integer")==0) {
Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))", Printf(f->code, "%s(is.integer(argv[[%d]]) || is.numeric(argv[[%d]]))",
j == 0 ? "" : " && ", j == 0 ? "" : " && ",
j+1, j+1); j+1, j+1);
} }
else if (DohStrcmp(tm,"character")==0) { else if (Strcmp(tm,"character")==0) {
Printf(f->code, "%sis.character(argv[[%d]])", Printf(f->code, "%sis.character(argv[[%d]])",
j == 0 ? "" : " && ", j == 0 ? "" : " && ",
j+1); j+1);
@ -1648,6 +1648,7 @@ void R::dispatchFunction(Node *n) {
j+1, j+1,
tm); tm);
} }
}
if (!SwigType_ispointer(Getattr(p, "type"))) { if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1", Printf(f->code, " && length(argv[[%d]]) == 1",
j+1); j+1);
@ -1845,9 +1846,10 @@ int R::functionWrapper(Node *n) {
String *lname = Getattr(p,"lname"); String *lname = Getattr(p,"lname");
// R keyword renaming // R keyword renaming
if (name && Swig_name_warning(p, 0, name, 0)) if (name) {
if (Swig_name_warning(p, 0, name, 0)) {
name = 0; name = 0;
} else {
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
we need to remove that prefix. */ we need to remove that prefix. */
while (Strstr(name, "::")) { while (Strstr(name, "::")) {
@ -1856,7 +1858,9 @@ int R::functionWrapper(Node *n) {
if (debugMode) if (debugMode)
Printf(stdout, "+++ parameter name with :: in it %s\n", name); Printf(stdout, "+++ parameter name with :: in it %s\n", name);
} }
if (Len(name) == 0) }
}
if (!name || Len(name) == 0)
name = NewStringf("s_arg%d", i+1); name = NewStringf("s_arg%d", i+1);
name = replaceInitialDash(name); name = replaceInitialDash(name);