KxSystems / kdb

Companion files to kdb+ and q
https://code.kx.com/q
Apache License 2.0
417 stars 162 forks source link

unary primitive type (101) cause SIGSEGV (Segmentation fault) when query result is processed in c library #30

Open tojocky opened 9 months ago

tojocky commented 9 months ago

Hi,

I found that if a query from a table where a value has unary primite type (101) then c library (c.o) ends up in Segmentation fault.

How to reproduce: create a table with a column type Char (10). insert some data where a row should contain unary primitive type (101)

create a simple C/C++ that execute the query.

I tried with the latest client version c.0 v.4.0 and it still coring. Unfortunately I cannot paste any code here.

sshanks-kx commented 5 months ago

kdb+ server

q -p 1234
q)t:([]a:("ab";"cd";(::)));

client program

#include <stdio.h>
#include "k.h"

int main(int argc,char** argv){
    K table,columns,values,col1;
    int x=0;
    int handle=khp("localhost", 1234);
    if(handle<=0){
        printf("Connect fail %d\n",handle);
        return -1;
    }
    printf("Connected\n",handle);
    table=k(handle, "select a from t", (K)0);
    if(table->t!=XT){
        printf("Not a table\n");
        return -1;
    }
    columns=kK(table->k)[0];
    values=kK(table->k)[1];
    col1=kK(values)[0];
    for(x=0;x<col1->n;x++){
        printf("Value type %d\n",kK(col1)[x]->t);
        if(kK(col1)[x]->t==KC)
            printf(" String %.*s\n",kK(col1)[x]->n,kK(col1)[x]->G0);
        else
            printf(" NULL\n");
    }
    r0(table);
    kclose(handle);
    return 1;
}

running i get

Connected
Value type 10
 String ab
Value type 10
 String cd
Value type 101
 NULL

Im not sure if this is what you meant, but doesnt crash for me. It would if I tried to print out a 101 as if it was a string. If you could clarify further if you still have an issue (or if the above causes an issue for you, which platform/version/etc).

Thanks