From afb7dafb44d240c9c306a41905812a40d700086c Mon Sep 17 00:00:00 2001 From: Aurelien DARRAGON Date: Tue, 4 Oct 2022 12:16:05 +0200 Subject: [PATCH] BUG/MINOR: hlua: hlua_channel_insert_data() behavior conflicts with documentation Channel.insert(channel, string, [,offset]): When no offset is provided, hlua_channel_insert_data() inserts string at the end of incoming data. This behavior conflicts with the documentation that explicitly says that the default behavior is to insert the string in front of incoming data. This patch fixes hlua_channel_insert_data() behavior so that it fully complies with the documentation. Thanks to Smackd0wn for noticing it. This could be backported to 2.6 and 2.5 --- src/hlua.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/hlua.c b/src/hlua.c index ee48f5c92f..19932a5b12 100644 --- a/src/hlua.c +++ b/src/hlua.c @@ -3573,7 +3573,7 @@ __LJMP static int hlua_channel_prepend(lua_State *L) } /* Inserts a given amount of input data at the given offset by a string - * content. By default the string is appended at the end of input data. It + * content. By default the string is appended in front of input data. It * returns the length of the written string, or -1 if the channel is closed or * if the buffer size is too little for the data. * @@ -3599,13 +3599,13 @@ __LJMP static int hlua_channel_insert_data(lua_State *L) if (filter && !hlua_filter_from_payload(filter)) WILL_LJMP(lua_error(L)); - offset = input + output; + offset = output; if (lua_gettop(L) > 2) { offset = MAY_LJMP(luaL_checkinteger(L, 3)); if (offset < 0) offset = MAX(0, (int)input + offset); offset += output; - if (offset < output || offset > output + input) { + if (offset > output + input) { lua_pushfstring(L, "offset out of range."); WILL_LJMP(lua_error(L)); }