From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Original-To: caml-list@sympa.inria.fr Delivered-To: caml-list@sympa.inria.fr Received: from mail3-relais-sop.national.inria.fr (mail3-relais-sop.national.inria.fr [192.134.164.104]) by sympa.inria.fr (Postfix) with ESMTPS id 2F8BE8009A for ; Sat, 3 Dec 2016 20:44:54 +0100 (CET) Authentication-Results: mail3-smtp-sop.national.inria.fr; spf=None smtp.pra=gabriel.scherer@gmail.com; spf=Pass smtp.mailfrom=gabriel.scherer@gmail.com; spf=None smtp.helo=postmaster@mail-io0-f169.google.com Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of gabriel.scherer@gmail.com) identity=pra; client-ip=209.85.223.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible Received-SPF: Pass (mail3-smtp-sop.national.inria.fr: domain of gabriel.scherer@gmail.com designates 209.85.223.169 as permitted sender) identity=mailfrom; client-ip=209.85.223.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="gabriel.scherer@gmail.com"; x-conformance=sidf_compatible; x-record-type="v=spf1" Received-SPF: None (mail3-smtp-sop.national.inria.fr: no sender authenticity information available from domain of postmaster@mail-io0-f169.google.com) identity=helo; client-ip=209.85.223.169; receiver=mail3-smtp-sop.national.inria.fr; envelope-from="gabriel.scherer@gmail.com"; x-sender="postmaster@mail-io0-f169.google.com"; x-conformance=sidf_compatible IronPort-PHdr: =?us-ascii?q?9a23=3ApFjgsRBcFaE+bzOGFwrwUyQJP3N1i/DPJgcQr6Af?= =?us-ascii?q?oPdwSPTyr8bcNUDSrc9gkEXOFd2CrakV0KyK7uu9CSQp2tWoiDg6aptCVhsI24?= =?us-ascii?q?09vjcLJ4q7M3D9N+PgdCcgHc5PBxdP9nC/NlVJSo6lPwWB6nK94iQPFRrhKAF7?= =?us-ascii?q?Ovr6GpLIj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AY+TerqiEeDUTFJfXqyUb?= =?us-ascii?q?g8tXkHD9fsN4bIRom3jPS+mgL9Vr9RYG1dQBjYC3bjd62NXfEBeCObZMh7nWpX?= =?us-ascii?q?e6KmTtoO3Bu0tQL+g4FsLufO9zdQ4Z3q3sJ06umVjhoy+CZ5FeyS1miMSyd/mW?= =?us-ascii?q?ZeFGx+57x2vUEokgTL6qN/mfENUIEK6g=3D=3D?= X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: =?us-ascii?q?A0BkAADeH0NYhqnfVdFdGgEBAQECAQEBA?= =?us-ascii?q?QgBAQEBFQEBAQECAQEBAQgBAQEBgw0BAQEBAXmBBgeNQJcKgjeGLYdOhEuCCCm?= =?us-ascii?q?FeQKCFgc/FAEBAQEBAQEBAQEBEgEBAQgLCwkdMIIzGoIbAQEBAwEjHQEbEgsBA?= =?us-ascii?q?wELBgUEBw0NHQICIgERAQUBChIGExIJiDkBAw8IDqB3P4t9ggQFAR+DDQWDUAo?= =?us-ascii?q?ZJwMKVIMiAQEBAQEBBAEBAQEBAQEBFwIGEoYshFuEdYJXgl0Fhw4MiGKFAIVqg?= =?us-ascii?q?XiEU4pMgkKNe0mNOYJIFB6BEw8QgS9EEYJtLCCCBiA0igABAQE?= X-IPAS-Result: =?us-ascii?q?A0BkAADeH0NYhqnfVdFdGgEBAQECAQEBAQgBAQEBFQEBAQE?= =?us-ascii?q?CAQEBAQgBAQEBgw0BAQEBAXmBBgeNQJcKgjeGLYdOhEuCCCmFeQKCFgc/FAEBA?= =?us-ascii?q?QEBAQEBAQEBEgEBAQgLCwkdMIIzGoIbAQEBAwEjHQEbEgsBAwELBgUEBw0NHQI?= =?us-ascii?q?CIgERAQUBChIGExIJiDkBAw8IDqB3P4t9ggQFAR+DDQWDUAoZJwMKVIMiAQEBA?= =?us-ascii?q?QEBBAEBAQEBAQEBFwIGEoYshFuEdYJXgl0Fhw4MiGKFAIVqgXiEU4pMgkKNe0m?= =?us-ascii?q?NOYJIFB6BEw8QgS9EEYJtLCCCBiA0igABAQE?= X-IronPort-AV: E=Sophos;i="5.33,294,1477954800"; d="scan'208,217";a="202723471" Received: from mail-io0-f169.google.com ([209.85.223.169]) by mail3-smtp-sop.national.inria.fr with ESMTP/TLS/AES128-GCM-SHA256; 03 Dec 2016 20:44:53 +0100 Received: by mail-io0-f169.google.com with SMTP id c21so492626238ioj.1 for ; Sat, 03 Dec 2016 11:44:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=Q+wb3tk9mZi3P2OtIiN5O+L8+aAx2g7tuBQta1780HQ=; b=OiwVSGQW9T9cYqitRH5plND0QLNiwnLYFRVswFLdQ2lR67qOQYsoEndea1Efa6xM92 i0l2OsCp4tgL0OD87SgBUb6eNZPtF7LN3rzMf24aapxsEwG8Il1qXqrTeSlqwc0VrF3g 39rFmJHdSxV4yKcROced1OwXGyVcfGJEegghvl3NZrrC1zbaq85atj6/RaQ3iTijT67e 8b/USCBCvv14Ne/DA4JJOYoJJz6ozjuLVx8kqJmzpZ6OwWDt5SDOkgbNd8N3h8LDGPB0 2Lzu8EagRZ7NStB1m2u6Vwza1wVINXwbI2Htnvmx0ckA65czfZ1qmVKD3D8bKDD30A3e WFfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=Q+wb3tk9mZi3P2OtIiN5O+L8+aAx2g7tuBQta1780HQ=; b=Tz9rfJYRT2I8iOCOkiQVjUsZNkeLwJ4YhQr/2d22//eqJ9PyBeh5fUwLRYB4WsPMV4 H+0BGqw6vos0JAKrL5RYqLkA+bxIwzRLvjd9vDoThnvzkVNgXU8JkEbEVGXQRUmKMfFv umxy0IEpUVRMw0YE3OBphdQrwXDrHh73OThu0l5wG2+CJOnPDzATJNZ5O4aMOks2xVoA zvqyoWq0bWJrZD4kbxdTjVyQUSpTNUUh/RHxZ7v+ID+4iPtfxzmiG2Deraym9ORBrt5K VT2MoDefqbesZL6EKuirDA0YB8sy/+bbBOKYnrIFR1x4aaEgdzSunl+mJklyDEsk6Hdt jwbA== X-Gm-Message-State: AKaTC01bvkhO1RLP7FvpqyPxoF9vK4FGUGi1OlEUhDrNAdYko+DXMLUVUC5HjBjHA2+o/WyQRmM1MqrsF89prA== X-Received: by 10.36.14.84 with SMTP id 81mr2728563ite.54.1480794291363; Sat, 03 Dec 2016 11:44:51 -0800 (PST) MIME-Version: 1.0 Received: by 10.79.140.146 with HTTP; Sat, 3 Dec 2016 11:44:10 -0800 (PST) In-Reply-To: <20161203193624.GB28111@annexia.org> References: <20161203132028.GA28111@annexia.org> <20161203193624.GB28111@annexia.org> From: Gabriel Scherer Date: Sat, 3 Dec 2016 14:44:10 -0500 Message-ID: To: "Richard W.M. Jones" Cc: immanuel litzroth , OCaML List Mailing Content-Type: multipart/alternative; boundary=001a1143e56ab8e38c0542c649d8 Subject: Re: [Caml-list] Raising invalid_argument with a constructed string. --001a1143e56ab8e38c0542c649d8 Content-Type: text/plain; charset=UTF-8 I guess I'm not modern enough to feel comfortable using alloca (or variable-length arrays) in my code :-) On Sat, Dec 3, 2016 at 2:36 PM, Richard W.M. Jones wrote: > On Sat, Dec 03, 2016 at 03:00:57PM +0100, immanuel litzroth wrote: > > Yes, I've used that solution too, keeping a static fixed string around, > > it's just not very nice and will break if it's ever multithreaded. > > You shouldn't make the string static, and we do *not* do that in > libguestfs. You should simply allocate it on the stack. This is > thread safe. > > Also on the bug it was stated: > > > The stack-based solutions rely on guessing arbitrary size limits on > > the dynamic strings, which is often possibles but sometimes > > inconvenient/inelegant. > > but this is not true either. You can use alloca to allocate a > variable sized string on the stack. > > As Xavier Leroy says, fixing this is not necessary, although there's > perhaps a usability argument. > > Rich. > > -- > Caml-list mailing list. Subscription management and archives: > https://sympa.inria.fr/sympa/arc/caml-list > Beginner's list: http://groups.yahoo.com/group/ocaml_beginners > Bug reports: http://caml.inria.fr/bin/caml-bugs > --001a1143e56ab8e38c0542c649d8 Content-Type: text/html; charset=UTF-8 Content-Transfer-Encoding: quoted-printable
I guess I'm not modern enough to feel comfortable usin= g alloca (or variable-length arrays) in my code :-)

On Sat, Dec 3, 2016 at 2:36 PM, Richa= rd W.M. Jones <rich@annexia.org> wrote:
On Sat, Dec 03, 2016 at 03:00:57PM +0100, immanuel litz= roth wrote:
> Yes, I've used that solution too, keeping a static fixed string ar= ound,
> it's just not very nice and will break if it's ever multithrea= ded.

You shouldn't make the string static, and we do *not* do that in=
libguestfs.=C2=A0 You should simply allocate it on the stack.=C2=A0 This is=
thread safe.

Also on the bug it was stated:

> The stack-based solutions rely on guessing arbitrary size limits on
> the dynamic strings, which is often possibles but sometimes
> inconvenient/inelegant.

but this is not true either.=C2=A0 You can use alloca to allocate a
variable sized string on the stack.

As Xavier Leroy says, fixing this is not necessary, although there's
perhaps a usability argument.

Rich.

--
Caml-list mailing list.=C2=A0 Subscription management and archives:
https://sympa.inria.fr/sympa/arc/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

--001a1143e56ab8e38c0542c649d8--