BUG/MEDIUM: lua: segfault with buffer_replace2
The function buffer_contig_space() returns the contiguous space avalaible
to add data (at the end of the input side) while the function
hlua_channel_send_yield() needs to insert data starting at p. Here we
introduce a new function bi_space_for_replace() which returns the amount
of space that can be inserted at the head of the input side with one of
the buffer_replace* functions.
This patch proposes a function that returns the space avalaible after buf->p.
diff --git a/src/hlua.c b/src/hlua.c
index 75dd077..3f9b909 100644
--- a/src/hlua.c
+++ b/src/hlua.c
@@ -2281,7 +2281,7 @@
/* The buffer avalaible size may be not contiguous. This test
* detects a non contiguous buffer and realign it.
*/
- if (buffer_contig_space(chn->chn->buf) < max)
+ if (bi_space_for_replace(chn->chn->buf) < max)
buffer_slow_realign(chn->chn->buf);
/* Copy input data in the buffer. */