使用OCILIB获取数据时大小为1的写入无效
在valgrind中运行代码时,我收到大小为1的使用OCILIB获取数据时大小为1的写入无效,c,C,在valgrind中运行代码时,我收到大小为1的无效写入错误: ==20470== Invalid write of size 1 ==20470== at 0x4E7213F: _IO_default_xsputn (in /lib64/libc-2.4.so) ==20470== by 0x4E4A666: vfprintf (in /lib64/libc-2.4.so) ==20470== by 0x4E67B08: vsprintf (in /lib64/libc-2.
无效写入错误:
==20470== Invalid write of size 1
==20470== at 0x4E7213F: _IO_default_xsputn (in /lib64/libc-2.4.so)
==20470== by 0x4E4A666: vfprintf (in /lib64/libc-2.4.so)
==20470== by 0x4E67B08: vsprintf (in /lib64/libc-2.4.so)
==20470== by 0x4E52637: sprintf (in /lib64/libc-2.4.so)
==20470== by 0x402875: buildQotHash (c4.c:180)
==20470== by 0x403695: main (c4.c:469)
==20470== Address 0xffefe1b73 is on thread 1's stack
我正在从循环中的数据库中获取结果。此处是带有标记的第180行的代码段,这会导致错误:
int buildQotHash(GTree* tree, char (*str)[3000])
{
OCI_ExecuteStmt(st, query);
rs = OCI_GetResultset(st);
int i = 1;
int j = 0;
while (OCI_FetchNext(rs))
{
const gchar *tri = OCI_GetString (rs, 1);
printf("%s " , tri);
sprintf(str[j]+strlen(str[j]),"&ik%d=%s", i, tri);//<-- here is line 180
i > 99 ? j++ : j;
i++;
if(i > 100) i = 1;
}
}
int main ( void ) {
char subStr[8][3000]={"","","","","","","",""};
buildQotHash(t, subStr);
}
intbuildqothash(GTree*tree,char(*str)[3000])
{
OCI_ExecuteStmt(st,查询);
rs=OCI_GetResultset(st);
int i=1;
int j=0;
而(保监处)
{
const gchar*tri=OCI_GetString(rs,1);
printf(“%s”,tri);
sprintf(str[j]+strlen(str[j]),“&ik%d=%s”,i,tri);//99?j++:j;
i++;
如果(i>100)i=1;
}
}
内部主(空){
char subStr[8][3000]={“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”、“”};
buildQotHash(t,subStr);
}
哪里定义了str
?我添加了遗漏的信息。您在哪里扩展str[j]
指向的存储以容纳sprintf()添加的其他字符?或者,如果在原始分配时间占用了可用空间,您是否确定strlen(str[j])+strlen(format\u string\u with\u variables\u expanded)
不会超过预分配的存储空间?您似乎在未初始化的字符数组中使用strlen()。你希望带着这个回来干什么?@nikpel7:这个可能就是那个。让我查一查。