aboutsummaryrefslogtreecommitdiffstats
path: root/src/xfont.c
diff options
context:
space:
mode:
authorDmitry Antipov2012-07-11 08:31:53 +0400
committerDmitry Antipov2012-07-11 08:31:53 +0400
commit984e7f300ef0bfec7be97c9bbaff5a6295a43aa2 (patch)
tree579e8e59109167073410ec78ea8c0ce5479c901f /src/xfont.c
parent9d596af370080cba1e67978018d72a836dba008a (diff)
downloademacs-984e7f300ef0bfec7be97c9bbaff5a6295a43aa2.tar.gz
emacs-984e7f300ef0bfec7be97c9bbaff5a6295a43aa2.zip
Avoid calls to strlen in font processing functions.
* font.c (font_parse_name, font_parse_xlfd, font_parse_fcname) (font_open_by_name): Changed to use length argument. Adjust users accordingly. * font.h (font_open_by_name, font_parse_xlfd): Adjust prototypes. * xfont.c (xfont_decode_coding_xlfd): Changed to return ptrdiff_t. (xfont_list_pattern, xfont_match): Use length returned by xfont_decode_coding_xlfd. * xfns.c (x_default_font_parameter): Omit useless xstrdup.
Diffstat (limited to 'src/xfont.c')
-rw-r--r--src/xfont.c14
1 files changed, 8 insertions, 6 deletions
diff --git a/src/xfont.c b/src/xfont.c
index b7a1e06199e..2ba7941c9cb 100644
--- a/src/xfont.c
+++ b/src/xfont.c
@@ -174,7 +174,7 @@ compare_font_names (const void *name1, const void *name2)
174 XLFD is NULL terminated. The caller must assure that OUTPUT is at 174 XLFD is NULL terminated. The caller must assure that OUTPUT is at
175 least twice (plus 1) as large as XLFD. */ 175 least twice (plus 1) as large as XLFD. */
176 176
177static int 177static ptrdiff_t
178xfont_decode_coding_xlfd (char *xlfd, int len, char *output) 178xfont_decode_coding_xlfd (char *xlfd, int len, char *output)
179{ 179{
180 char *p0 = xlfd, *p1 = output; 180 char *p0 = xlfd, *p1 = output;
@@ -397,13 +397,14 @@ xfont_list_pattern (Display *display, const char *pattern,
397 397
398 for (i = 0; i < num_fonts; i++) 398 for (i = 0; i < num_fonts; i++)
399 { 399 {
400 ptrdiff_t len;
400 Lisp_Object entity; 401 Lisp_Object entity;
401 402
402 if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0) 403 if (i > 0 && xstrcasecmp (indices[i - 1], indices[i]) == 0)
403 continue; 404 continue;
404 entity = font_make_entity (); 405 entity = font_make_entity ();
405 xfont_decode_coding_xlfd (indices[i], -1, buf); 406 len = xfont_decode_coding_xlfd (indices[i], -1, buf);
406 if (font_parse_xlfd (buf, entity) < 0) 407 if (font_parse_xlfd (buf, len, entity) < 0)
407 continue; 408 continue;
408 ASET (entity, FONT_TYPE_INDEX, Qx); 409 ASET (entity, FONT_TYPE_INDEX, Qx);
409 /* Avoid auto-scaled fonts. */ 410 /* Avoid auto-scaled fonts. */
@@ -604,10 +605,11 @@ xfont_match (Lisp_Object frame, Lisp_Object spec)
604 string. We must avoid such a name. */ 605 string. We must avoid such a name. */
605 if (*s) 606 if (*s)
606 { 607 {
608 ptrdiff_t len;
607 entity = font_make_entity (); 609 entity = font_make_entity ();
608 ASET (entity, FONT_TYPE_INDEX, Qx); 610 ASET (entity, FONT_TYPE_INDEX, Qx);
609 xfont_decode_coding_xlfd (s, -1, name); 611 len = xfont_decode_coding_xlfd (s, -1, name);
610 if (font_parse_xlfd (name, entity) < 0) 612 if (font_parse_xlfd (name, len, entity) < 0)
611 entity = Qnil; 613 entity = Qnil;
612 } 614 }
613 XFree (s); 615 XFree (s);
@@ -796,7 +798,7 @@ xfont_open (FRAME_PTR f, Lisp_Object entity, int pixel_size)
796 ASET (font_object, FONT_TYPE_INDEX, Qx); 798 ASET (font_object, FONT_TYPE_INDEX, Qx);
797 if (STRINGP (fullname)) 799 if (STRINGP (fullname))
798 { 800 {
799 font_parse_xlfd (SSDATA (fullname), font_object); 801 font_parse_xlfd (SSDATA (fullname), SBYTES (fullname), font_object);
800 ASET (font_object, FONT_NAME_INDEX, fullname); 802 ASET (font_object, FONT_NAME_INDEX, fullname);
801 } 803 }
802 else 804 else