我一直在g_tree_lookup()
函数中获得段错误。
这一行给了我一个例外:
value = g_tree_lookup(tree, (gpointer *)triP);
triP
,tree
和value
似乎是正确的。这里回溯
(gdb) backtrace
#0 0x00002aaaaac10800 in ?? () from /opt/gnome/lib64/libglib-2.0.so.0
#1 0x00002aaaaac10def in g_tree_lookup () from /opt/gnome/lib64/libglib-2.0.so.0
#2 0x00000000004031ca in processXML (start=0x506011 "<I k=\"2723195,361,333\" b=\"908\""..., stop=0x51e6d6 "\n<I k=\"472672,847,814\" b=\"2216"..., tree=0x51e6c0) at c2.c:404
#3 0x000000000040375e in main () at c2.c:538
(gdb) frame 2
#2 0x00000000004031ca in processXML (start=0x506011 "<I k=\"2723195,361,333\" b=\"908\""..., stop=0x51e6d6 "\n<I k=\"472672,847,814\" b=\"2216"..., tree=0x51e6c0) at c2.c:404
404 if( p != NULL && (triP!=NULL) &&( (value = g_tree_lookup(tree, (gpointer *)triP) )!= NULL) )
(gdb) print tree
$17 = (GTree *) 0x51e6c0
(gdb) print triP
$18 = 0x5ad1f0 "2723195,361,333"
(gdb) print value
$19 = (gpointer *) 0x40331e
我插入这样的键:
const char *tri = OCI_GetString (rs, 1);
printf("%s " , tri);
g_tree_insert(tree,(gpointer *) g_strdup(tri), t);
树的创建方式如下:
typedef struct tic {
int qotId;
int excId;
char closeTs[19];
char closeSixCode[10];
double close;
double open;
double high;
double low;
double volume;
double tradeVolume;
double turnover;
double ask;
char askTs[19];
double askVolume;
double bid;
char bidTs[19];
double bidVolume;
float realClose;
char realCloseTs[19];
double kassa;
double settle;
char settleTs[19];
char zusatz;
double anzahlTicHeute;
double midPrice;
char midPriceTs[19];
char supXpressfeed[32];
char source;
char tradeType[1];
char buyer;
}tic, *ticP;
int buildQotHash(GTree* tree, char (*str)[3000])
{
OCI_Connection* cn;
OCI_Statement* st;
OCI_Resultset* rs;
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
return EXIT_FAILURE;
cn = OCI_ConnectionCreate( "db", "user", "pass", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
char query[5000];
");
// CUT QUERY
OCI_ExecuteStmt(st, query);
rs = OCI_GetResultset(st);
int i = 1;
int j = 0;
while (OCI_FetchNext(rs))
{
tic *t = malloc(sizeof(tic)) ;
t->qotId = OCI_GetInt (rs, 2);
t->close = OCI_GetFloat (rs, 3);
if (OCI_GetDate(rs, 4) != NULL) OCI_DateToText(OCI_GetDate(rs, 4), DATEFORMAT, 19, t->closeTs );
//t->closeTs = OCI_GetString (rs, 4);
t->open = OCI_GetFloat (rs, 5);
t->high = OCI_GetFloat (rs, 6);
t->low = OCI_GetFloat (rs, 7);
t->volume = OCI_GetFloat (rs, 8);
t->ask = OCI_GetFloat (rs, 9);
if (OCI_GetDate(rs, 10) != NULL) OCI_DateToText(OCI_GetDate(rs, 10), DATEFORMAT, 19, t->askTs );
t->askVolume = OCI_GetFloat (rs, 11);
t->bid = OCI_GetFloat (rs, 12);
if (OCI_GetDate(rs, 13) != NULL) OCI_DateToText(OCI_GetDate(rs, 13), DATEFORMAT, 19, t->bidTs );
t->bidVolume = OCI_GetFloat (rs, 14);
t->realClose = OCI_GetFloat (rs, 15);
if (OCI_GetDate(rs, 16) != NULL) OCI_DateToText(OCI_GetDate(rs, 16), DATEFORMAT, 19, t->realCloseTs );
//t->realCloseTs = OCI_GetString (rs, 16);
t->settle = OCI_GetFloat (rs, 17);
if (OCI_GetDate(rs, 18) != NULL) OCI_DateToText(OCI_GetDate(rs, 18), DATEFORMAT, 19, t->settleTs );
strcpy(t->tradeType, "H");
strcpy(t->closeSixCode, OCI_GetString (rs, 19));
const char *tri = OCI_GetString (rs, 1);
printf("%s " , tri);
g_tree_insert(tree,(gpointer *) g_strdup(tri), t);
sprintf(str[j]+strlen(str[j]),"&ik%d=%s", i, tri);
//i= (i > 99) ? i++ : 0;
i > 99 ? j++ : j;
i++;
if(i > 100) i = 1;
}
OCI_Cleanup();
return EXIT_SUCCESS;
}