aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/ChangeLog12
-rw-r--r--src/font.c24
-rw-r--r--src/font.h4
-rw-r--r--src/fontset.c2
-rw-r--r--src/frame.c4
-rw-r--r--src/w32fns.c2
-rw-r--r--src/xfns.c8
-rw-r--r--src/xfont.c14
8 files changed, 39 insertions, 31 deletions
diff --git a/src/ChangeLog b/src/ChangeLog
index 244ba0148ca..ed98c47d1cb 100644
--- a/src/ChangeLog
+++ b/src/ChangeLog
@@ -1,3 +1,15 @@
12012-07-11 Dmitry Antipov <dmantipov@yandex.ru>
2
3 Avoid calls to strlen in font processing functions.
4 * font.c (font_parse_name, font_parse_xlfd, font_parse_fcname)
5 (font_open_by_name): Changed to use length argument. Adjust
6 users accordingly.
7 * font.h (font_open_by_name, font_parse_xlfd): Adjust prototypes.
8 * xfont.c (xfont_decode_coding_xlfd): Changed to return ptrdiff_t.
9 (xfont_list_pattern, xfont_match): Use length returned by
10 xfont_decode_coding_xlfd.
11 * xfns.c (x_default_font_parameter): Omit useless xstrdup.
12
12012-07-11 Glenn Morris <rgm@gnu.org> 132012-07-11 Glenn Morris <rgm@gnu.org>
2 14
3 * s/darwin.h, s/freebsd.h, s/netbsd.h: 15 * s/darwin.h, s/freebsd.h, s/netbsd.h:
diff --git a/src/font.c b/src/font.c
index ea6fc47884c..27abbe25786 100644
--- a/src/font.c
+++ b/src/font.c
@@ -739,7 +739,7 @@ font_put_extra (Lisp_Object font, Lisp_Object prop, Lisp_Object val)
739 739
740static int parse_matrix (const char *); 740static int parse_matrix (const char *);
741static int font_expand_wildcards (Lisp_Object *, int); 741static int font_expand_wildcards (Lisp_Object *, int);
742static int font_parse_name (char *, Lisp_Object); 742static int font_parse_name (char *, ptrdiff_t, Lisp_Object);
743 743
744/* An enumerator for each field of an XLFD font name. */ 744/* An enumerator for each field of an XLFD font name. */
745enum xlfd_field_index 745enum xlfd_field_index
@@ -1019,9 +1019,8 @@ font_expand_wildcards (Lisp_Object *field, int n)
1019 a fully specified XLFD. */ 1019 a fully specified XLFD. */
1020 1020
1021int 1021int
1022font_parse_xlfd (char *name, Lisp_Object font) 1022font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
1023{ 1023{
1024 ptrdiff_t len = strlen (name);
1025 int i, j, n; 1024 int i, j, n;
1026 char *f[XLFD_LAST_INDEX + 1]; 1025 char *f[XLFD_LAST_INDEX + 1];
1027 Lisp_Object val; 1026 Lisp_Object val;
@@ -1336,12 +1335,11 @@ font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
1336 This function tries to guess which format it is. */ 1335 This function tries to guess which format it is. */
1337 1336
1338static int 1337static int
1339font_parse_fcname (char *name, Lisp_Object font) 1338font_parse_fcname (char *name, ptrdiff_t len, Lisp_Object font)
1340{ 1339{
1341 char *p, *q; 1340 char *p, *q;
1342 char *size_beg = NULL, *size_end = NULL; 1341 char *size_beg = NULL, *size_end = NULL;
1343 char *props_beg = NULL, *family_end = NULL; 1342 char *props_beg = NULL, *family_end = NULL;
1344 ptrdiff_t len = strlen (name);
1345 1343
1346 if (len == 0) 1344 if (len == 0)
1347 return -1; 1345 return -1;
@@ -1694,11 +1692,11 @@ font_unparse_fcname (Lisp_Object font, int pixel_size, char *name, int nbytes)
1694 0. Otherwise return -1. */ 1692 0. Otherwise return -1. */
1695 1693
1696static int 1694static int
1697font_parse_name (char *name, Lisp_Object font) 1695font_parse_name (char *name, ptrdiff_t namelen, Lisp_Object font)
1698{ 1696{
1699 if (name[0] == '-' || strchr (name, '*') || strchr (name, '?')) 1697 if (name[0] == '-' || strchr (name, '*') || strchr (name, '?'))
1700 return font_parse_xlfd (name, font); 1698 return font_parse_xlfd (name, namelen, font);
1701 return font_parse_fcname (name, font); 1699 return font_parse_fcname (name, namelen, font);
1702} 1700}
1703 1701
1704 1702
@@ -2987,7 +2985,7 @@ font_spec_from_name (Lisp_Object font_name)
2987 Lisp_Object spec = Ffont_spec (0, NULL); 2985 Lisp_Object spec = Ffont_spec (0, NULL);
2988 2986
2989 CHECK_STRING (font_name); 2987 CHECK_STRING (font_name);
2990 if (font_parse_name (SSDATA (font_name), spec) == -1) 2988 if (font_parse_name (SSDATA (font_name), SBYTES (font_name), spec) == -1)
2991 return Qnil; 2989 return Qnil;
2992 font_put_extra (spec, QCname, font_name); 2990 font_put_extra (spec, QCname, font_name);
2993 font_put_extra (spec, QCuser_spec, font_name); 2991 font_put_extra (spec, QCuser_spec, font_name);
@@ -3359,13 +3357,13 @@ font_open_by_spec (FRAME_PTR f, Lisp_Object spec)
3359 found, return Qnil. */ 3357 found, return Qnil. */
3360 3358
3361Lisp_Object 3359Lisp_Object
3362font_open_by_name (FRAME_PTR f, const char *name) 3360font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len)
3363{ 3361{
3364 Lisp_Object args[2]; 3362 Lisp_Object args[2];
3365 Lisp_Object spec, ret; 3363 Lisp_Object spec, ret;
3366 3364
3367 args[0] = QCname; 3365 args[0] = QCname;
3368 args[1] = make_unibyte_string (name, strlen (name)); 3366 args[1] = make_unibyte_string (name, len);
3369 spec = Ffont_spec (2, args); 3367 spec = Ffont_spec (2, args);
3370 ret = font_open_by_spec (f, spec); 3368 ret = font_open_by_spec (f, spec);
3371 /* Do not lose name originally put in. */ 3369 /* Do not lose name originally put in. */
@@ -3872,7 +3870,7 @@ usage: (font-spec ARGS...) */)
3872 if (EQ (key, QCname)) 3870 if (EQ (key, QCname))
3873 { 3871 {
3874 CHECK_STRING (val); 3872 CHECK_STRING (val);
3875 font_parse_name (SSDATA (val), spec); 3873 font_parse_name (SSDATA (val), SBYTES (val), spec);
3876 font_put_extra (spec, key, val); 3874 font_put_extra (spec, key, val);
3877 } 3875 }
3878 else 3876 else
@@ -4887,7 +4885,7 @@ If the named font is not yet loaded, return nil. */)
4887 4885
4888 if (fontset >= 0) 4886 if (fontset >= 0)
4889 name = fontset_ascii (fontset); 4887 name = fontset_ascii (fontset);
4890 font_object = font_open_by_name (f, SSDATA (name)); 4888 font_object = font_open_by_name (f, SSDATA (name), SBYTES (name));
4891 } 4889 }
4892 else if (FONT_OBJECT_P (name)) 4890 else if (FONT_OBJECT_P (name))
4893 font_object = name; 4891 font_object = name;
diff --git a/src/font.h b/src/font.h
index adb2566327c..11329daa6e7 100644
--- a/src/font.h
+++ b/src/font.h
@@ -771,7 +771,7 @@ extern void font_prepare_for_face (FRAME_PTR f, struct face *face);
771extern void font_done_for_face (FRAME_PTR f, struct face *face); 771extern void font_done_for_face (FRAME_PTR f, struct face *face);
772 772
773extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec); 773extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec);
774extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name); 774extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len);
775 775
776extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len, 776extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len,
777 int force_symbol); 777 int force_symbol);
@@ -781,7 +781,7 @@ extern void font_parse_family_registry (Lisp_Object family,
781 Lisp_Object registry, 781 Lisp_Object registry,
782 Lisp_Object spec); 782 Lisp_Object spec);
783 783
784extern int font_parse_xlfd (char *name, Lisp_Object font); 784extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font);
785extern int font_unparse_xlfd (Lisp_Object font, int pixel_size, 785extern int font_unparse_xlfd (Lisp_Object font, int pixel_size,
786 char *name, int bytes); 786 char *name, int bytes);
787extern int font_unparse_fcname (Lisp_Object font, int pixel_size, 787extern int font_unparse_fcname (Lisp_Object font, int pixel_size,
diff --git a/src/fontset.c b/src/fontset.c
index 056ef31e4f1..3397502a2fd 100644
--- a/src/fontset.c
+++ b/src/fontset.c
@@ -1646,7 +1646,7 @@ FONT-SPEC is a vector, a cons, or a string. See the documentation of
1646 char xlfd[256]; 1646 char xlfd[256];
1647 int len; 1647 int len;
1648 1648
1649 if (font_parse_xlfd (SSDATA (name), font_spec) < 0) 1649 if (font_parse_xlfd (SSDATA (name), SBYTES (name), font_spec) < 0)
1650 error ("Fontset name must be in XLFD format"); 1650 error ("Fontset name must be in XLFD format");
1651 short_name = AREF (font_spec, FONT_REGISTRY_INDEX); 1651 short_name = AREF (font_spec, FONT_REGISTRY_INDEX);
1652 if (strncmp (SSDATA (SYMBOL_NAME (short_name)), "fontset-", 8) 1652 if (strncmp (SSDATA (SYMBOL_NAME (short_name)), "fontset-", 8)
diff --git a/src/frame.c b/src/frame.c
index 8d7981777bf..8f4bdc84a31 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -3167,7 +3167,7 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3167 fontset = fs_query_fontset (arg, 0); 3167 fontset = fs_query_fontset (arg, 0);
3168 if (fontset < 0) 3168 if (fontset < 0)
3169 { 3169 {
3170 font_object = font_open_by_name (f, SSDATA (arg)); 3170 font_object = font_open_by_name (f, SSDATA (arg), SBYTES (arg));
3171 if (NILP (font_object)) 3171 if (NILP (font_object))
3172 error ("Font `%s' is not defined", SSDATA (arg)); 3172 error ("Font `%s' is not defined", SSDATA (arg));
3173 arg = AREF (font_object, FONT_NAME_INDEX); 3173 arg = AREF (font_object, FONT_NAME_INDEX);
@@ -3176,7 +3176,7 @@ x_set_font (struct frame *f, Lisp_Object arg, Lisp_Object oldval)
3176 { 3176 {
3177 Lisp_Object ascii_font = fontset_ascii (fontset); 3177 Lisp_Object ascii_font = fontset_ascii (fontset);
3178 3178
3179 font_object = font_open_by_name (f, SSDATA (ascii_font)); 3179 font_object = font_open_by_name (f, SSDATA (ascii_font), SBYTES (ascii_font));
3180 if (NILP (font_object)) 3180 if (NILP (font_object))
3181 error ("Font `%s' is not defined", SDATA (arg)); 3181 error ("Font `%s' is not defined", SDATA (arg));
3182 arg = AREF (font_object, FONT_NAME_INDEX); 3182 arg = AREF (font_object, FONT_NAME_INDEX);
diff --git a/src/w32fns.c b/src/w32fns.c
index 825f9815482..dac83ab6ae1 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -4036,7 +4036,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
4036 4036
4037 for (i = 0; names[i]; i++) 4037 for (i = 0; names[i]; i++)
4038 { 4038 {
4039 font = font_open_by_name (f, names[i]); 4039 font = font_open_by_name (f, names[i], strlen (names[i]));
4040 if (! NILP (font)) 4040 if (! NILP (font))
4041 break; 4041 break;
4042 } 4042 }
diff --git a/src/xfns.c b/src/xfns.c
index ad3fff85f30..a0229919aa0 100644
--- a/src/xfns.c
+++ b/src/xfns.c
@@ -2956,11 +2956,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
2956 read yet. */ 2956 read yet. */
2957 const char *system_font = xsettings_get_system_font (); 2957 const char *system_font = xsettings_get_system_font ();
2958 if (system_font) 2958 if (system_font)
2959 { 2959 font = font_open_by_name (f, system_font, strlen (system_font));
2960 char *name = xstrdup (system_font);
2961 font = font_open_by_name (f, name);
2962 xfree (name);
2963 }
2964 } 2960 }
2965 2961
2966 if (NILP (font)) 2962 if (NILP (font))
@@ -2990,7 +2986,7 @@ x_default_font_parameter (struct frame *f, Lisp_Object parms)
2990 2986
2991 for (i = 0; names[i]; i++) 2987 for (i = 0; names[i]; i++)
2992 { 2988 {
2993 font = font_open_by_name (f, names[i]); 2989 font = font_open_by_name (f, names[i], strlen (names[i]));
2994 if (! NILP (font)) 2990 if (! NILP (font))
2995 break; 2991 break;
2996 } 2992 }
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