summaryrefslogtreecommitdiff
path: root/soltools/mkdepend
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2014-09-03 22:59:10 +0100
committerCaolán McNamara <caolanm@redhat.com>2014-09-04 07:57:33 +0100
commit3e835154a7af929fd18683af85c28efabd498d41 (patch)
tree350ddb41683a7032c394f8e8f988321440c797d0 /soltools/mkdepend
parenteef839fe482c8c3ba2152b3e1edd43fb21c2de02 (diff)
coverity#1019334 Explicit null dereferenced
Change-Id: I22b85cbfda1c1bd705b35095e03cfae4071d2fb7
Diffstat (limited to 'soltools/mkdepend')
-rw-r--r--soltools/mkdepend/main.c79
1 files changed, 5 insertions, 74 deletions
diff --git a/soltools/mkdepend/main.c b/soltools/mkdepend/main.c
index b8dde42ef9a0..6cbcf128f55b 100644
--- a/soltools/mkdepend/main.c
+++ b/soltools/mkdepend/main.c
@@ -115,7 +115,7 @@ char *directives[] = {
/******* function declarations ********/
/******* added by -Wall project *******/
-void redirect(char * line, char * makefile );
+void redirect(char * makefile);
struct inclist inclist[ MAXFILES ],
*inclistp = inclist;
@@ -375,7 +375,7 @@ int main(int argc, char **argv)
*incp++ = defincdir;
}
- redirect(startat, makefile);
+ redirect(makefile);
/*
* catch signals.
@@ -650,81 +650,12 @@ int rename (char *from, char *to)
}
#endif /* USGISH */
-void redirect(char *line, char *makefile)
+void redirect(char *makefile)
{
FILE *fdout;
- fdout = freopen(makefile, "wb", stdout); // binary mode please
+ fdout = makefile ? freopen(makefile, "wb", stdout) : NULL; // binary mode please
if (fdout == NULL)
- fatalerr("cannot open \"%s\"\n", makefile);
- (void) line;
-
- // don't need any of that nonsense
-#if 0
- struct stat st;
- FILE *fdin, *fdout;
- char backup[ BUFSIZ ],
- buf[ BUFSIZ ];
- boolean found = FALSE;
- int len;
-
- /*
- * if makefile is "-" then let it pour onto stdout.
- */
- if (makefile && *makefile == '-' && *(makefile+1) == '\0')
- return;
-
- /*
- * use a default makefile is not specified.
- */
- if (!makefile) {
- if (stat("Makefile", &st) == 0)
- makefile = "Makefile";
- else if (stat("makefile", &st) == 0)
- makefile = "makefile";
- else
- fatalerr("[mM]akefile is not present\n");
- }
- else
- stat(makefile, &st);
- if ((fdin = fopen(makefile, "r")) == NULL)
- fatalerr("cannot open \"%s\"\n", makefile);
- sprintf(backup, "%s.bak", makefile);
- unlink(backup);
-#if defined(WIN32)
- fclose(fdin);
-#endif
- if (rename(makefile, backup) < 0)
- fatalerr("cannot rename %s to %s\n", makefile, backup);
-#if defined(WIN32)
- if ((fdin = fopen(backup, "r")) == NULL)
- fatalerr("cannot open \"%s\"\n", backup);
-#endif
- if ((fdout = freopen(makefile, "w", stdout)) == NULL)
- fatalerr("cannot open \"%s\"\n", backup);
- len = strlen(line);
- while (!found && fgets(buf, BUFSIZ, fdin)) {
- if (*buf == '#' && strncmp(line, buf, len) == 0)
- found = TRUE;
- fputs(buf, fdout);
- }
- if (!found) {
- if (verbose)
- warning("Adding new delimiting line \"%s\" and dependencies...\n",
- line);
- puts(line); /* same as fputs(fdout); but with newline */
- } else if (append) {
- while (fgets(buf, BUFSIZ, fdin)) {
- fputs(buf, fdout);
- }
- }
- fflush(fdout);
-#if defined(USGISH) || defined(USE_CHMOD)
- chmod(makefile, st.st_mode);
-#else
- fchmod(fileno(fdout), st.st_mode);
-#endif /* USGISH */
- fclose(fdin);
-#endif
+ fatalerr("cannot open \"%s\"\n", makefile ? makefile : "<NULL>");
}
void fatalerr(char *msg, ...)