On Friday, February 21, 2014 09:20:35 AM René Rebe wrote:
There is no corner case left. At EOF without EOL the string is 0 terminated.
My last patch checks for if the stream reached EOF and removes the
superfluous 0円\n.
I realised after I sent the mail that it was less hairy than I had assumed.
But the way to do it is much simpler than your patch. Just use memrchr instead
of memchr to find the terminating NULL. The read_line function then becomes:
## SNIP ##
memset(p, '\n', LUAL_BUFFERSIZE); /* could be any non-NULL character */
if (fgets(p, LUAL_BUFFERSIZE, f) == NULL) { /* eof? */
luaL_pushresult(&b); /* close buffer */
return (lua_rawlen(L, -1) > 0); /* check whether read something */
}
l = (char*)memrchr(p, '0円', LUAL_BUFFERSIZE) - p;
## SNIP ##
1 insertion and 1 changed line. Though I get a warning that I think must be a
bug in GCC. (It's trying to tell me memrchr returns an int.)