Re: [PATCH 2/4] scaled fonts: Use wide enough type for pointer arithmetic

Adrian Johnson <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
On 12/02/16 10:19, Simon Richter wrote:
> Hi,
> 
> On 11.02.2016 21:00, Uli Schlachter wrote:
> 
>> Where is this cast back to a pointer that you talk about?
> 
> There are two instances in cairo-scaled-font.c, in lines 480 and 2827.
> Both of them read
> 
>     scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash;
> 
> and the pointer is dereferenced afterwards.
> 
> I agree with your assessment that this should really be a hash value
> only, and using the lower bits might work for that (although the
> bottommost bits are probably all zero due to alignment, so it is not a
> very good hash), but fixing that requires more changes.
> 
>    Simon

Attached is a patch to avoid storing the pointer in the hash value.

-- 
cairo mailing list
[email protected]
https://lists.cairographics.org/mailman/listinfo/cairo
0001-scaled-font-don-t-store-pointer-in-hash-value.patch (text/x-patch, 1.7 KB)
From 8e520e9b7bf1197a932bb3d063c0a7a7115a7698 Mon Sep 17 00:00:00 2001
From: Adrian Johnson <[email protected]>
Date: Sun, 21 Feb 2016 09:07:40 +1030
Subject: [PATCH] scaled-font: don't store pointer in hash value

---
 src/cairo-scaled-font.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/src/cairo-scaled-font.c b/src/cairo-scaled-font.c
index ac80c97..b2557d4 100644
--- a/src/cairo-scaled-font.c
+++ b/src/cairo-scaled-font.c
@@ -85,7 +85,7 @@ static cairo_cache_t cairo_scaled_glyph_page_cache;
 #define CAIRO_SCALED_GLYPH_PAGE_SIZE 32
 struct _cairo_scaled_glyph_page {
     cairo_cache_entry_t cache_entry;
-
+    cairo_scaled_font_t *scaled_font;
     cairo_list_t link;
 
     unsigned int num_glyphs;
@@ -477,7 +477,7 @@ _cairo_scaled_glyph_page_pluck (void *closure)
 
     assert (! cairo_list_is_empty (&page->link));
 
-    scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash;
+    scaled_font = page->scaled_font;
 
     CAIRO_MUTEX_LOCK (scaled_font->mutex);
     _cairo_scaled_glyph_page_destroy (scaled_font, page);
@@ -2824,7 +2824,7 @@ _cairo_scaled_glyph_page_can_remove (const void *closure)
     const cairo_scaled_glyph_page_t *page = closure;
     const cairo_scaled_font_t *scaled_font;
 
-    scaled_font = (cairo_scaled_font_t *) page->cache_entry.hash;
+    scaled_font = page->scaled_font;
     return scaled_font->cache_frozen == 0;
 }
 
@@ -2853,6 +2853,7 @@ _cairo_scaled_font_allocate_glyph (cairo_scaled_font_t *scaled_font,
 	return _cairo_error (CAIRO_STATUS_NO_MEMORY);
 
     page->cache_entry.hash = (unsigned long) scaled_font;
+    page->scaled_font = scaled_font;
     page->cache_entry.size = 1; /* XXX occupancy weighting? */
     page->num_glyphs = 0;
 
-- 
2.1.4
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.