From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by yquem.inria.fr (Postfix) with ESMTP id 3B618BC8B for ; Mon, 31 Jan 2005 17:03:55 +0100 (CET) Received: from pauillac.inria.fr (pauillac.inria.fr [128.93.11.35]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0VG3s6J001445 for ; Mon, 31 Jan 2005 17:03:55 +0100 Received: from nez-perce.inria.fr (nez-perce.inria.fr [192.93.2.78]) by pauillac.inria.fr (8.7.6/8.7.3) with ESMTP id RAA06229 for ; Mon, 31 Jan 2005 17:03:54 +0100 (MET) Received: from [IPv6:::1] (yquem.inria.fr [128.93.8.37]) by nez-perce.inria.fr (8.13.0/8.13.0) with ESMTP id j0VG3s1s001438 for ; Mon, 31 Jan 2005 17:03:54 +0100 Mime-Version: 1.0 (Apple Message framework v619) In-Reply-To: <20050129120009.GA7721@furbychan.cocan.org> References: <20050129120009.GA7721@furbychan.cocan.org> Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: Content-Transfer-Encoding: 7bit From: Damien Doligez Subject: Re: [Caml-list] Copying strings which may contain NUL chars Date: Mon, 31 Jan 2005 17:03:54 +0100 To: caml users X-Mailer: Apple Mail (2.619) X-Miltered: at nez-perce with ID 41FE56EB.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Miltered: at nez-perce with ID 41FE56EA.000 by Joe's j-chkmail (http://j-chkmail.ensmp.fr)! X-Spam: no; 0.00; damien:01 damien:01 caml-list:01 wrote:01 camlprim:01 camlparam:01 val:01 char:01 alloc:01 memcpy:01 val:01 camlreturn:01 doligez:01 doligez:01 strings:01 X-Spam-Checker-Version: SpamAssassin 3.0.2 (2004-11-16) on yquem.inria.fr X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.0.2 X-Spam-Level: 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