From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by sourceware.org (Postfix) with ESMTPS id B657B385800F for ; Sat, 27 Mar 2021 10:37:17 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org B657B385800F Received: by mail-wr1-x434.google.com with SMTP id x16so8007658wrn.4 for ; Sat, 27 Mar 2021 03:37:17 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=lbtN7Y0YiBIvSxb2cVifg2Tcw6z2zMFVm/JL2c5DGoY=; b=XMFqGcPjorYxlu+/D5g6RwXRgqiPk/DLOokLJ+foxsPYrXR2tPViMQswHxnjzViaqw uukxJ5mu+K4pAKyNDMZYeXi7iGJxzKgYfpv2UDL727PAWASjEhdZNaUmtdX1y7NLWkhe FgPb72kYUOjO72Ve+FQPVTpEEvaWJ5AvzWFxSx3T+4NJtteh39CpszttXjmAKR9vXEt8 YTLDB2jhvpQgtNqw7gPlUIb5ahJ2NLCFSpsOnKtw84LuOOyRES8WweQgC52k68vuDBSj LSbEj8Fg/wtRaoRLobB+6JQR3ylCT6434eUjm2NYClMsrFkml4aUmgjo3eLo9uToieEZ /Mrg== X-Gm-Message-State: AOAM5327zILghM/a7Pldeul7reYSjNYfj3dG6bzuQW6vKv6iqcyIdCTx odFAMqr5V505TdvzZtaM5fCP19qVcetJJe0nQyX5h4SniS8= X-Google-Smtp-Source: ABdhPJzF7vyof0XnARTwHFl7WaVBjS5dW337WS0YoBnDMtOrKumTrlMZhahcDUUZVV3b9kcgp7L/s2RAcd8JpdXjuA0= X-Received: by 2002:a5d:5708:: with SMTP id a8mr17566923wrv.185.1616841436936; Sat, 27 Mar 2021 03:37:16 -0700 (PDT) MIME-Version: 1.0 References: <7eeb24bf-58cc-5316-807e-64434ecf4b83.ref@yahoo.fr> <7eeb24bf-58cc-5316-807e-64434ecf4b83@yahoo.fr> In-Reply-To: From: Jonathan Wakely Date: Sat, 27 Mar 2021 10:37:06 +0000 Message-ID: Subject: Re: Questions about std::string::operator=(char) To: tika Cc: "libstdc++" Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-1.6 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: libstdc++@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Libstdc++ mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 27 Mar 2021 10:37:19 -0000 On Sat, 27 Mar 2021 at 10:35, Jonathan Wakely wrote: > > On Sat, 27 Mar 2021 at 02:26, tika via Libstdc++ wrote: > > > > > > Synopsys:?? assigning a char to a std::string makes a string 1 char long, > > but what happens if that char is zero??? And showing how easily can this > > UB pass undetected through unit testing... > > This is not UB. > > > > > The story:?? I created a stupid bug, that my unit testing did not > > catch....?? And ended up spending more more time debugging the test than > > fixing my bug. > > > > The bug itself is kind of boring...?? Using the return value of int > > snd_get_name(int, char*) C function from the alsa library, and putting > > an int into a string. That's what I think could be a rather common mistake. See the proposal http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2020/p2037r1.html The C++ committee rejected the proposal, so it won't be part of the C++ standard, but it might help you understand the behaviour you see (and why GCC is correct).