timepng: C++ fixes, correct add_one_file
timepng would could a file as added even if it failed and the assembly file got rewound. Signed-off-by: John Bowler <jbowler@acm.org>
This commit is contained in:
parent
e81f16bf5d
commit
703944c39d
@ -36,6 +36,13 @@
|
|||||||
# include "../../png.h"
|
# include "../../png.h"
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
/* The following is to support direct compilation of this file as C++ */
|
||||||
|
#ifdef __cplusplus
|
||||||
|
# define voidcast(type, value) static_cast<type>(value)
|
||||||
|
#else
|
||||||
|
# define voidcast(type, value) (value)
|
||||||
|
#endif /* __cplusplus */
|
||||||
|
|
||||||
#if ((defined(PNG_SEQUENTIAL_READ_SUPPORTED)) && defined(PNG_STDIO_SUPPORTED)\
|
#if ((defined(PNG_SEQUENTIAL_READ_SUPPORTED)) && defined(PNG_STDIO_SUPPORTED)\
|
||||||
&& defined(PNG_EASY_ACCESS_SUPPORTED) && defined(PNG_INFO_IMAGE_SUPPORTED))
|
&& defined(PNG_EASY_ACCESS_SUPPORTED) && defined(PNG_INFO_IMAGE_SUPPORTED))
|
||||||
typedef struct
|
typedef struct
|
||||||
@ -82,8 +89,8 @@ static void read_by_row(png_structp png_ptr, png_infop info_ptr,
|
|||||||
{
|
{
|
||||||
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
png_size_t rowbytes = png_get_rowbytes(png_ptr, info_ptr);
|
||||||
|
|
||||||
row = malloc(rowbytes);
|
row = voidcast(png_bytep,malloc(rowbytes));
|
||||||
display = malloc(rowbytes);
|
display = voidcast(png_bytep,malloc(rowbytes));
|
||||||
|
|
||||||
if (row == NULL || display == NULL)
|
if (row == NULL || display == NULL)
|
||||||
png_error(png_ptr, "OOM allocating row buffers");
|
png_error(png_ptr, "OOM allocating row buffers");
|
||||||
@ -302,10 +309,9 @@ static int add_one_file(FILE *fp, char *name)
|
|||||||
/* file open error: */
|
/* file open error: */
|
||||||
perror(name);
|
perror(name);
|
||||||
fprintf(stderr, "%s: open failed\n", name);
|
fprintf(stderr, "%s: open failed\n", name);
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return 1;
|
return 0; /* file not added */
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
Loading…
Reference in New Issue
Block a user