* Copying strings which may contain NUL chars
@ 2005-01-29 12:00 Richard Jones
2005-01-31 16:03 ` [Caml-list] " Damien Doligez
0 siblings, 1 reply; 2+ messages in thread
From: Richard Jones @ 2005-01-29 12:00 UTC (permalink / raw)
To: caml-list
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);
}
--
Richard Jones, CTO Merjis Ltd.
Merjis - web marketing and technology - http://merjis.com
Team Notepad - intranets and extranets for business - http://team-notepad.com
^ permalink raw reply [flat|nested] 2+ messages in thread
* Re: [Caml-list] Copying strings which may contain NUL chars
2005-01-29 12:00 Copying strings which may contain NUL chars Richard Jones
@ 2005-01-31 16:03 ` Damien Doligez
0 siblings, 0 replies; 2+ messages in thread
From: Damien Doligez @ 2005-01-31 16:03 UTC (permalink / raw)
To: caml users
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
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2005-01-31 16:03 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-01-29 12:00 Copying strings which may contain NUL chars Richard Jones
2005-01-31 16:03 ` [Caml-list] " Damien Doligez
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox