guile-commits
[Top][All Lists]
Advanced

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

[Guile-commits] 05/08: scm_to_stringn: Avoid passing NULL to c_strcasecm


From: Mark H. Weaver
Subject: [Guile-commits] 05/08: scm_to_stringn: Avoid passing NULL to c_strcasecmp.
Date: Tue, 18 Jun 2019 02:08:20 -0400 (EDT)

mhw pushed a commit to branch stable-2.2
in repository guile.

commit a23ee74fab7f192a8b3da76554d27944821754f8
Author: Mark H Weaver <address@hidden>
Date:   Wed May 29 15:31:42 2019 -0400

    scm_to_stringn: Avoid passing NULL to c_strcasecmp.
    
    Reported by Massimiliano Gubinelli <address@hidden> in
    <https://lists.gnu.org/archive/html/guile-user/2019-05/msg00070.html>.
    
    * libguile/strings.c (scm_to_stringn): Check for (encoding == NULL)
    before passing it to 'c_strcasecmp'.  Eliminate redundant 'enc'
    variable.
---
 libguile/strings.c | 11 +++++------
 1 file changed, 5 insertions(+), 6 deletions(-)

diff --git a/libguile/strings.c b/libguile/strings.c
index 9497a3f..180fae1 100644
--- a/libguile/strings.c
+++ b/libguile/strings.c
@@ -2190,11 +2190,13 @@ scm_to_stringn (SCM str, size_t *lenp, const char 
*encoding,
   char *buf;
   size_t ilen, len, i;
   int ret;
-  const char *enc;
 
   if (!scm_is_string (str))
     scm_wrong_type_arg_msg (NULL, 0, str, "string");
 
+  if (encoding == NULL)
+    encoding = "ISO-8859-1";
+
   if (c_strcasecmp (encoding, "UTF-8") == 0)
     /* This is the most common case--e.g., when calling libc bindings
        while using a UTF-8 locale.  */
@@ -2242,13 +2244,10 @@ scm_to_stringn (SCM str, size_t *lenp, const char 
*encoding,
 
   buf = NULL;
   len = 0;
-  enc = encoding;
-  if (enc == NULL)
-    enc = "ISO-8859-1";
   if (scm_i_is_narrow_string (str))
     {
       ret = mem_iconveh (scm_i_string_chars (str), ilen,
-                         "ISO-8859-1", enc,
+                         "ISO-8859-1", encoding,
                          (enum iconv_ilseq_handler) handler, NULL,
                          &buf, &len);
 
@@ -2261,7 +2260,7 @@ scm_to_stringn (SCM str, size_t *lenp, const char 
*encoding,
     }
   else
     {
-      buf = u32_conv_to_encoding (enc,
+      buf = u32_conv_to_encoding (encoding,
                                   (enum iconv_ilseq_handler) handler,
                                   (scm_t_uint32 *) scm_i_string_wide_chars 
(str),
                                   ilen,



reply via email to

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