[cairo-commit] 2 commits - src/cairo-png.c
Chris Wilson
ickle at kemper.freedesktop.org
Wed Oct 31 14:47:49 PDT 2007
src/cairo-png.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
New commits:
commit a26118cf5bf4063a4bdac2bece1bba0be776c801
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Oct 31 16:37:09 2007 +0000
[cairo-png] Check for feof whilst reading.
We need to check for both ferror() and feof() when handling short reads.
diff --git a/src/cairo-png.c b/src/cairo-png.c
index b485eb6..67c87fd 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -500,7 +500,7 @@ stdio_read_func (png_structp png, png_bytep data, png_size_t size)
size_t ret = fread (data, 1, size, fp);
size -= ret;
data += ret;
- if (size && ferror (fp)) {
+ if (size && (feof (fp) || ferror (fp))) {
cairo_status_t *error = png_get_error_ptr (png);
*error = _cairo_error (CAIRO_STATUS_READ_ERROR);
png_error (png, NULL);
commit 61143e5b21ea4c2687c1cef012eb0758a7cb378a
Author: Chris Wilson <chris at chris-wilson.co.uk>
Date: Wed Oct 31 16:34:51 2007 +0000
[cairo-png] Handle missing PNG_SETJMP_SUPPORTED
If libpng has not been compiled with jmpbuf support, then we cannot
atempt to use it - in which case we fall back to png's default error
handler and abort.
diff --git a/src/cairo-png.c b/src/cairo-png.c
index c503994..b485eb6 100644
--- a/src/cairo-png.c
+++ b/src/cairo-png.c
@@ -88,20 +88,24 @@ convert_data_to_bytes (png_structp png, png_row_infop row_info, png_bytep data)
* return.
*/
static void
-png_simple_error_callback (png_structp png_save_ptr,
+png_simple_error_callback (png_structp png,
png_const_charp error_msg)
{
- cairo_status_t *error = png_get_error_ptr (png_save_ptr);
+ cairo_status_t *error = png_get_error_ptr (png);
/* default to the most likely error */
if (*error == CAIRO_STATUS_SUCCESS)
*error = _cairo_error (CAIRO_STATUS_NO_MEMORY);
- longjmp (png_save_ptr->jmpbuf, 1);
+#ifdef PNG_SETJMP_SUPPORTED
+ longjmp (png_jmpbuf (png), 1);
+#endif
+
+ /* if we get here, then we have to choice but to abort ... */
}
static void
-png_simple_warning_callback (png_structp png_save_ptr,
+png_simple_warning_callback (png_structp png,
png_const_charp error_msg)
{
}
@@ -158,8 +162,10 @@ write_png (cairo_surface_t *surface,
goto BAIL3;
}
+#ifdef PNG_SETJMP_SUPPORTED
if (setjmp (png_jmpbuf (png)))
goto BAIL3;
+#endif
png_set_write_fn (png, closure, write_func, NULL);
@@ -396,11 +402,13 @@ read_png (png_rw_ptr read_func,
png_set_read_fn (png, closure, read_func);
status = CAIRO_STATUS_SUCCESS;
+#ifdef PNG_SETJMP_SUPPORTED
if (setjmp (png_jmpbuf (png))) {
if (status != CAIRO_STATUS_NO_MEMORY)
surface = (cairo_surface_t*) &_cairo_surface_nil_read_error;
goto BAIL;
}
+#endif
png_read_info (png, info);
More information about the cairo-commit
mailing list