diff options
author | Ludovic Courtès <ludo@gnu.org> | 2009-08-18 00:09:26 +0200 |
---|---|---|
committer | Ludovic Courtès <ludo@gnu.org> | 2009-08-18 00:09:26 +0200 |
commit | 1ac8a47f0187d2a96bc4571cb10cbf45b0edc9d4 (patch) | |
tree | c77281cb55da7982f81814f9abd4723c4ff67b8d /libguile/bytevectors.c | |
parent | fbb857a472eb4e69c1cba05e86646b7004f32df6 (diff) | |
download | guile-1ac8a47f0187d2a96bc4571cb10cbf45b0edc9d4.tar.gz |
Fix malloc/scm_c_take_bytevector mismatch.
* libguile/bytevectors.c (STRING_TO_UTF): Use `make_bytevector ()'
instead of `scm_c_take_bytevector ().
(scm_string_to_utf8): Likewise.
Diffstat (limited to 'libguile/bytevectors.c')
-rw-r--r-- | libguile/bytevectors.c | 30 |
1 files changed, 24 insertions, 6 deletions
diff --git a/libguile/bytevectors.c b/libguile/bytevectors.c index 24afd2414..ee7004590 100644 --- a/libguile/bytevectors.c +++ b/libguile/bytevectors.c @@ -1895,9 +1895,18 @@ utf_encoding_name (char *name, size_t utf_width, SCM endianness) scm_syserror_msg (FUNC_NAME, "failed to convert string: ~A", \ scm_list_1 (str), err); \ else \ - /* C_UTF is null-terminated. */ \ - utf = scm_c_take_bytevector ((signed char *) c_utf, \ - c_utf_len); \ + { \ + /* C_UTF is null-terminated. It is malloc(3)-allocated, so we cannot \ + use `scm_c_take_bytevector ()'. */ \ + scm_dynwind_begin (0); \ + scm_dynwind_free (c_utf); \ + \ + utf = make_bytevector (c_utf_len); \ + memcpy (SCM_BYTEVECTOR_CONTENTS (utf), c_utf, \ + c_utf_len); \ + \ + scm_dynwind_end (); \ + } \ \ return (utf); @@ -1931,9 +1940,18 @@ SCM_DEFINE (scm_string_to_utf8, "string->utf8", if (SCM_UNLIKELY (c_utf == NULL)) scm_syserror (FUNC_NAME); else - /* C_UTF is null-terminated. */ - utf = scm_c_take_bytevector ((signed char *) c_utf, - UTF_STRLEN (8, c_utf)); + { + /* C_UTF is null-terminated. It is malloc(3)-allocated, so we cannot + use `scm_c_take_bytevector ()'. */ + scm_dynwind_begin (0); + scm_dynwind_free (c_utf); + + utf = make_bytevector (UTF_STRLEN (8, c_utf)); + memcpy (SCM_BYTEVECTOR_CONTENTS (utf), c_utf, + UTF_STRLEN (8, c_utf)); + + scm_dynwind_end (); + } return (utf); } |