lua-users home
lua-l archive

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

On Fri, Feb 21, 2014 at 5:51 PM, Tim Hill <> wrote:
> Arguing that it’s not the programs fault it exploded because “you should not have fed it a non-text file” is bogus.

but it didn't explode.  it simply discards the part of the line after
the \0.  Hey, now that i think of it, we have a line-comment feature
on any file for free!

seriously, what are the consequences of not fixing it?  it means that
any program that uses it to read line-oriented files would get
truncated lines if those lines have embedded terminators.  doesn't
sound too bad.

and why not to fix it anyway?  as someone said before, most of the
included Lua libraries are just thin wrappers of the old and most
common C functions.  this issue is a (known) defect of fgets().
fixing it correctly[1] means replacing fgets() with something else.
this is what typically goes as an external module, not in the Lua

so, i really think there are just two honest, good ways to fix all this:

A.- document it as: "uses old standards, expect weird results if you
do weird things" and provide common alternative implementations as
extra modules (wrappings for getline(), reimplementation using
fgetc(), do it in Lua using file:read(), etc)

B.- bite the bullet and replace fgets() using fgetc()

on other, less minimalist languages, i'd advice B as the only
reasonable way; but on Lua, the libraries are optional, simplistic,
and already inherit several issues from the C libraries.  So, A is
truly a good answer too.

[1] i don't consider the "use fgets() and then try to figure where the
line really ends" a correct fix.  it depends on specific ways fgets()
fail, goes against the (naive) design of fgets() and is frankly ugly.