moonbridge

changeset 142:8cd9acda3853

Bugfix regarding detection of read end in "read" method
author jbe
date Fri May 01 13:56:52 2015 +0200 (2015-05-01)
parents 845e3dce3774
children 41da87a681d6
files moonbridge_io.c
line diff
     1.1 --- a/moonbridge_io.c	Fri May 01 04:05:31 2015 +0200
     1.2 +++ b/moonbridge_io.c	Fri May 01 13:56:52 2015 +0200
     1.3 @@ -180,21 +180,27 @@
     1.4    if (!drain) luaL_buffinit(L, &luabuf);
     1.5    while (1) {
     1.6      remaining = -1;
     1.7 +    terminatorpos = NULL;
     1.8      if (
     1.9        maxread > 0 &&
    1.10 -      handle->readbufin - handle->readbufout >= (size_t)maxread - luabufcnt
    1.11 +      (size_t)maxread - luabufcnt <= handle->readbufin - handle->readbufout
    1.12      ) {
    1.13 -      remaining = maxread - luabufcnt;
    1.14 +      remaining = (size_t)maxread - luabufcnt;
    1.15 +      terminatorpos = memchr(
    1.16 +        handle->readbuf + handle->readbufout,
    1.17 +        terminator,
    1.18 +        remaining
    1.19 +      );
    1.20      } else if (terminatorlen) {
    1.21        terminatorpos = memchr(
    1.22          handle->readbuf + handle->readbufout,
    1.23          terminator,
    1.24          handle->readbufin - handle->readbufout
    1.25        );
    1.26 -      if (terminatorpos) remaining = 1 + (
    1.27 -        terminatorpos - (handle->readbuf + handle->readbufout)
    1.28 -      );
    1.29      }
    1.30 +    if (terminatorpos) remaining = 1 + (
    1.31 +      terminatorpos - (handle->readbuf + handle->readbufout)
    1.32 +    );
    1.33      if (remaining >= 0) {
    1.34        if (!drain) {
    1.35          luaL_addlstring(

Impressum / About Us