Skip to content

Commit

Permalink
prevent overwriting input file (not foolproof) and remove tabs
Browse files Browse the repository at this point in the history
  • Loading branch information
dbry committed Sep 12, 2018
1 parent f10b54a commit 37359e6
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions adpcm-xq.c
Original file line number Diff line number Diff line change
Expand Up @@ -113,14 +113,14 @@ int main (argc, argv) int argc; char **argv;
fprintf (stderr, "\nillegal option: %c !\n", **argv);
return 1;
}
else if (!infilename) {
else if (!infilename) {
infilename = malloc (strlen (*argv) + 10);
strcpy (infilename, *argv);
}
else if (!outfilename) {
}
else if (!outfilename) {
outfilename = malloc (strlen (*argv) + 10);
strcpy (outfilename, *argv);
}
}
else {
fprintf (stderr, "\nextra unknown argument: %s !\n", *argv);
return 1;
Expand All @@ -135,6 +135,11 @@ int main (argc, argv) int argc; char **argv;
return 0;
}

if (!strcmp (infilename, outfilename)) {
fprintf (stderr, "can't overwrite input file (specify different/new output file name)\n");
return -1;
}

if (!overwrite && (outfile = fopen (outfilename, "r"))) {
fclose (outfile);
fprintf (stderr, "output file \"%s\" exists (use -y to overwrite)\n", outfilename);
Expand Down

0 comments on commit 37359e6

Please sign in to comment.