This is the mail archive of the
ecos-patches@sourceware.org
mailing list for the eCos project.
Re: Please advice w.r.t. language/tcl
- From: "Øyvind Harboe" <oyvind dot harboe at zylin dot com>
- To: "Andrew Lunn" <andrew at lunn dot ch>, jim-devel at lists dot berlios dot de, ecos-patches at ecos dot sourceware dot org
- Date: Tue, 17 Jun 2008 21:52:26 +0200
- Subject: Re: Please advice w.r.t. language/tcl
- Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:in-reply-to:mime-version:content-type :content-transfer-encoding:content-disposition:references :x-google-sender-auth; bh=dRCRyrwTzuFGt6XVc+6yS2UPq707wHHQjn0dLpkSZuo=; b=V6W43Rqrj/3eUuoWI6QvrGUe1KakwFB683MQD+xPIeCppwDDmWsb1ws1eJmsnjQrBm dI+CfUKhFirhEL2kM6CyY22VyzQusb6UHY4al2XzVdxm/C2I1qf4TtrZPtZ36OroftNT E7tRuEXmjCSS1qhwzNdyA0ZI1FqPheXefcUTA=
- Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:in-reply-to:mime-version :content-type:content-transfer-encoding:content-disposition :references:x-google-sender-auth; b=F1fk5M0OF6r6M6T7o0ima5WwsoOCOUCQy8JnLpO0rMoGo2Roe5ZTTBZpZNCi11Aduj PfaNzPtfn2aH0AX2jIPJQzzixV5BNoykixrwLReZmwQn9YKQ1hh6afg/IaIYq7AAe0bA 4Vr0GPTi+Qe99q0D608IejqWdenStyOpuGkCE=
- References: <c09652430806170914t63890b1akcb1efc15c164dee5@mail.gmail.com> <20080617193405.GA26768@lunn.ch>
On Tue, Jun 17, 2008 at 9:34 PM, Andrew Lunn <andrew@lunn.ch> wrote:
> On Tue, Jun 17, 2008 at 06:14:47PM +0200, ?yvind Harboe wrote:
>> Jim Tcl contains an eCos repository in CVS HEAD.
>>
>>
>> http://cvs.berlios.de/cgi-bin/viewcvs.cgi/jim/jim/ecos/
>
> Hi Oyvind
>
> I have gcc 4.3.1 installed as the host compiler. I just tried
> compiling the jim tcl interpreter with synth, ie the host tools and i
> get a warning:
>
> /home/lunn/eCos/anoncvs-clean/packages/net/athttpd/current/src/jim-aio.c:140: warning: array subscript is above array bounds
>
> The code fragment is:
>
> /* GETS */
> char buf[AIO_BUF_LEN];
> Jim_Obj *objPtr;
>
> if (argc != 2 && argc != 3) {
> Jim_WrongNumArgs(interp, 2, argv, "?varName?");
> return JIM_ERR;
> }
> objPtr = Jim_NewStringObj(interp, NULL, 0);
> while (1) {
> int more = 0;
> buf[AIO_BUF_LEN-1] = '_';
> if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL)
> break;
> if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN] == '\n')
>
> buf[AIO_BUF_LEN] is a buffer overrun by one.
>
> Andrew
>
I'm having trouble parsing the docs for fgets(), but
http://linux.die.net/man/3/fgets
indicates that the attached patch should be correct.
What do you think?
### Eclipse Workspace Patch 1.0
#P jim
Index: ChangeLog
===================================================================
RCS file: /cvsroot/jim/jim/ChangeLog,v
retrieving revision 1.131
diff -u -r1.131 ChangeLog
--- ChangeLog 16 Jun 2008 14:03:10 -0000 1.131
+++ ChangeLog 17 Jun 2008 19:51:38 -0000
@@ -1,3 +1,9 @@
+2008-06-17 Andrew Lunn <andrew@lunn.ch> / oharboe
+
+ * ChangeLog, jim-aio.c: Andrew spotted a bug in the
+ aio.gets implementation for lines that are more than
+ AIO_BUF_LEN long. GCC 4.3.1 pointed out this problem.
+
2008-06-16 Uwe Klein wiederling at googlemail.com
* ChangeLog, jim.c: fixed parsing in "expr 0x1234".
Index: jim-aio.c
===================================================================
RCS file: /cvsroot/jim/jim/jim-aio.c,v
retrieving revision 1.12
diff -u -r1.12 jim-aio.c
--- jim-aio.c 15 Jun 2008 21:03:26 -0000 1.12
+++ jim-aio.c 17 Jun 2008 19:51:38 -0000
@@ -143,7 +143,7 @@
buf[AIO_BUF_LEN-1] = '_';
if (fgets(buf, AIO_BUF_LEN, af->fp) == NULL)
break;
- if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN] == '\n')
+ if (buf[AIO_BUF_LEN-1] == '\0' && buf[AIO_BUF_LEN-2] != '\n')
more = 1;
if (more) {
Jim_AppendString(interp, objPtr, buf, AIO_BUF_LEN-1);
--
Øyvind Harboe
http://www.zylin.com/zy1000.html
ARM7 ARM9 XScale Cortex
JTAG debugger and flash programmer