gpt4 book ai didi

c - ocilib 的稳定性如何

转载 作者:行者123 更新时间:2023-11-30 17:38:23 24 4
gpt4 key购买 nike

我有这段代码,它使用 OCIlib:

int HoleInstrumentenDiffListeDB(GTree *tree)
{

OCI_Connection* cn;
OCI_Statement* st;
OCI_Resultset* rs;
if (!OCI_Initialize(err_handler, NULL, OCI_ENV_DEFAULT))
return EXIT_FAILURE;
char query[500];
query[0] ='\0';
cn = OCI_ConnectionCreate( "db", "user", "pass", OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);
strcat(query, "SELECT...");
OCI_ExecuteStmt(st, query);
rs = OCI_GetResultset(st);
int i = 1;
int j = 0;
char *symbolp;
while (OCI_FetchNext(rs)){

const char * symbolp = OCI_GetString(rs,2);
switch ( * OCI_GetString(rs,3))
{
case 'N':
insertQot(tree, symbolp, OCI_GetInt(rs, 1) );
printf("new \n");
break;
case 'U':
insertQot(tree, symbolp, OCI_GetInt(rs, 1) );
printf("upd \n");
break;
case 'D':
deleteQot(tree, symbolp);
printf("del \n");
break;
}
}
OCI_Cleanup();
return 1;
}

连接已建立,选择似乎有效。但是在用 valgrind 检查时我收到了很多错误。这里有一些:

==21085== Source and destination overlap in memcpy(0x742dc80, 0x742dc80, 1)
==21085== at 0x4A24F66: _intel_fast_memcpy (mc_replace_strmem.c:894)
==21085== by 0x562E6D7: kpufprow (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x562BFDE: kpufch0 (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x562ACB6: kpufch (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5520A2F: OCIStmtFetch2 (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x4CDAF6E: OCI_FetchData (resultset.c:506)
==21085== by 0x4CDB405: OCI_FetchNext (resultset.c:1117)
==21085== by 0x401B95: HoleInstrumentenDiffListeDB (unzipper_m.c:221)
==21085== by 0x402AA9: main (unzipper_m.c:691)


==21085== Conditional jump or move depends on uninitialised value(s)
==21085== at 0x5EC79DF: slpmloclfv (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EC771E: slpmloc (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EC4C44: lpmloadpkg (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EAAA8E: lfvLoadPkg (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EAA719: lfvSetShlMode (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EAA518: lfvini1 (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5EAA234: lfvinit (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5ACD1C9: kpummpin (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x547EED8: kpuenvcr (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x551FCD5: OCIEnvCreate (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x4CE311B: OCI_Initialize (library.c:1140)
==21085== by 0x401942: HoleInstrumentenDiffListeDB (unzipper_m.c:207)



==21085== Use of uninitialised value of size 8
==21085== at 0x56DFE05: ztceadecbk (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x56DC6BC: ztceb_decblk (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x56DC3BE: ztcebf (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x56DBB8A: ztcef (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x56DBC6E: ztcedec (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x57341A3: ztvo5ed (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x5734FA5: ztvo5ver (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x54C899D: kpu8lgn (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x54C649C: kpuauthxa (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x54C5EA5: kpuauth (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x551FF1A: OCISessionBegin (in /opt/oracle/product/10.2/lib/libclntsh.so.10.1)
==21085== by 0x4CD45EA: OCI_ConnectionLogon (connection.c:598)

我可以改进我的代码吗?如果不是 - 保持原样有多安全?

最佳答案

首先,您应该为每个应用程序调用 OCI_Initialize() 和 OCI_Cleanup() 一次,并且最好是从主线程调用一次。

关于您拥有的 Valgrind 跟踪,您可以看到它涉及 Oracle 提供的 Oracle 客户端共享库的内部代码。使用纯 OCI 代码编码的应用程序也会得到同样的效果。这些跟踪与构建在 OCI 之上的 OCILIB 代码无关。

创建一个仅调用 OCI 调用 OCIEnvCreate() 的应用程序并查看 Valgrind 跟踪。你也会有类似的痕迹。

问候,

文森特

关于c - ocilib 的稳定性如何,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22151847/

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