emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] /srv/bzr/emacs/trunk r108992: Avoid calls to strlen in mis


From: Dmitry Antipov
Subject: [Emacs-diffs] /srv/bzr/emacs/trunk r108992: Avoid calls to strlen in miscellaneous functions.
Date: Tue, 10 Jul 2012 11:59:31 +0400
User-agent: Bazaar (2.5.0)

------------------------------------------------------------
revno: 108992
committer: Dmitry Antipov <address@hidden>
branch nick: trunk
timestamp: Tue 2012-07-10 11:59:31 +0400
message:
  Avoid calls to strlen in miscellaneous functions.
  * buffer.c (init_buffer): Use precalculated len, adjust if needed.
  * font.c (Ffont_xlfd_name): Likewise.  Change to call make_string.
  * lread.c (openp): Likewise.
modified:
  src/ChangeLog
  src/buffer.c
  src/font.c
  src/lread.c
=== modified file 'src/ChangeLog'
--- a/src/ChangeLog     2012-07-10 07:37:17 +0000
+++ b/src/ChangeLog     2012-07-10 07:59:31 +0000
@@ -1,11 +1,18 @@
 2012-07-10  Dmitry Antipov  <address@hidden>
 
+       Avoid calls to strlen in miscellaneous functions.
+       * buffer.c (init_buffer): Use precalculated len, adjust if needed.
+       * font.c (Ffont_xlfd_name): Likewise.  Change to call make_string.
+       * lread.c (openp): Likewise.
+
+2012-07-10  Dmitry Antipov  <address@hidden>
+
        Avoid calls to strlen in path processing functions.
        * fileio.c (file_name_as_directory): Add comment.  Change to add
        srclen argument and return the length of result.  Adjust users
        accordingly.
        (directory_file_name): Fix comment.  Change to add srclen argument,
-       swap 1nd and 2st arguments to obey the common convention.  Adjust
+       swap 1st and 2nd arguments to obey the common convention.  Adjust
        users accordingly.
        * filelock.c (fill_in_lock_file_name): Avoid calls to strlen.
 

=== modified file 'src/buffer.c'
--- a/src/buffer.c      2012-07-09 12:02:27 +0000
+++ b/src/buffer.c      2012-07-10 07:59:31 +0000
@@ -5091,9 +5091,10 @@
        fatal ("`get_current_dir_name' failed: %s\n", strerror (errno));
       pwd[len] = DIRECTORY_SEP;
       pwd[len + 1] = '\0';
+      len++;
     }
 
-  BVAR (current_buffer, directory) = make_unibyte_string (pwd, strlen (pwd));
+  BVAR (current_buffer, directory) = make_unibyte_string (pwd, len);
   if (! NILP (BVAR (&buffer_defaults, enable_multibyte_characters)))
     /* At this moment, we still don't know how to decode the
        directory name.  So, we keep the bytes in multibyte form so

=== modified file 'src/font.c'
--- a/src/font.c        2012-07-05 18:35:48 +0000
+++ b/src/font.c        2012-07-10 07:59:31 +0000
@@ -4218,7 +4218,7 @@
   (Lisp_Object font, Lisp_Object fold_wildcards)
 {
   char name[256];
-  int pixel_size = 0;
+  int namelen, pixel_size = 0;
 
   CHECK_FONT (font);
 
@@ -4232,11 +4232,13 @@
          if (NILP (fold_wildcards))
            return font_name;
          strcpy (name, SSDATA (font_name));
+         namelen = SBYTES (font_name);
          goto done;
        }
       pixel_size = XFONT_OBJECT (font)->pixel_size;
     }
-  if (font_unparse_xlfd (font, pixel_size, name, 256) < 0)
+  namelen = font_unparse_xlfd (font, pixel_size, name, 256);
+  if (namelen < 0)
     return Qnil;
  done:
   if (! NILP (fold_wildcards))
@@ -4246,11 +4248,12 @@
       while ((p1 = strstr (p0, "-*-*")))
        {
          strcpy (p1, p1 + 2);
+         namelen -= 2;
          p0 = p1;
        }
     }
 
-  return build_string (name);
+  return make_string (name, namelen);
 }
 
 DEFUN ("clear-font-cache", Fclear_font_cache, Sclear_font_cache, 0, 0, 0,

=== modified file 'src/lread.c'
--- a/src/lread.c       2012-07-10 01:04:28 +0000
+++ b/src/lread.c       2012-07-10 07:59:31 +0000
@@ -1489,7 +1489,7 @@
       for (tail = NILP (suffixes) ? Fcons (empty_unibyte_string, Qnil) : 
suffixes;
           CONSP (tail); tail = XCDR (tail))
        {
-         ptrdiff_t lsuffix = SBYTES (XCAR (tail));
+         ptrdiff_t fnlen, lsuffix = SBYTES (XCAR (tail));
          Lisp_Object handler;
          int exists;
 
@@ -1499,20 +1499,22 @@
              && SREF (filename, 0) == '/'
              && SREF (filename, 1) == ':')
            {
-             strncpy (fn, SSDATA (filename) + 2,
-                      SBYTES (filename) - 2);
-             fn[SBYTES (filename) - 2] = 0;
+             fnlen = SBYTES (filename) - 2;
+             strncpy (fn, SSDATA (filename) + 2, fnlen);
+             fn[fnlen] = '\0';
            }
          else
            {
-             strncpy (fn, SSDATA (filename),
-                      SBYTES (filename));
-             fn[SBYTES (filename)] = 0;
+             fnlen = SBYTES (filename);
+             strncpy (fn, SSDATA (filename), fnlen);
+             fn[fnlen] = '\0';
            }
 
          if (lsuffix != 0)  /* Bug happens on CCI if lsuffix is 0.  */
-           strncat (fn, SSDATA (XCAR (tail)), lsuffix);
-
+           {
+             strncat (fn, SSDATA (XCAR (tail)), lsuffix);
+             fnlen += lsuffix;
+           }
          /* Check that the file exists and is not a directory.  */
          /* We used to only check for handlers on non-absolute file names:
                if (absolute)
@@ -1521,7 +1523,7 @@
                  handler = Ffind_file_name_handler (filename, Qfile_exists_p);
             It's not clear why that was the case and it breaks things like
             (load "/bar.el") where the file is actually "/bar.el.gz".  */
-         string = build_string (fn);
+         string = make_string (fn, fnlen);
          handler = Ffind_file_name_handler (string, Qfile_exists_p);
          if ((!NILP (handler) || !NILP (predicate)) && !NATNUMP (predicate))
             {


reply via email to

[Prev in Thread] Current Thread [Next in Thread]