1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-05-20 11:40:18 +02:00

Avoid calling `u32_conv_from_encoding' on the null string

* libguile/strings.c (scm_from_stringn): Avoid calling
  `u32_conv_from_encoding' on the null string, by using the same
  fast-path code used if (encoding == NULL).  This is an optimization,
  and also avoids any possible encoding errors.
This commit is contained in:
Mark H Weaver 2012-01-10 06:18:31 -05:00
parent 3248c954db
commit 7532125912

View file

@ -1473,9 +1473,9 @@ scm_from_stringn (const char *str, size_t len, const char *encoding,
if (len == (size_t) -1)
len = strlen (str);
if (encoding == NULL)
if (encoding == NULL || len == 0)
{
/* If encoding is null, use Latin-1. */
/* If encoding is null (or the string is empty), use Latin-1. */
char *buf;
res = scm_i_make_string (len, &buf, 0);
memcpy (buf, str, len);