[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
| Date: | -- (:) |
| From: | Damien Doligez <damien.doligez@i...> |
| Subject: | Re: [Caml-list] Copying strings which may contain NUL chars |
On Jan 29, 2005, at 13:00, Richard Jones wrote:
> Is this code safe? hv_iterkey returns a string and a length, but the
> string may contain ASCII NUL characters, and hence I cannot use
> caml_copy_string directly.
>
> Rich.
>
> CAMLprim value
> perl4caml_hv_iterkey (value hev)
> {
> CAMLparam1 (hev);
> CAMLlocal1 (strv);
> HE *he = He_val (hev);
> I32 len;
> char *str = hv_iterkey (he, &len);
> strv = caml_alloc_string (len);
> memcpy (String_val (strv), str, len);
> CAMLreturn (strv);
> }
I don't see anything wrong with this code.
-- Damien