[m-users.] Segmentation violation on FFI wrapper for linenoise-ng

Julien Fischer jfischer at opturion.com
Sat Jun 19 23:21:23 AEST 2021

On Sat, 19 Jun 2021, Sean Charles (emacstheviking) wrote:

> Hi Julien,
> Yes, the C++ code uses fgets() which returns NULL on end of file, one is supposed to then use feof() I guess but I didnt write that code.
> As I am checking the value of LineNull first and foremost on return, I
> didn’t (still don’t!) see the harm in what I have done i.e. I only use
> the value in Line to call execute() with if LineNull is 0 i.e. there
> is something, even an empty line, in it. If you press RETURN, it
> allocates a zero length buffer but that is still a non-null address
> which should be fine, and seems to be the case.

Your Mercury code executes the following line

     io.format("LNG: NULL:%d, len:%d, \n", [i(LineNull), i(length(Line))], !IO),

regardless of what the value of LineNull is.  I suspect the call to
length/1 is causing the segmentation fault, since in the case where
LineNull is 1, Line is not set by the foreign code.


More information about the users mailing list