gpt4 book ai didi

c - g_tree_lookup 中的段错误

转载 作者:行者123 更新时间:2023-11-30 15:40:32 30 4
gpt4 key购买 nike

我在 g_tree_lookup() 函数中不断出现段错误。

这一行给了我一个异常(exception):

value = g_tree_lookup(tree, (gpointer *)triP);

triPtreevalue 似乎是正确的。这里回溯

(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;

}

最佳答案

第二个参数(关键)看起来很可疑;您确定它应该是“指针到指针”,即 gpointer *

注意原型(prototype)from the documentation :

gpointer g_tree_lookup(GTree *tree, gconstpointer key);

第二个参数应该只是一个常量指针,因此强制转换看起来非常可疑。

不过,您需要显示更多代码才能确定。

关于c - g_tree_lookup 中的段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20968139/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com