[PATCH] Ensure null-terminated result from strncpy()

Bryce Harrington <[email protected]>
Newsgroups gmane.comp.lib.cairo
Message-ID <[email protected]>
Signed-off-by: Bryce Harrington <[email protected]>
---
 src/cairo-scaled-font-subsets.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)

diff --git a/src/cairo-scaled-font-subsets.c b/src/cairo-scaled-font-subsets.c
index 2121761..196fa99 100644
--- a/src/cairo-scaled-font-subsets.c
+++ b/src/cairo-scaled-font-subsets.c
@@ -1206,10 +1206,12 @@ _cairo_scaled_font_subset_create_glyph_names (cairo_scaled_font_subset_t *subset
 
 	if (utf16_len == 1) {
 	    int ch = _cairo_unicode_to_winansi (utf16[0]);
-	    if (ch > 0 && _cairo_winansi_to_glyphname (ch))
+	    if (ch > 0 && _cairo_winansi_to_glyphname (ch)) {
 		strncpy (buf, _cairo_winansi_to_glyphname (ch), sizeof (buf));
-	    else
+		buf[sizeof (buf)-1] = '\0';
+	    } else {
 		snprintf (buf, sizeof (buf), "uni%04X", (int) utf16[0]);
+	    }
 
 	    _cairo_string_init_key (&key, buf);
 	    entry = _cairo_hash_table_lookup (names, &key.base);
-- 
1.9.1

-- 
cairo mailing list
[email protected]
http://lists.cairographics.org/mailman/listinfo/cairo
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.