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,16 +2214,18 @@ 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);
c_baseclassname = Getattr(base.item, "name"); if (base.item) {
baseclass = Copy(getProxyName(c_baseclassname)); c_baseclassname = Getattr(base.item, "name");
if (baseclass) { baseclass = Copy(getProxyName(c_baseclassname));
c_baseclass = SwigType_namestr(Getattr(base.item, "name")); if (baseclass) {
} c_baseclass = SwigType_namestr(Getattr(base.item, "name"));
base = Next(base); }
if (base.item != NIL) { base = Next(base);
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), if (base.item != NIL) {
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
name, Getattr(base.item, "name")); "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
name, Getattr(base.item, "name"));
}
} }
} }
@ -2460,12 +2462,14 @@ 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);
Append(baseclassname, Getattr(base.item, "sym:name")); if (base.item) {
base = Next(base); Append(baseclassname, Getattr(base.item, "sym:name"));
if (base.item != NIL) { base = Next(base);
Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n), if (base.item) {
"Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n", Swig_warning(WARN_MODULA3_MULTIPLE_INHERITANCE, Getfile(n), Getline(n),
proxy_class_name, Getattr(base.item, "name")); "Warning for %s proxy: Base %s ignored. Multiple inheritance is not supported in Modula 3.\n",
proxy_class_name, Getattr(base.item, "name"));
}
} }
} }
} }

View file

@ -1256,13 +1256,12 @@ 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);
Insert(evname, 0, "SWIG_ENUM_"); Insert(evname, 0, "SWIG_ENUM_");

View file

@ -1638,8 +1638,8 @@ 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) {
if (c && isdigit(c[0])) { 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);
@ -1626,32 +1625,34 @@ void R::dispatchFunction(Node *n) {
tmcheck); tmcheck);
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);
} }
else { else {
Printf(f->code, "%sextends(argtypes[%d], '%s')", Printf(f->code, "%sextends(argtypes[%d], '%s')",
j == 0 ? "" : " && ", j == 0 ? "" : " && ",
j+1, j+1,
tm); tm);
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
} }
}
if (!SwigType_ispointer(Getattr(p, "type"))) {
Printf(f->code, " && length(argv[[%d]]) == 1",
j+1);
}
p = Getattr(p, "tmap:in:next"); p = Getattr(p, "tmap:in:next");
} }
Printf(f->code, ") { f <- %s%s; }\n", sfname, overname); Printf(f->code, ") { f <- %s%s; }\n", sfname, overname);
@ -1845,18 +1846,21 @@ 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) {
name = 0; if (Swig_name_warning(p, 0, name, 0)) {
name = 0;
/* If we have a :: in the parameter name because we are accessing a static member of a class, say, then } else {
we need to remove that prefix. */ /* If we have a :: in the parameter name because we are accessing a static member of a class, say, then
while (Strstr(name, "::")) { we need to remove that prefix. */
//XXX need to free. while (Strstr(name, "::")) {
name = NewStringf("%s", Strchr(name, ':') + 2); //XXX need to free.
if (debugMode) name = NewStringf("%s", Strchr(name, ':') + 2);
Printf(stdout, "+++ parameter name with :: in it %s\n", name); if (debugMode)
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);