提交 af9d06e0 编写于 作者: J John Bowler

timepng: better errors, fix signed overflow

Too many input files would overflow nfiles
Signed-off-by: NJohn Bowler <jbowler@acm.org>
上级 703944c3
...@@ -20,6 +20,7 @@ ...@@ -20,6 +20,7 @@
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
#include <errno.h> #include <errno.h>
#include <limits.h>
#include <time.h> #include <time.h>
...@@ -279,6 +280,9 @@ static int add_one_file(FILE *fp, char *name) ...@@ -279,6 +280,9 @@ static int add_one_file(FILE *fp, char *name)
ok = 1; /* read ok */ ok = 1; /* read ok */
} }
else
fprintf(stderr, "%s: file not added\n", name);
(void)fclose(ip); (void)fclose(ip);
/* An error in the output is fatal; exit immediately: */ /* An error in the output is fatal; exit immediately: */
...@@ -463,7 +467,13 @@ int main(int argc, char **argv) ...@@ -463,7 +467,13 @@ int main(int argc, char **argv)
for (i=1; i<argc; ++i) for (i=1; i<argc; ++i)
{ {
if (add_one_file(fp, argv[i])) if (nfiles == INT_MAX)
{
fprintf(stderr, "%s: skipped, too many files\n", argv[i]);
break;
}
else if (add_one_file(fp, argv[i]))
++nfiles; ++nfiles;
} }
} }
...@@ -479,7 +489,13 @@ int main(int argc, char **argv) ...@@ -479,7 +489,13 @@ int main(int argc, char **argv)
if (filename[len-1] == '\n') if (filename[len-1] == '\n')
{ {
filename[len-1] = 0; filename[len-1] = 0;
if (add_one_file(fp, filename)) if (nfiles == INT_MAX)
{
fprintf(stderr, "%s: skipped, too many files\n", filename);
break;
}
else if (add_one_file(fp, filename))
++nfiles; ++nfiles;
} }
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册