]> git.eshelyaron.com Git - emacs.git/commitdiff
Avoid call to strlen in fast_c_string_match_ignore_case.
authorDmitry Antipov <dmantipov@yandex.ru>
Wed, 11 Jul 2012 06:14:19 +0000 (10:14 +0400)
committerDmitry Antipov <dmantipov@yandex.ru>
Wed, 11 Jul 2012 06:14:19 +0000 (10:14 +0400)
* search.c (fast_c_string_match_ignore_case): Change to use
length argument.  Adjust users accordingly.
* lisp.h (fast_c_string_match_ignore_case): Adjust prototype.

src/ChangeLog
src/font.c
src/font.h
src/ftfont.c
src/lisp.h
src/lread.c
src/search.c
src/xfont.c

index 7b47636969e8fc1f279e7f09811417bf62b95af9..8a6dc8644b81d507c697fab14cb882f15fe98d89 100644 (file)
@@ -1,3 +1,10 @@
+2012-07-11  Dmitry Antipov  <dmantipov@yandex.ru>
+
+       Avoid call to strlen in fast_c_string_match_ignore_case.
+       * search.c (fast_c_string_match_ignore_case): Change to use
+       length argument.  Adjust users accordingly.
+       * lisp.h (fast_c_string_match_ignore_case): Adjust prototype.
+
 2012-07-11  Paul Eggert  <eggert@cs.ucla.edu>
 
        Assume rename.
 
        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
+       (font_open_by_name): Change 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.
+       * font.h (font_open_by_name, font_parse_xlfd, font_unparse_xlfd):
+       Adjust prototypes.
+       * xfont.c (xfont_decode_coding_xlfd, font_unparse_xlfd):
+       Change 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.
        Use XCAR and XCDR instead of Fcar and Fcdr where possible.
        * callint.c, coding.c, doc.c, editfns.c, eval.c, font.c, fontset.c,
        * frame.c, gnutls.c, minibuf.c, msdos.c, textprop.c, w32fns.c,
-       * w32menu.c, window.c, xmenu.c: Changed to use XCAR and XCDR
+       * w32menu.c, window.c, xmenu.c: Change to use XCAR and XCDR
        where argument type is known to be a Lisp_Cons.
 
 2012-07-10  Tom Tromey  <tromey@redhat.com>
index 27abbe25786f288a4cc76a40e23dedcd4214f365..bbfda984a4d55fe1cbc2dea6f4bbada727a1f818 100644 (file)
@@ -1199,7 +1199,7 @@ font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font)
    length), and return the name length.  If FONT_SIZE_INDEX of FONT is
    0, use PIXEL_SIZE instead.  */
 
