使用OCILIB获取数据时写入大小为1无效

时间:2014-01-13 15:58:20

标签: c

我在valgrind中运行代码时遇到Invalid write of size 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.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

我在循环中从数据库获得结果。这里标有line 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);
}

0 个答案:

没有答案
相关问题