From patchwork Wed Feb 14 21:28:00 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Indu Bhagat X-Patchwork-Id: 873506 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=gcc.gnu.org (client-ip=209.132.180.131; helo=sourceware.org; envelope-from=gcc-patches-return-473304-incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="l9BdtUW2"; dkim-atps=neutral Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3zhXVl72kmz9t2f for ; Thu, 15 Feb 2018 08:25:02 +1100 (AEDT) DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; q=dns; s=default; b=nFR8B9NgMu3X/V86/VrhA9wUFyQGfrVztvxxW/D7rYPqF2VqWl /mFifggL33vdfeWfpKqiI5CWRV4pMAGg82GAZOn1dAEa/zUMwvbXmQbwQosTsSsA bdFlMmRIoWs6CwxJR8t3FxcGcnAEvlmrbdPNPtUq4X7SpCDgNzI5eWqjg= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:to :from:subject:message-id:date:mime-version:content-type; s= default; bh=mdJFfdJJyR+rJt3b+3sbVgUUY38=; b=l9BdtUW2Q72asgOtQIXM cbax1EqBL6Sqk5FwKJ9b3y9E0OSX76iZ6SmEN0T1kdlKn/UPWZvjdNnLXRZMT4NR Vq3gTb6F4Iy/hD8V5MsEhaohT51JXVR2oP+iYf5j27RmOTaJefC8A1+b7hZxF/RG rA68rjCmFowhzYcrdwMWkX8= Received: (qmail 76690 invoked by alias); 14 Feb 2018 21:24:50 -0000 Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org Received: (qmail 76441 invoked by uid 89); 14 Feb 2018 21:24:18 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=BAYES_00, GIT_PATCH_2, GIT_PATCH_3, SPF_PASS, T_RP_MATCHES_RCVD autolearn=ham version=3.3.2 spammy= X-HELO: userp2130.oracle.com Received: from userp2130.oracle.com (HELO userp2130.oracle.com) (156.151.31.86) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 14 Feb 2018 21:24:17 +0000 Received: from pps.filterd (userp2130.oracle.com [127.0.0.1]) by userp2130.oracle.com (8.16.0.22/8.16.0.22) with SMTP id w1ELLklo086351 for ; Wed, 14 Feb 2018 21:24:09 GMT Received: from userv0021.oracle.com (userv0021.oracle.com [156.151.31.71]) by userp2130.oracle.com with ESMTP id 2g4t59gxcs-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK) for ; Wed, 14 Feb 2018 21:24:09 +0000 Received: from userv0122.oracle.com (userv0122.oracle.com [156.151.31.75]) by userv0021.oracle.com (8.14.4/8.14.4) with ESMTP id w1ELO9mX015586 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL) for ; Wed, 14 Feb 2018 21:24:09 GMT Received: from abhmp0008.oracle.com (abhmp0008.oracle.com [141.146.116.14]) by userv0122.oracle.com (8.14.4/8.14.4) with ESMTP id w1ELO7VH020777 for ; Wed, 14 Feb 2018 21:24:09 GMT Received: from [10.159.242.193] (/10.159.242.193) by default (Oracle Beehive Gateway v4.0) with ESMTP ; Wed, 14 Feb 2018 13:24:07 -0800 To: gcc-patches@gcc.gnu.org From: Indu Bhagat Subject: [Patch] Minor GCC documentation correction for -Wformat-overflow Message-ID: <099f32f6-4972-7617-e407-f506877b232b@oracle.com> Date: Wed, 14 Feb 2018 13:28:00 -0800 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 X-Proofpoint-Virus-Version: vendor=nai engine=5900 definitions=8805 signatures=668671 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 suspectscore=1 malwarescore=0 phishscore=0 bulkscore=0 spamscore=0 mlxscore=0 mlxlogscore=884 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1711220000 definitions=main-1802140251 In section "-Wformat-overflow=1", following is stated : void f (int a, int b) { char buf [12]; sprintf (buf, "a = %i, b = %i\n", a, b); } " Increasing the size of the buffer by a single byte is sufficient to avoid the warning," [size of an unknown int for the purpose of this warning is = 1 (to represent 0); add 1 for newline, add 1 for null; add all the other chars in the format string = 14] The minimum increase however needs to be of 2 bytes. i.e., a buf of size 14 is the minimum length for the warning in the example to go away. So the correct statement should be - " Increasing the size of the buffer by two bytes is sufficient to avoid the warning," Alternatively, the size of buf can be bumped up to 13 in the sample code as done in the patch below. Thanks -------------- gcc/ChangeLog: * doc/invoke.texi: Correction in -Wformat-overflow code sample. Index: gcc/doc/invoke.texi =================================================================== --- gcc/doc/invoke.texi (revision 257646) +++ gcc/doc/invoke.texi (working copy) @@ -4184,7 +4184,7 @@ @smallexample void f (int a, int b) @{ - char buf [12]; + char buf [13]; sprintf (buf, "a = %i, b = %i\n", a, b); @} @end smallexample