From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mail-io1-xd35.google.com (mail-io1-xd35.google.com [IPv6:2607:f8b0:4864:20::d35]) by sourceware.org (Postfix) with ESMTPS id BD634385DC00 for ; Sun, 31 May 2020 18:32:44 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org BD634385DC00 Received: by mail-io1-xd35.google.com with SMTP id h4so1408260iob.10 for ; Sun, 31 May 2020 11:32:44 -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:from:date:message-id:subject:to; bh=B5iTgy3OCSyFzYV0x/elrStCOlGM6HNgFjigTmQy8io=; b=TBixorK+1bM0diOvfwrlmDVN0a6gSeVExxPofUuZ7KDDLO+/yl8xkU/IESAlauHg0y +4+wtO7i7al2ViJUXhkgjthYPKt1zS5LSvoZi9BY3+s2zybQxADfnJyCipu7WgYd/yX5 pASIAxtnhyH+k72pzG/GaMJc8Vg3A4ibX6TH6yLXAOrRvxK0qCjZHw5eZnLiYo0hgoKK QyyXAzEanbEQPQpTqCbPHf3tftnU5esIpTVeOKQZVHNpG7PXwoAMLLTwcw4fYIKdHa/o Bf6zGBHLJvp4ieQYX7A9bdtWEGVzY7eJ7gWaxitRc+fdfZzix2meuIJpZ4GnlnfiAQ27 7HkQ== X-Gm-Message-State: AOAM531WkaQ7ACQT0K67CHSmLcqqt8yftBUC8P4bN90t/QgFanVKUK0O gObm98zv5SJZgDD9RBF++lAhihscvDxYqRafx91UMCX2 X-Google-Smtp-Source: ABdhPJxVc9b9wLCr2X0jE4xoZjcWyejF+nMGaMPdmIiMghX7JXMPVbzX++TsLL5Guke03tFUVHQ1qYZyxHnf/cPdPsw= X-Received: by 2002:a5e:8e47:: with SMTP id r7mr15787101ioo.204.1590949963942; Sun, 31 May 2020 11:32:43 -0700 (PDT) MIME-Version: 1.0 From: NightStrike Date: Sun, 31 May 2020 14:32:33 -0400 Message-ID: Subject: Strange warning on printf checks To: gcc-help X-Spam-Status: No, score=-3.1 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, HTML_MESSAGE, 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 Content-Type: text/plain; charset="UTF-8" X-Content-Filtered-By: Mailman/MimeDel 2.1.29 X-BeenThere: gcc-help@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-help mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 31 May 2020 18:32:45 -0000 I'm curious if this is a gcc bug or not. The warning I get is trying to highlight a real problem, but it's referring to a string literal as a directive, which I thought was just for the %XX printf commands. Given the following: #include void f() { char x[4]; char y[5]; sprintf(x, "%s_%s", y, y); } $ gcc a.c -c -Wall a.c: In function 'f': a.c:6:16: warning: '_' directive writing 1 byte into a region of size between 0 and 4 [-Wformat-overflow=] 6 | sprintf(x, "%s_%s", y, y); | ^ a.c:6:2: note: 'sprintf' output between 2 and 10 bytes into a destination of size 4 6 | sprintf(x, "%s_%s", y, y); | ^~~~~~~~~~~~~~~~~~~~~~~~~ I hope the fixed width display shows this correctly. The point is that the ^ points to the underscore, which is right, but the message calls the underscore a printf directive. Maybe I'm splitting hairs, but this confused me for a good half hour before I realized what was wrong.