guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.9-159-gd278d


From: Ludovic Courtès
Subject: [Guile-commits] GNU Guile branch, stable-2.0, updated. v2.0.9-159-gd278dac
Date: Fri, 17 Jan 2014 17:22:24 +0000

This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GNU Guile".

http://git.savannah.gnu.org/cgit/guile.git/commit/?id=d278daca688148f4d1a270e984b054b8ea23cc8a

The branch, stable-2.0 has been updated
       via  d278daca688148f4d1a270e984b054b8ea23cc8a (commit)
       via  3ff8a9d6ff9c8b9f3be7c03b624b3042bb61079f (commit)
      from  802a25b1ed5c738aa5f9d3d01f33eb89b22afd1b (commit)

Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.

- Log -----------------------------------------------------------------
commit d278daca688148f4d1a270e984b054b8ea23cc8a
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jan 17 18:20:09 2014 +0100

    Thank Sree Harsha.

commit 3ff8a9d6ff9c8b9f3be7c03b624b3042bb61079f
Author: Ludovic Courtès <address@hidden>
Date:   Fri Jan 17 18:18:41 2014 +0100

    Arrange so that 'file-encoding' does not truncate the encoding name.
    
    Fixes <http://bugs.gnu.org/16463>.
    Reported by Sree Harsha Totakura <address@hidden>.
    
    * libguile/read.c (ENCODING_NAME_MAX_SIZE): New macro.
      (SCM_ENCODING_SEARCH_SIZE): Change to 500 + ENCODING_NAME_MAX_SIZE.
      (scm_i_scan_for_encoding): Return NULL if there's less than
      ENCODING_NAME_MAX_SIZE bytes once "coding: *" has been read.
    * test-suite/tests/coding.test ("line
      comment")["http://bugs.gnu.org/16463"]: New test.

-----------------------------------------------------------------------

Summary of changes:
 THANKS                       |    1 +
 libguile/read.c              |   30 +++++++++++++++++++++++-------
 test-suite/tests/coding.test |   10 ++++++++--
 3 files changed, 32 insertions(+), 9 deletions(-)

diff --git a/THANKS b/THANKS
index 90a4357..f16376b 100644
--- a/THANKS
+++ b/THANKS
@@ -168,6 +168,7 @@ For fixes or providing information which led to a fix:
          Rainer Tammer
         Samuel Thibault
         Richard Todd
+    Sree Harsha Totakura
             Tom Tromey
           Issac Trotts
            Greg Troxel
diff --git a/libguile/read.c b/libguile/read.c
index f7edc4f..419ad12 100644
--- a/libguile/read.c
+++ b/libguile/read.c
@@ -2046,11 +2046,20 @@ scm_get_hash_procedure (int c)
     }
 }
 
-#define SCM_ENCODING_SEARCH_SIZE (500)
+/* Maximum size of an encoding name.  This is a bit more than the
+   longest name listed at
+   <http://www.iana.org/assignments/character-sets> ("ISO-2022-JP-2", 13
+   characters.)  */
+#define ENCODING_NAME_MAX_SIZE 20
 
-/* Search the first few hundred characters of a file for an Emacs-like coding
-   declaration.  Returns either NULL or a string whose storage has been
-   allocated with `scm_gc_malloc ()'.  */
+/* Number of bytes at the beginning or end of a file that are scanned
+   for a "coding:" declaration.  */
+#define SCM_ENCODING_SEARCH_SIZE (500 + ENCODING_NAME_MAX_SIZE)
+
+
+/* Search the SCM_ENCODING_SEARCH_SIZE bytes of a file for an Emacs-like
+   coding declaration.  Returns either NULL or a string whose storage
+   has been allocated with `scm_gc_malloc'.  */
 char *
 scm_i_scan_for_encoding (SCM port)
 {
@@ -2109,8 +2118,8 @@ scm_i_scan_for_encoding (SCM port)
       if ((pos = strstr(pos, "coding")) == NULL)
         return NULL;
 
-      pos += strlen("coding");
-      if (pos - header >= SCM_ENCODING_SEARCH_SIZE || 
+      pos += strlen ("coding");
+      if (pos - header >= SCM_ENCODING_SEARCH_SIZE ||
           (*pos == ':' || *pos == '='))
         {
           pos ++;
@@ -2119,10 +2128,17 @@ scm_i_scan_for_encoding (SCM port)
     }
 
   /* skip spaces */
-  while (pos - header <= SCM_ENCODING_SEARCH_SIZE && 
+  while (pos - header <= SCM_ENCODING_SEARCH_SIZE &&
         (*pos == ' ' || *pos == '\t'))
     pos ++;
 
+  if (pos - header >= SCM_ENCODING_SEARCH_SIZE - ENCODING_NAME_MAX_SIZE)
+    /* We found the "coding:" string, but there is probably not enough
+       room to store an encoding name in its entirety, so ignore it.
+       This makes sure we do not end up returning a truncated encoding
+       name.  */
+    return NULL;
+
   /* grab the next token */
   encoding_start = pos;
   i = 0;
diff --git a/test-suite/tests/coding.test b/test-suite/tests/coding.test
index a8a415f..b57ef7d 100644
--- a/test-suite/tests/coding.test
+++ b/test-suite/tests/coding.test
@@ -1,6 +1,6 @@
 ;;;; coding.test --- test suite for coding declarations. -*- mode: scheme -*-
 ;;;;
-;;;; Copyright (C) 2011, 2013 Free Software Foundation, Inc.
+;;;; Copyright (C) 2011, 2013, 2014 Free Software Foundation, Inc.
 ;;;;
 ;;;; This library is free software; you can redistribute it and/or
 ;;;; modify it under the terms of the GNU Lesser General Public
@@ -101,4 +101,10 @@
 
   (pass-if-equal "second line, whitespace, nl"
       "ISO-8859-1"
-    (scan-coding "\n; coding: iso-8859-1 \n")))
+    (scan-coding "\n; coding: iso-8859-1 \n"))
+
+  (pass-if-equal "http://bugs.gnu.org/16463";
+      ;; On Guile <= 2.0.9, this would return "ISO-8".
+      "ISO-8859-1"
+    (scan-coding (string-append (make-string 485 #\space)
+                                "; coding: ISO-8859-1"))))


hooks/post-receive
-- 
GNU Guile



reply via email to

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