From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-il1-x12b.google.com (mail-il1-x12b.google.com [IPv6:2607:f8b0:4864:20::12b]) by sourceware.org (Postfix) with ESMTPS id 92D46385840F for ; Tue, 5 Mar 2024 22:42:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 92D46385840F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=baylibre.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=baylibre.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 92D46385840F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::12b ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709678580; cv=none; b=Zr+v4e2R9soNJ/EpAHiKtexvkGk7rzCjhXOnN0NtrvKuTaqjZMQ4FI/FaG21WI20K0EETMpzCGPUg2kGEqxS+LIMbwNSfIzTMUDmq99zSlpRYLvsB3WdBcbhUNEQKtsADjJD74HK7uYZcWIUzWXosQ9CoMmKk0hYcMNqYU3VCys= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1709678580; c=relaxed/simple; bh=tAC/qIIdqSa6AaO1Mnk5WgCmbqT0oGmZgxUIcW3eqY8=; h=DKIM-Signature:Message-ID:Date:MIME-Version:Subject:To:From; b=YV/g4XivVkds52zgDjyT/Cb5zWvWH6x9KVyDHLGEVpqy+eygYEfsbWUTzaLV2ycPO/4EulDl1Kk//cqIzvv3D+vvQ934OIs/8ggk/6+XGKc69SkObRFEPYEj5U8kyJIaLnl09Po0IoWjhgkqBGAut1SUNbR0J4MMTNHJl5F/sLQ= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x12b.google.com with SMTP id e9e14a558f8ab-365bd66bea9so22612045ab.3 for ; Tue, 05 Mar 2024 14:42:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20230601.gappssmtp.com; s=20230601; t=1709678577; x=1710283377; darn=gcc.gnu.org; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=N3g2/dyEqteuXpTYLMrlbwr+JLjOr389BXcq35mM79o=; b=R4/Q5dRB5ToN+LKh3ctkgIs0kbtWGtbyt3MxR1t+ZbV+Nz+XfGRoygI8uPUJTAXtzw NpJFoEhBSkVrTRSPeanQZiGBsLLjMgYPlOrVvvchWhJT79WX+YMA/nmvbfLL5yIBf5a2 Z79R/bQHP+p9UBgd0a4WuEVBvuqnzKNeRGhGveeT8N68mgJj7wDFnpS4ezS47/+kTmh0 imWQCK2jIg1fimAeTphW9Nky3fITplzcwT5WHbcWDzWVekS9VShmMZQuQIX+mK7CjLNO gI3Flb0lZTHlQ2oeguLrL+Jny5xj+9pqw472EJ47N9Bh5Fb3eYQj80V1Mr9Tum19sx9k 3nSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1709678577; x=1710283377; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=N3g2/dyEqteuXpTYLMrlbwr+JLjOr389BXcq35mM79o=; b=gfREMsA0wiHW1bKGOq/tgrp07roJRQGtCDi8PIzBd2GApvdyDcqxcDZsRAvMg3fOaZ 2BSvCReS4UvpqH7O4vxmaRZ/Tig/Md5COhdJGKoTzkpVYojYMGj67WrHkHEe/ElLr5O4 QrGZCcP1o++V3PLAr24TcY7SrbLImejhu+wDkL8Ke5Bu2k6ZoceHA3uRTnDLWJMWncc1 kUAgrKLI5QPwULoyGwj4a+arXx1cotQyY17b9O59RAcCiNtUKJgVdwEB2MzJzLp+Xa99 iQb/WXKQMbyMUhVOY7QJk+sevJHbs+fxrN61LmyV0Ed2y+raPEfnBjLpwD7TwNeTM0HW 1VXg== X-Forwarded-Encrypted: i=1; AJvYcCXotQiU60BN+wAkx5c/i8qkam3Zm0chcISa2M7lVXZKQ37mc7jWr5GzOCQFOtOkIeNMEYtLPNWCJaUlMTC13L93fXzD755jIg== X-Gm-Message-State: AOJu0YyDUg8HIyFhKZR4Dn+TGyS3NSC4bweImn5B9Oa8MSaKUa62JmI7 0H3D4KBop/f+IgeVMmHbpNcpFbVSf9vpSWYBjos49YAe1O6ngHnAm9+VropeTX8= X-Google-Smtp-Source: AGHT+IGeLhcsJfav9KUQeUE1zd+/Az+76M0blXplFgJde7JvE6YqB6WYTT6TZHXqXmAb/lMEww0/0A== X-Received: by 2002:a05:6e02:1c82:b0:365:b614:5cb7 with SMTP id w2-20020a056e021c8200b00365b6145cb7mr18201388ill.16.1709678576757; Tue, 05 Mar 2024 14:42:56 -0800 (PST) Received: from ?IPV6:2601:281:d901:5620:567a:307d:fb:fc1b? ([2601:281:d901:5620:567a:307d:fb:fc1b]) by smtp.gmail.com with ESMTPSA id h10-20020a056e02052a00b003637871ec98sm3256851ils.27.2024.03.05.14.42.56 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 05 Mar 2024 14:42:56 -0800 (PST) Message-ID: Date: Tue, 5 Mar 2024 15:42:55 -0700 MIME-Version: 1.0 User-Agent: Mozilla Thunderbird Subject: Re: [PATCH v7] C, ObjC: Add -Wunterminated-string-initialization Content-Language: en-US To: Alejandro Colomar , gcc-patches@gcc.gnu.org Cc: Joseph Myers , Mike Stump References: <20240305203353.21784-1-alx@kernel.org> From: Sandra Loosemore In-Reply-To: <20240305203353.21784-1-alx@kernel.org> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-4.0 required=5.0 tests=BAYES_00,DKIM_SIGNED,DKIM_VALID,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 3/5/24 13:33, Alejandro Colomar wrote: > Warn about the following: > > char s[3] = "foo"; > > Initializing a char array with a string literal of the same length as > the size of the array is usually a mistake. Rarely is the case where > one wants to create a non-terminated character sequence from a string > literal. > > In some cases, for writing faster code, one may want to use arrays > instead of pointers, since that removes the need for storing an array of > pointers apart from the strings themselves. > > char *log_levels[] = { "info", "warning", "err" }; > vs. > char log_levels[][7] = { "info", "warning", "err" }; > > This forces the programmer to specify a size, which might change if a > new entry is later added. Having no way to enforce null termination is > very dangerous, however, so it is useful to have a warning for this, so > that the compiler can make sure that the programmer didn't make any > mistakes. This warning catches the bug above, so that the programmer > will be able to fix it and write: > > char log_levels[][8] = { "info", "warning", "err" }; > > This warning already existed as part of -Wc++-compat, but this patch > allows enabling it separately. It is also included in -Wextra, since > it may not always be desired (when unterminated character sequences are > wanted), but it's likely to be desired in most cases. > > Since Wc++-compat now includes this warning, the test has to be modified > to expect the text of the new warning too, in . The documentation parts of the patch are OK. -Sandra