lcb_wait() crashes with C SDK 2.5.1 and server 4.0 Beta in the N1QL example

The sample is the following one:

 * Simple C "script" showing how to connect to Couchbase 4.0 cluster and
 * execute a N1QL query. This also creates the primary index which should
 * be executed only once.
 * If you try to run this against an older cluster (e.g. 3.0.x) you will get
 * an LCB_NOT_SUPPORTED error (Operation not supported).
 * Compile and link with couchbase (-lcouchbase). This requires libcouchbase
 * version 2.4.8 or greater
 * This file uses the "V3" API (<libcouchbase/api3.h>)
 * First argument is a _connection string_, e.g. couchbase://localhost/default

I run it against travel-sample.

The index is created just fine, but the lcb_wait(instance) call, which is the third-to-last line in the program, segfaults.

The gdb backtrace is:

 #0  0x00007ffab2ef25b6 in __memcpy_ssse3_back () from /lib64/
 #1  0x00007ffab3176ea4 in memcpy (__len=4294967295, __src=0x7ffab31ac6b4, __dest=<optimized out>) at /usr/include/bits/string3.h:51
 #2  lcb_string_append (str=str@entry=0x1911988, data=0x7ffab31ac6b4, size=4294967295) at /usr/src/debug/libcouchbase-2.5.1/src/simplestring.c:104
 #3  0x00007ffab3176f8e in lcb_string_appendv (str=str@entry=0x1911988) at /usr/src/debug/libcouchbase-2.5.1/src/simplestring.c:134
 #4  0x00007ffab31924da in finalize_field (params=params@entry=0x1911940, field=field@entry=0x7ffab31ac6cf "args", term=term@entry=0x7ffab31a74e9 "]", ss=0x1911940, ss=0x1911940)
    at /usr/src/debug/libcouchbase-2.5.1/src/n1ql/params.c:183
 #5  0x00007ffab319276d in lcb_n1p_encode (params=params@entry=0x1911940, err=err@entry=0x7fff48293314) at /usr/src/debug/libcouchbase-2.5.1/src/n1ql/params.c:219
 #6  0x00007ffab31928fe in lcb_n1p_mkcmd (params=0x1911940, cmd=0x7fff48293360) at /usr/src/debug/libcouchbase-2.5.1/src/n1ql/params.c:268
 #7  0x0000000000400e63 in cb_store (instance=0x19050a0, cbtype=2, rb=0x7fff482933f0) at example.c:72
 #8  0x00007ffab3196f99 in H_store (immerr=LCB_SUCCESS, response=0x7fff48293520, request=0x191b3d0, pipeline=0x1925f90) at /usr/src/debug/libcouchbase-2.5.1/src/handler.c:437
 #9  mcreq_dispatch_response (pipeline=pipeline@entry=0x1925f90, req=req@entry=0x191b3d0, res=res@entry=0x7fff48293520, immerr=immerr@entry=LCB_SUCCESS) at /usr/src/debug/libcouchbase-2.5.1/src/handler.c:617
 #10 0x00007ffab319e9bf in try_read (ior=0x191b2b8, server=0x1925f90, ctx=0x191b270) at /usr/src/debug/libcouchbase-2.5.1/src/mcserver/mcserver.c:259
 #11 on_read (ctx=0x191b270, nb=<optimized out>) at /usr/src/debug/libcouchbase-2.5.1/src/mcserver/mcserver.c:300
 #12 0x00007ffab3182418 in invoke_read_cb (nb=<optimized out>, ctx=0x191b270) at /usr/src/debug/libcouchbase-2.5.1/src/lcbio/ctx.c:273
 #13 E_handler (sock=<optimized out>, which=<optimized out>, arg=0x191b270) at /usr/src/debug/libcouchbase-2.5.1/src/lcbio/ctx.c:290
 #14 0x00007ffab01bc3a4 in event_base_loop () from /lib64/  
 #15 0x00007ffab31a2857 in lcb_wait (instance=0x19050a0) at /usr/src/debug/libcouchbase-2.5.1/src/wait.c:108
 #16 0x000000000040114d in main (argc=1, argv=0x7fff48293978) at example.c:147

I’d suggest for the time being to manually encode the REST API parameters. This involves manually encoding the JSON parameters, however. The REST API can be found here:

I’ll update the docs a bit later with an example of this.

The N1QLPARAMS API will likely be removed in a future release.