From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 35126 invoked by alias); 22 Nov 2017 16:16:00 -0000 Mailing-List: contact gdb-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: gdb-owner@sourceware.org Received: (qmail 35107 invoked by uid 89); 22 Nov 2017 16:16:00 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,KAM_SHORT,KB_WAM_FROM_NAME_SINGLEWORD,RCVD_IN_DNSWL_NONE,SPF_PASS autolearn=no version=3.3.2 spammy=H*f:sk:86r2str, HCc:U*gdb, watch X-HELO: mail-oi0-f43.google.com Received: from mail-oi0-f43.google.com (HELO mail-oi0-f43.google.com) (209.85.218.43) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Wed, 22 Nov 2017 16:15:58 +0000 Received: by mail-oi0-f43.google.com with SMTP id h6so11262466oia.10 for ; Wed, 22 Nov 2017 08:15:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc:content-transfer-encoding; bh=X/drTjA8sYdqqiLda0u+ExofeZ2SjViOEmFKAD1impY=; b=RSvXPqXXo42j4jPFPJcB8a1j+z2e/zzCzs2nmiBTQ0xvpDEJA/Q5ASp3R4zg/A+PEo /avrJWBxastFAJNz2dslCZSy1xXzEU6sthp8VogXHXy4v5STQafk+I/4LPkYu5HWG61M 9wuAo/0sGMt4nB8U4XL9ARKPzYS5bUpNnDj3SoORESBOBeAJY2VM2Trj5NiC6IZDphsV lsFdNuSkgMdsREmIstuz5fSb4PcJukbe//RBR8kxAZ0zlHNAnLSTBYVRbst/RC9msiRk T6krQiYpbr4u9hVBbE6XfDJO2rsXL75M6FOtcRMesTvWSdy3R+dgcakY2ijT/pcZbZ8d 21Yg== X-Gm-Message-State: AJaThX4z4FNlES+BbrLXbkTZUdnuHfvf0DH2vnth6C9L10ooOu//HLwk rtAyiTij6k/e0FxLwllkjvACh2bU1IGac+oZAOtb5Q== X-Google-Smtp-Source: AGs4zMb+onjgPJ4c4L8OiJ0OYqgSgSf9KgK10wGEEEL2mLntFrjIgmOvVHQ7t/2jaNW0o/+d2WbgievFSBKIFj5Ebcw= X-Received: by 10.202.180.132 with SMTP id d126mr995650oif.299.1511367357031; Wed, 22 Nov 2017 08:15:57 -0800 (PST) MIME-Version: 1.0 Received: by 10.157.81.200 with HTTP; Wed, 22 Nov 2017 08:15:56 -0800 (PST) In-Reply-To: References: <86r2strlrd.fsf@gmail.com> From: Eric Gallager Date: Wed, 22 Nov 2017 16:16:00 -0000 Message-ID: Subject: Re: Fail to compile GDB with recent GCC trunk (-Werror=stringop-overflow=, -Werror=stringop-truncation) To: Yao Qi Cc: gcc@gcc.gnu.org, gdb@sourceware.org, msebor@redhat.com Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-SW-Source: 2017-11/txt/msg00024.txt.bz2 On 11/20/17, Eric Gallager wrote: > On 11/20/17, Yao Qi wrote: >> >> Hi, >> I failed to compile GDB with GCC trunk (8.0.0 20171117) because of some >> -Werror=3Dstringop-overflow=3D and -Werror=3Dstringop-truncation warning= s. >> Some of them are not necessary to me, >> >> 1. ../../binutils-gdb/gdb/python/py-gdb-readline.c:79:15: error: =E2=80= =98char* >> strncpy(char*, const char*, size_t)=E2=80=99 output truncated before ter= minating >> nul >> copying as many bytes from a string as its length >> [-Werror=3Dstringop-truncation] >> strncpy (q, p, n); >> ~~~~~~~~^~~~~~~~~ >> ../../binutils-gdb/gdb/python/py-gdb-readline.c:73:14: note: length >> computed >> here >> n =3D strlen (p); >> ~~~~~~~^~~ >> >> the code is simple, >> >> n =3D strlen (p); >> >> /* Copy the line to Python and return. */ >> q =3D (char *) PyMem_RawMalloc (n + 2); >> if (q !=3D NULL) >> { >> strncpy (q, p, n); >> q[n] =3D '\n'; >> q[n + 1] =3D '\0'; >> } >> >> I don't see the point of warning here. >> >> 2. ../../binutils-gdb/gdb/cp-namespace.c:1071:11: error: =E2=80=98char* >> strncpy(char*, const char*, size_t)=E2=80=99 output truncated before ter= minating >> nul >> copying 2 bytes from a string of the same length >> [-Werror=3Dstringop-truncation] >> strncpy (full_name + scope_length, "::", 2); >> ~~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ >> >> full_name =3D (char *) alloca (scope_length + 2 + strlen (name) + 1); >> strncpy (full_name, scope, scope_length); >> strncpy (full_name + scope_length, "::", 2); >> strcpy (full_name + scope_length + 2, name); >> >> the code looks right to me, >> >> Likewise, >> >> ../../../binutils-gdb/gdb/gdbserver/remote-utils.c:1204:14: error: =E2= =80=98char* >> strncpy(char*, const char*, size_t)=E2=80=99 output truncated before ter= minating >> nul >> copying 6 bytes from a string of the same length >> [-Werror=3Dstringop-truncation] >> strncpy (buf, "watch:", 6); >> ~~~~~~~~^~~~~~~~~~~~~~~~~~ >> >> strncpy (buf, "watch:", 6); >> buf +=3D 6; >> .... >> *buf =3D '\0'; >> >> I can "fix" these warnings by changing GDB code, use strcpy in 1) and >> use memcpy in 2). Do we expect all the users of GCC 8 changing their >> correct code because GCC is not happy on the code? The warning is too >> aggressive to me. >> >> -- >> Yao (=E9=BD=90=E5=B0=A7) >> > > I thought there was a gcc bug open about this but now I can't seem to > find it; please let me know if you come across the one I was trying to > remember... > Never mind, I found the bug I was looking for (80354), but it was about -Wformat-truncation, not -Wstringop-truncation, and it's closed, not open, and the point I made in it was about sprintf vs. snprintf, not strcpy vs. strncpy (although it applies equally as well in both cases): https://gcc.gnu.org/bugzilla/show_bug.cgi?id=3D80354