# HG changeset patch # User jbe # Date 1430481412 -7200 # Node ID 8cd9acda385300da81577bcc567b69fcc40530cf # Parent 845e3dce37749b0ef431f8bc8a35d806a1b467ff Bugfix regarding detection of read end in "read" method diff -r 845e3dce3774 -r 8cd9acda3853 moonbridge_io.c --- a/moonbridge_io.c Fri May 01 04:05:31 2015 +0200 +++ b/moonbridge_io.c Fri May 01 13:56:52 2015 +0200 @@ -180,21 +180,27 @@ if (!drain) luaL_buffinit(L, &luabuf); while (1) { remaining = -1; + terminatorpos = NULL; if ( maxread > 0 && - handle->readbufin - handle->readbufout >= (size_t)maxread - luabufcnt + (size_t)maxread - luabufcnt <= handle->readbufin - handle->readbufout ) { - remaining = maxread - luabufcnt; + remaining = (size_t)maxread - luabufcnt; + terminatorpos = memchr( + handle->readbuf + handle->readbufout, + terminator, + remaining + ); } else if (terminatorlen) { terminatorpos = memchr( handle->readbuf + handle->readbufout, terminator, handle->readbufin - handle->readbufout ); - if (terminatorpos) remaining = 1 + ( - terminatorpos - (handle->readbuf + handle->readbufout) - ); } + if (terminatorpos) remaining = 1 + ( + terminatorpos - (handle->readbuf + handle->readbufout) + ); if (remaining >= 0) { if (!drain) { luaL_addlstring(