2 commits - src/cairo-surface.c test/create-from-broken-png-stream.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Feb 17 10:01:16 UTC 2024


 src/cairo-surface.c                  |    4 +++-
 test/create-from-broken-png-stream.c |    7 ++-----
 2 files changed, 5 insertions(+), 6 deletions(-)

New commits:
commit bbbc68e6195ba75bcb3ef71a4be8082aa6619862
Merge: 586c8acac 23a643c80
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 17 10:01:14 2024 +0000

    Merge branch 'surface-error-png' into 'master'
    
    _cairo_surface_create_in_error(): Add PNG_ERROR support
    
    See merge request cairo/cairo!524

commit 23a643c80d435b8322d05a0bf127a324f3122333
Author: Uli Schlachter <psychon at znc.in>
Date:   Tue Oct 31 14:54:06 2023 +0100

    _cairo_surface_create_in_error(): Add PNG_ERROR support
    
    Traditionally, loading a malformed PNG file with
    cairo_image_surface_create_from_png() resulted in
    CAIRO_STATUS_NO_MEMORY. This was apparently changed in commit
    c5ee3f11b5f by adding CAIRO_STATUS_PNG_ERROR and using it for errors
    returned from libpng. However, I don't see how this was supposed to
    actually work.
    
    There are a couple of error codes supported by
    _cairo_surface_create_in_error(). Anything else is turned into
    CAIRO_STATUS_NO_MEMORY, which is not a helpful status. For this reason,
    CAIRO_STATUS_PNG_ERROR would be turned into CAIRO_STATUS_NO_MEMORY.
    
    This commit adds support for CAIRO_STATUS_PNG_ERROR to
    _cairo_surface_create_in_error() so that this error can actually be
    returned to the caller.
    
    Signed-off-by: Uli Schlachter <psychon at znc.in>

diff --git a/src/cairo-surface.c b/src/cairo-surface.c
index 2f5a6ac3d..657146790 100644
--- a/src/cairo-surface.c
+++ b/src/cairo-surface.c
@@ -159,6 +159,7 @@ static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_STRIDE, _cairo_surface_nil_invali
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_INVALID_SIZE, _cairo_surface_nil_invalid_size);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_TYPE_MISMATCH, _cairo_surface_nil_device_type_mismatch);
 static DEFINE_NIL_SURFACE(CAIRO_STATUS_DEVICE_ERROR, _cairo_surface_nil_device_error);
+static DEFINE_NIL_SURFACE(CAIRO_STATUS_PNG_ERROR, _cairo_surface_nil_png_error);
 
 static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_UNSUPPORTED, _cairo_surface_nil_unsupported);
 static DEFINE_NIL_SURFACE(CAIRO_INT_STATUS_NOTHING_TO_DO, _cairo_surface_nil_nothing_to_do);
@@ -3133,6 +3134,8 @@ _cairo_surface_create_in_error (cairo_status_t status)
 	return (cairo_surface_t *) &_cairo_surface_nil_device_type_mismatch;
     case CAIRO_STATUS_DEVICE_ERROR:
 	return (cairo_surface_t *) &_cairo_surface_nil_device_error;
+    case CAIRO_STATUS_PNG_ERROR:
+	return (cairo_surface_t *) &_cairo_surface_nil_png_error;
     case CAIRO_STATUS_SUCCESS:
     case CAIRO_STATUS_LAST_STATUS:
 	ASSERT_NOT_REACHED;
@@ -3161,7 +3164,6 @@ _cairo_surface_create_in_error (cairo_status_t status)
     case CAIRO_STATUS_INVALID_MESH_CONSTRUCTION:
     case CAIRO_STATUS_DEVICE_FINISHED:
     case CAIRO_STATUS_JBIG2_GLOBAL_MISSING:
-    case CAIRO_STATUS_PNG_ERROR:
     case CAIRO_STATUS_FREETYPE_ERROR:
     case CAIRO_STATUS_WIN32_GDI_ERROR:
     case CAIRO_INT_STATUS_DWRITE_ERROR:
diff --git a/test/create-from-broken-png-stream.c b/test/create-from-broken-png-stream.c
index 7c02a2639..88cce0aff 100644
--- a/test/create-from-broken-png-stream.c
+++ b/test/create-from-broken-png-stream.c
@@ -61,13 +61,10 @@ preamble (cairo_test_context_t *ctx)
     surface = cairo_image_surface_create_from_png_stream (read_png_from_data,
 							  &offset);
 
-    /* XXX: The actual error is CAIRO_STATUS_PNG_ERROR, but
-     * _cairo_surface_create_in_error() does not support that.
-     */
-    expected = CAIRO_STATUS_NO_MEMORY;
+    expected = CAIRO_STATUS_PNG_ERROR;
     status = cairo_surface_status (surface);
     cairo_surface_destroy (surface);
-    if (status != CAIRO_STATUS_NO_MEMORY) {
+    if (status != expected) {
 	cairo_test_log (ctx,
 			"Error: expected error %s, but got %s\n",
 			cairo_status_to_string (expected),


More information about the cairo-commit mailing list