NetBSD Problem Report #54131

From www@netbsd.org  Fri Apr 19 22:32:57 2019
Return-Path: <www@netbsd.org>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits))
	(Client CN "mail.NetBSD.org", Issuer "mail.NetBSD.org CA" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 9912A7A149
	for <gnats-bugs@gnats.NetBSD.org>; Fri, 19 Apr 2019 22:32:57 +0000 (UTC)
Message-Id: <20190419223256.BEB347A1C2@mollari.NetBSD.org>
Date: Fri, 19 Apr 2019 22:32:56 +0000 (UTC)
From: jperkins+netbsd@google.com
Reply-To: jperkins+netbsd@google.com
To: gnats-bugs@NetBSD.org
Subject: libedit: declaration of i inside for loop in unescape_string
X-Send-Pr-Version: www-1.0

>Number:         54131
>Category:       lib
>Synopsis:       libedit: declaration of i inside for loop in unescape_string
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    abhinav
>State:          closed
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Fri Apr 19 22:35:00 +0000 2019
>Closed-Date:    Sun Apr 21 05:15:19 +0000 2019
>Last-Modified:  Sun Apr 21 05:15:19 +0000 2019
>Originator:     Jonathan Perkins
>Release:        Sources as of 2019/04/19
>Organization:
Google
>Environment:
>Description:
In filecomplete.c, unescape_string has a declaration inside a for loop.  This is incompatible with certain C versions.

The specific line in unescape_string that's an issue is:
	for (size_t i = 0; i < length ; i++) {

This was added in revision 53 (http://cvsweb.netbsd.org/bsdweb.cgi/src/lib/libedit/filecomplete.c.diff?r1=1.52&r2=1.53&only_with_tag=MAIN&f=h)

This just looked like an oversight to me because most of the code declares outside the for loop.  I noticed because we have some code that compiles in a way that hit the issue.
>How-To-Repeat:
gcc -std=c90 -c filecomplete.c -o filecomplete.o
>Fix:
--- old/src/lib/libedit/filecomplete.c
+++ new/src/lib/libedit/filecomplete.c
@@ -193,8 +193,8 @@ unescape_string(const wchar_t *string, s
 	wchar_t *unescaped = el_malloc(sizeof(*string) * (length + 1));
 	if (unescaped == NULL)
 		return NULL;
-	size_t j = 0;
-	for (size_t i = 0; i < length ; i++) {
+	size_t i = 0, j = 0;
+	for (; i < length ; i++) {
 		if (string[i] == '\\')
 			continue;
 		unescaped[j++] = string[i];

>Release-Note:

>Audit-Trail:
From: matthew green <mrg@eterna.com.au>
To: gnats-bugs@netbsd.org
Cc: lib-bug-people@netbsd.org, gnats-admin@netbsd.org,
    netbsd-bugs@netbsd.org
Subject: re: lib/54131: libedit: declaration of i inside for loop in unescape_string
Date: Sat, 20 Apr 2019 17:20:44 +1000

 compile with -std=c99?  use a newer compiler?  i feel like 20
 years is long enough to say "you need a c99 compiler" and
 the default has already changed in GCC and clang...


 .mrg.

From: "Abhinav Upadhyay" <abhinav@netbsd.org>
To: gnats-bugs@gnats.NetBSD.org
Cc: 
Subject: PR/54131 CVS commit: src/lib/libedit
Date: Sat, 20 Apr 2019 08:44:10 +0000

 Module Name:	src
 Committed By:	abhinav
 Date:		Sat Apr 20 08:44:10 UTC 2019

 Modified Files:
 	src/lib/libedit: filecomplete.c

 Log Message:
 PR lib/54131 - declare the loop variable outside the for loop


 To generate a diff of this commit:
 cvs rdiff -u -r1.54 -r1.55 src/lib/libedit/filecomplete.c

 Please note that diffs are not public domain; they are subject to the
 copyright notices on the relevant files.

Responsible-Changed-From-To: lib-bug-people->abhinav
Responsible-Changed-By: abhinav@NetBSD.org
Responsible-Changed-When: Sat, 20 Apr 2019 08:46:30 +0000
Responsible-Changed-Why:
I committed a fix


State-Changed-From-To: open->feedback
State-Changed-By: abhinav@NetBSD.org
State-Changed-When: Sat, 20 Apr 2019 08:47:43 +0000
State-Changed-Why:
Thank you for the PR. Does the committed change work for you?


From: Jon Perkins <jperkins@google.com>
To: gnats-bugs@netbsd.org
Cc: abhinav@netbsd.org, netbsd-bugs@netbsd.org, gnats-admin@netbsd.org, 
	jperkins+netbsd@google.com
Subject: Re: lib/54131 (libedit: declaration of i inside for loop in unescape_string)
Date: Sat, 20 Apr 2019 09:24:12 -0700

 --0000000000008cce730586f8acd4
 Content-Type: text/plain; charset="UTF-8"

 abhinav: Yes, it works for me.  Thanks!

 mrg: If the intent is to require c99, please don't let me stop it.  I
 reported this because the compatibility break was recent, and looked
 unintentional.  While it did break a team's build, I'm also following up
 with them about why they're building like that; I'm surprised it hasn't
 caused them more problems.

 On Sat, Apr 20, 2019 at 1:47 AM <abhinav@netbsd.org> wrote:

 > Synopsis: libedit: declaration of i inside for loop in unescape_string
 >
 > State-Changed-From-To: open->feedback
 > State-Changed-By: abhinav@NetBSD.org
 > State-Changed-When: Sat, 20 Apr 2019 08:47:43 +0000
 > State-Changed-Why:
 > Thank you for the PR. Does the committed change work for you?
 >
 >
 >
 >

 --0000000000008cce730586f8acd4
 Content-Type: text/html; charset="UTF-8"
 Content-Transfer-Encoding: quoted-printable

 <div dir=3D"ltr"><div dir=3D"ltr">abhinav: Yes, it works for me.=C2=A0 Than=
 ks!<br></div><div dir=3D"ltr"><br></div><div>mrg: If the intent is to requi=
 re c99, please don&#39;t let me stop it.=C2=A0 I reported this because the =
 compatibility break was recent, and looked unintentional.=C2=A0 While it di=
 d break a team&#39;s build, I&#39;m also following up with them about why t=
 hey&#39;re building like that; I&#39;m surprised it hasn&#39;t caused them =
 more problems.</div></div><br><div class=3D"gmail_quote"><div dir=3D"ltr" c=
 lass=3D"gmail_attr">On Sat, Apr 20, 2019 at 1:47 AM &lt;<a href=3D"mailto:a=
 bhinav@netbsd.org">abhinav@netbsd.org</a>&gt; wrote:<br></div><blockquote c=
 lass=3D"gmail_quote" style=3D"margin:0px 0px 0px 0.8ex;border-left:1px soli=
 d rgb(204,204,204);padding-left:1ex">Synopsis: libedit: declaration of i in=
 side for loop in unescape_string<br>
 <br>
 State-Changed-From-To: open-&gt;feedback<br>
 State-Changed-By: abhinav@NetBSD.org<br>
 State-Changed-When: Sat, 20 Apr 2019 08:47:43 +0000<br>
 State-Changed-Why:<br>
 Thank you for the PR. Does the committed change work for you?<br>
 <br>
 <br>
 <br>
 </blockquote></div>

 --0000000000008cce730586f8acd4--

State-Changed-From-To: feedback->closed
State-Changed-By: abhinav@NetBSD.org
State-Changed-When: Sun, 21 Apr 2019 05:15:19 +0000
State-Changed-Why:
fix confirmed, thank you for the PR.


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.43 2018/01/16 07:36:43 maya Exp $
$NetBSD: gnats_config.sh,v 1.9 2014/08/02 14:16:04 spz Exp $
Copyright © 1994-2017 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.