Program exited with code -11 when calling

H. S. Teoh hsteoh at
Wed Jul 1 05:33:48 UTC 2020

On Wed, Jul 01, 2020 at 05:04:28AM +0000, Anthony via Digitalmars-d-learn wrote:
> auto str_utf8 = str.toUTF8();
> bson_error_t error
> auto bson = bson_new_from_json(cast(const uint8_t*)str_utf8.ptr, -1,
> &error);
> I get a "Program exited with code -11" message.
> Does anyone know what I'm doing wrong?

D strings are generally not null-terminated (except for literals).
Before passing them to a C function you need to add a trailing null. Try
using std.conv.toStringz instead of casting the pointer yourself.


A programming language should be a toolbox for the programmer to draw upon, not a minefield of dangerous explosives that you have to very carefully avoid touching in the wrong way.

More information about the Digitalmars-d-learn mailing list