summaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2013-05-07 14:31:35 -0500
committerGlenn Randers-Pehrson <glennrp at users.sourceforge.net>2013-05-07 14:31:35 -0500
commitdb67cba8d42f5f13a96ce6080a61567f66afd915 (patch)
tree9dcb3d7f5ffd84924d22f9789c870398935f73fa /contrib
parent2aa6c96e5dd6d46d9ad34380319bda0340bf3208 (diff)
downloadlibpng-db67cba8d42f5f13a96ce6080a61567f66afd915.tar.gz
[libpng16] Check for EOF in contrib/pngminus/pnm2png.c (Paul Stewart).
Ignore "#" delimited comments in input file to pnm2png.c.
Diffstat (limited to 'contrib')
-rw-r--r--contrib/pngminus/pnm2png.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/contrib/pngminus/pnm2png.c b/contrib/pngminus/pnm2png.c
index d098e33cb..953011223 100644
--- a/contrib/pngminus/pnm2png.c
+++ b/contrib/pngminus/pnm2png.c
@@ -460,19 +460,32 @@ BOOL pnm2png (FILE *pnm_file, FILE *png_file, FILE *alpha_file, BOOL interlace,
void get_token(FILE *pnm_file, char *token)
{
int i = 0;
+ int ret;
- /* remove white-space */
+ /* remove white-space and comment lines */
do
{
- token[i] = (unsigned char) fgetc (pnm_file);
+ ret = fgetc(pnm_file);
+ if (ret == '#') {
+ /* the rest of this line is a comment */
+ do
+ {
+ ret = fgetc(pnm_file);
+ }
+ while ((ret != '\n') && (ret != '\r') && (ret != EOF));
+ }
+ if (ret == EOF) break;
+ token[i] = (unsigned char) ret;
}
while ((token[i] == '\n') || (token[i] == '\r') || (token[i] == ' '));
/* read string */
do
{
+ ret = fgetc(pnm_file);
+ if (ret == EOF) break;
i++;
- token[i] = (unsigned char) fgetc (pnm_file);
+ token[i] = (unsigned char) ret;
}
while ((token[i] != '\n') && (token[i] != '\r') && (token[i] != ' '));