diff options
author | Mark H Weaver <mhw@netris.org> | 2019-05-29 15:31:42 -0400 |
---|---|---|
committer | Mark H Weaver <mhw@netris.org> | 2019-06-18 02:05:20 -0400 |
commit | a23ee74fab7f192a8b3da76554d27944821754f8 (patch) | |
tree | 793e8892f497d1534d7e58b8cf994815a59ce67e /libguile | |
parent | 75f3ba77596851724079670775e6c3ba3daf5929 (diff) |
scm_to_stringn: Avoid passing NULL to c_strcasecmp.
Reported by Massimiliano Gubinelli <m.gubinelli@gmail.com> 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.
Diffstat (limited to 'libguile')
-rw-r--r-- | libguile/strings.c | 11 |
1 files changed, 5 insertions, 6 deletions
diff --git a/libguile/strings.c b/libguile/strings.c index 9497a3fe1..180fae1ce 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, |