From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 23453 invoked by alias); 7 Jan 2013 13:48:52 -0000 Received: (qmail 23358 invoked by uid 48); 7 Jan 2013 13:48:19 -0000 From: "sworddragon2 at aol dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug c/55896] New: Annoying compiler warning Date: Mon, 07 Jan 2013 13:48:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: c X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: sworddragon2 at aol dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Changed-Fields: Message-ID: X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated Content-Type: text/plain; charset="UTF-8" MIME-Version: 1.0 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org X-SW-Source: 2013-01/txt/msg00487.txt.bz2 http://gcc.gnu.org/bugzilla/show_bug.cgi?id=55896 Bug #: 55896 Summary: Annoying compiler warning Classification: Unclassified Product: gcc Version: 4.7.2 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c AssignedTo: unassigned@gcc.gnu.org ReportedBy: sworddragon2@aol.com Created attachment 29097 --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=29097 Example code After changing a global struct to a static variable I got a compiler warning. I have analyzed this and tried to produce a minimum testcase. In the attachments is an example code and compiling it with "gcc -O3 -Wall -Wextra -o test -pedantic test.c" will result in the following warning: In file included from /usr/include/string.h:638:0, from test.c:3: In function 'strncat', inlined from 'load_app_settings' at test.c:39:10: /usr/include/x86_64-linux-gnu/bits/string3.h:150:3: warning: call to __builtin___strncat_chk might overflow destination buffer [enabled by default] Removing static from "static struct status STATUS;" solves the problem. Any random change in load_app_settings() can solve the problem too even if the change has nothing to do with the problem. For example if "strncat(content_2, content_1, w_strlen(content_1) - 1);" is changed to "strncat(content_2, content_1, w_strlen(content_1));" or " && content_1[0] == '['" is removed in the condition.