lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


On Monday 02 August 2004 15:23, Rob Kendrick wrote:
> On Mon, Aug 02, 2004 at 03:13:10PM +0100, David Given wrote:
> > I think I've just found a bug in Lua.
> >
> > In liolib.c, there's the following code in aux_close():
> >
> >     int ok = (pclose(f) != -1) || (fclose(f) == 0);
>
> Daniel Silverstone spotted this a week or so ago, and posted about it
> here: http://lua-users.org/lists/lua-l/2004-07/msg00430.html

Ah, synchronicity is wonderful... and yeah, I should have remembered to check 
the archives.

> He also suggests a patch to fix it in a way that's POSIX compatible.  I
> don't think I've spotted any comment from the Lua guys about it.  (But I
> believe Dan's fix is now in the patches for the Debian package.)

Unfortunately that patch doesn't work. The spec says quite firmly that calling 
pclose() on a file that wasn't opened with popen() is undefined, which means 
it's demons flying out of your nose time. Dan's fix still relies on it 
returning a meaningful errno.

It just so happens that on my embedded system that'll work, but that's just a 
quirk of the implementation. The only safe thing to do is to keep track of 
what sort of file it is and call the right function.

-- 
+- David Given --McQ-+ "USER'S MANUAL VERSION 1.0:  The information
|  dg@cowlark.com    | presented in this publication has been carefully
| (dg@tao-group.com) | for reliability." --- anonymous computer hardware
+- www.cowlark.com --+ manual