-int
+ptrdiff_t
 font_unparse_xlfd (Lisp_Object font, int pixel_size, char *name, int nbytes)
 {
   char *p;
@@ -2642,15 +2642,18 @@ font_delete_unmatched (Lisp_Object vec, Lisp_Object spec, int size)
       if (! NILP (Vface_ignored_fonts))
        {
          char name[256];
+         ptrdiff_t namelen;
          Lisp_Object tail, regexp;
 
-         if (font_unparse_xlfd (entity, 0, name, 256) >= 0)
+         namelen = font_unparse_xlfd (entity, 0, name, 256);
+         if (namelen >= 0)
            {
              for (tail = Vface_ignored_fonts; CONSP (tail); tail = XCDR (tail))
                {
                  regexp = XCAR (tail);
                  if (STRINGP (regexp)
-                     && fast_c_string_match_ignore_case (regexp, name) >= 0)
+                     && fast_c_string_match_ignore_case (regexp, name,
+                                                         namelen) >= 0)
                    break;
                }
              if (CONSP (tail))
index 11329daa6e763ce0a8304b84be561f519f1bdfe0..b4e994397dea9006754703f5c7f38920eb437c23 100644 (file)
@@ -782,8 +782,8 @@ extern void font_parse_family_registry (Lisp_Object family,
                                         Lisp_Object spec);
 
 extern int font_parse_xlfd (char *name, ptrdiff_t len, Lisp_Object font);
-extern int font_unparse_xlfd (Lisp_Object font, int pixel_size,
-                              char *name, int bytes);
+extern ptrdiff_t font_unparse_xlfd (Lisp_Object font, int pixel_size,
+                                   char *name, int bytes);
 extern int font_unparse_fcname (Lisp_Object font, int pixel_size,
                                 char *name, int bytes);
 extern void register_font_driver (struct font_driver *driver, FRAME_PTR f);
index 8e322369868bdb7c929bec275684bea8330a138b..131a27f76e014a403ccda3f2615d975471268e2a 100644 (file)
@@ -598,7 +598,9 @@ ftfont_get_charset (Lisp_Object registry)
   re[j] = '\0';
   regexp = make_unibyte_string (re, j);
   for (i = 0; fc_charset_table[i].name; i++)
-    if (fast_c_string_match_ignore_case (regexp, fc_charset_table[i].name) >= 0)
+    if (fast_c_string_match_ignore_case
+       (regexp, fc_charset_table[i].name,
+        strlen (fc_charset_table[i].name)) >= 0)
       break;
   if (! fc_charset_table[i].name)
     return -1;
index b4499b0eaaa8f741e1435f5652912b1a12a54cf1..5077713451ef32f895fe70ca2561573804b28e14 100644 (file)
@@ -2896,7 +2896,8 @@ extern struct re_pattern_buffer *compile_pattern (Lisp_Object,
                                                  struct re_registers *,
                                                  Lisp_Object, int, int);
 extern ptrdiff_t fast_string_match (Lisp_Object, Lisp_Object);
-extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *);
+extern ptrdiff_t fast_c_string_match_ignore_case (Lisp_Object, const char *,
+                                                 ptrdiff_t);
 extern ptrdiff_t fast_string_match_ignore_case (Lisp_Object, Lisp_Object);
 extern ptrdiff_t fast_looking_at (Lisp_Object, ptrdiff_t, ptrdiff_t,
                                   ptrdiff_t, ptrdiff_t, Lisp_Object);
index c0e4a173eeb4c12c4ed5ff8a821326004617be73..f74d44d12a8b9149d6c6264c36e2e5ed71733618 100644 (file)
@@ -906,7 +906,7 @@ safe_to_load_p (int fd)
 
       if (i >= nbytes
          || fast_c_string_match_ignore_case (Vbytecomp_version_regexp,
-                                             buf + i) < 0)
+                                             buf + i, nbytes - i) < 0)
        safe_p = 0;
     }
   if (safe_p)
index de95f5a30f45a62fc7f35f15d3b25eb859c73eb1..118cec4af481cdd199a84fef938173f35c8936a6 100644 (file)
@@ -490,11 +490,11 @@ fast_string_match (Lisp_Object regexp, Lisp_Object string)
    We assume that STRING contains single-byte characters.  */
 
 ptrdiff_t
-fast_c_string_match_ignore_case (Lisp_Object regexp, const char *string)
+fast_c_string_match_ignore_case (Lisp_Object regexp,
+                                const char *string, ptrdiff_t len)
 {
   ptrdiff_t val;
   struct re_pattern_buffer *bufp;
-  size_t len = strlen (string);
 
   regexp = string_make_unibyte (regexp);
   re_match_object = Qt;
index 2ba7941c9cb4e1fb1535ec5ac1102a098cce66d9..0443b49de8f6c72514817f8c107fd99ce66b14d6 100644 (file)
@@ -434,7 +434,8 @@ xfont_list_pattern (Display *display, const char *pattern,
                {
                  elt = XCAR (tail);
                  if (STRINGP (elt)
-                     && fast_c_string_match_ignore_case (elt, indices[i]) >= 0)
+                     && fast_c_string_match_ignore_case (elt, indices[i],
+                                                         len) >= 0)
                    break;
                }
              if (! CONSP (tail))