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 /src/font.c | |
| 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.
Diffstat (limited to 'src/font.c')
| -rw-r--r-- | src/font.c | 24 |
1 files changed, 11 insertions, 13 deletions
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; |