diff options
| author | Dmitry Antipov | 2012-07-11 08:31:53 +0400 |
|---|---|---|
| committer | Dmitry Antipov | 2012-07-11 08:31:53 +0400 |
| commit | 984e7f300ef0bfec7be97c9bbaff5a6295a43aa2 (patch) | |
| tree | 579e8e59109167073410ec78ea8c0ce5479c901f | |
| parent | 9d596af370080cba1e67978018d72a836dba008a (diff) | |
| download | emacs-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.
| -rw-r--r-- | src/ChangeLog | 12 | ||||
| -rw-r--r-- | src/font.c | 24 | ||||
| -rw-r--r-- | src/font.h | 4 | ||||
| -rw-r--r-- | src/fontset.c | 2 | ||||
| -rw-r--r-- | src/frame.c | 4 | ||||
| -rw-r--r-- | src/w32fns.c | 2 | ||||
| -rw-r--r-- | src/xfns.c | 8 | ||||
| -rw-r--r-- | src/xfont.c | 14 |
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 @@ | |||
| 1 | 2012-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 | |||
| 1 | 2012-07-11 Glenn Morris <rgm@gnu.org> | 13 | 2012-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 | ||
| 740 | static int parse_matrix (const char *); | 740 | static int parse_matrix (const char *); |
| 741 | static int font_expand_wildcards (Lisp_Object *, int); | 741 | static int font_expand_wildcards (Lisp_Object *, int); |
| 742 | static int font_parse_name (char *, Lisp_Object); | 742 | static 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. */ |
| 745 | enum xlfd_field_index | 745 | enum 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 | ||
| 1021 | int | 1021 | int |
| 1022 | font_parse_xlfd (char *name, Lisp_Object font) | 1022 | font_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 | ||
| 1338 | static int | 1337 | static int |
| 1339 | font_parse_fcname (char *name, Lisp_Object font) | 1338 | font_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 | ||
| 1696 | static int | 1694 | static int |
| 1697 | font_parse_name (char *name, Lisp_Object font) | 1695 | font_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 | ||
| 3361 | Lisp_Object | 3359 | Lisp_Object |
| 3362 | font_open_by_name (FRAME_PTR f, const char *name) | 3360 | font_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); | |||
| 771 | extern void font_done_for_face (FRAME_PTR f, struct face *face); | 771 | extern void font_done_for_face (FRAME_PTR f, struct face *face); |
| 772 | 772 | ||
| 773 | extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec); | 773 | extern Lisp_Object font_open_by_spec (FRAME_PTR f, Lisp_Object spec); |
| 774 | extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name); | 774 | extern Lisp_Object font_open_by_name (FRAME_PTR f, const char *name, ptrdiff_t len); |
| 775 | 775 | ||
| 776 | extern Lisp_Object font_intern_prop (const char *str, ptrdiff_t len, | 776 | extern 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 | ||
| 784 | extern int font_parse_xlfd (char *name, Lisp_Object font); | 784 | extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font); |
| 785 | extern int font_unparse_xlfd (Lisp_Object font, int pixel_size, | 785 | extern int font_unparse_xlfd (Lisp_Object font, int pixel_size, |
| 786 | char *name, int bytes); | 786 | char *name, int bytes); |
| 787 | extern int font_unparse_fcname (Lisp_Object font, int pixel_size, | 787 | extern 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 | ||
| 177 | static int | 177 | static ptrdiff_t |
| 178 | xfont_decode_coding_xlfd (char *xlfd, int len, char *output) | 178 | xfont_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 |