[cairo-commit] 3 commits - src/cairo-font-options.c src/cairo-gstate.c src/cairoint.h src/cairo-truetype-subset.c

GitLab Mirror gitlab-mirror at kemper.freedesktop.org
Sat Feb 11 04:18:05 UTC 2023


 src/cairo-font-options.c    |   35 +++++++++++++++++++++++++++++++++++
 src/cairo-gstate.c          |    2 +-
 src/cairo-truetype-subset.c |    6 +++++-
 src/cairoint.h              |    4 ++++
 4 files changed, 45 insertions(+), 2 deletions(-)

New commits:
commit f2f2d20a367be0e120dc901089d1fd294094a8f2
Merge: 876ee0bb4 e85c242f0
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Sat Feb 11 04:18:03 2023 +0000

    Merge branch 'fix-valgrind-errors' into 'master'
    
    Fix some problems found by valgrind
    
    See merge request cairo/cairo!452

commit e85c242f0a4306f829b9587233dd366f2443a620
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Feb 8 20:09:15 2023 +1030

    Implement a font options compare function and use it in gstate
    
    Valgrind is not happy with the memcmp() to compare font options and it
    won't work correctly with variations and custom_palette.

diff --git a/src/cairo-font-options.c b/src/cairo-font-options.c
index 361882ae5..8876d9265 100644
--- a/src/cairo-font-options.c
+++ b/src/cairo-font-options.c
@@ -105,6 +105,41 @@ _cairo_font_options_init_copy (cairo_font_options_t		*options,
     }
 }
 
+cairo_bool_t
+_cairo_font_options_compare (const cairo_font_options_t	*a,
+                             const cairo_font_options_t	*b)
+{
+    if (a->antialias != b->antialias ||
+        a->subpixel_order != b->subpixel_order ||
+        a->lcd_filter != b->lcd_filter ||
+        a->hint_style != b->hint_style ||
+        a->hint_metrics != b->hint_metrics ||
+        a->round_glyph_positions != b->round_glyph_positions ||
+        a->color_mode != b->color_mode ||
+        a->palette_index != b->palette_index ||
+        a->custom_palette_size != b->custom_palette_size)
+    {
+        return FALSE;
+    }
+
+    if (a->variations && b->variations && strcmp (a->variations, b->variations) != 0)
+        return FALSE;
+    else if (a->variations != b->variations)
+        return FALSE;
+
+    if (a->custom_palette && b->custom_palette &&
+        memcmp (a->custom_palette, b->custom_palette, sizeof (cairo_palette_color_t) * a->custom_palette_size) != 0)
+    {
+        return FALSE;
+    }
+    else if (a->custom_palette != b->custom_palette)
+    {
+        return FALSE;
+    }
+
+    return TRUE;
+}
+
 /**
  * cairo_font_options_create:
  *
diff --git a/src/cairo-gstate.c b/src/cairo-gstate.c
index 0f4fd541a..8a253468d 100644
--- a/src/cairo-gstate.c
+++ b/src/cairo-gstate.c
@@ -1748,7 +1748,7 @@ void
 _cairo_gstate_set_font_options (cairo_gstate_t             *gstate,
 				const cairo_font_options_t *options)
 {
-    if (memcmp (options, &gstate->font_options, sizeof (cairo_font_options_t)) == 0)
+    if (_cairo_font_options_compare (options, &gstate->font_options))
 	return;
 
     _cairo_gstate_unset_scaled_font (gstate);
diff --git a/src/cairoint.h b/src/cairoint.h
index 5ce747ee4..6682e4b30 100644
--- a/src/cairoint.h
+++ b/src/cairoint.h
@@ -897,6 +897,10 @@ cairo_private void
 _cairo_font_options_init_copy (cairo_font_options_t		*options,
 			       const cairo_font_options_t	*other);
 
+cairo_private cairo_bool_t
+_cairo_font_options_compare (const cairo_font_options_t	*a,
+                             const cairo_font_options_t	*b);
+
 cairo_private void
 _cairo_font_options_fini (cairo_font_options_t *options);
 
commit 4fbc2ea3869a5148529ee59161d78952b64bb697
Author: Adrian Johnson <ajohnson at redneon.com>
Date:   Wed Feb 8 20:05:52 2023 +1030

    truetype: revert use of _cairo_strndup
    
    3d102f25 changed the malloc/memcpy to _cairo_strndup but it won't work
    in this case as the string may be UTF-16.

diff --git a/src/cairo-truetype-subset.c b/src/cairo-truetype-subset.c
index 91ee0e90b..78c7dd5ec 100644
--- a/src/cairo-truetype-subset.c
+++ b/src/cairo-truetype-subset.c
@@ -1471,10 +1471,14 @@ find_name (tt_name_t *name, unsigned long size, int name_id, int platform, int e
 	    if (offset + len > size)
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
-	    str = _cairo_strndup (((char*)name) + offset, len);
+	    str = _cairo_malloc (len + 1);
 	    if (str == NULL)
 		return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
+	    memcpy (str,
+		    ((char*)name) + offset,
+		    len);
+	    str[len] = 0;
 	    break;
 	}
     }


More information about the cairo-commit mailing list