C语言操作Mysql 插入操作是发生Core dump

jhg1204 2014-04-05 12:01:16
将数据插入到数据库时Core Dump
错误提示:
insert data successfully
*** stack smashing detected ***: ./server terminated
Segmentation fault (core dumped)


源代码:

int insert(MYSQL *conn_ptr, TRANFER_DATA data)
{
char sql[100];
memset(sql, 0, sizeof(sql));
sprintf(sql, "INSERT INTO USER_POSITION_INFO(telnum, imei, longitude, latitude, time) VALUES \
('%s', '%s', %f, %f, '%s')", data.telnum, data.imei, data.longitude, data.latitude, data.time);

if (mysql_query(conn_ptr, sql) != 0)
{
fprintf(stderr, "occur a errno: %s\n", mysql_error(conn_ptr));
return EXIT_FAILURE;
}

printf("insert data successfully\n");

return EXIT_SUCCESS;
}



各位前辈帮忙看看是怎么回事?调试了很久都没找到错误!
gdb调试结果:

gdb ./server core
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/freeman/Desktop/graduation project/Server/server...done.
[New LWP 6425]
[New LWP 6415]

warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7f4e1afa5000
Core was generated by `./server'.
Program terminated with signal 11, Segmentation fault.
#0 0x00007f4e19143066 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
(gdb) run ./server
Starting program: /home/freeman/Desktop/graduation project/Server/server ./server
warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7ffff7ffa000
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".
[New Thread 0x7ffff6b9f700 (LWP 6488)]
[Thread 0x7ffff6b9f700 (LWP 6488) exited]
connection success!
server is running...
runa client connected...
[New Thread 0x7ffff6b9f700 (LWP 6489)]
insert data successfully
*** stack smashing detected ***: /home/freeman/Desktop/graduation project/Server/server terminated

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7ffff6b9f700 (LWP 6489)]
0x00007ffff6198066 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1



core文件的查看结果:

$ gdb -c core ./server
GNU gdb (Ubuntu/Linaro 7.4-2012.04-0ubuntu2.1) 7.4-2012.04
Copyright (C) 2012 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://bugs.launchpad.net/gdb-linaro/>...
Reading symbols from /home/freeman/Desktop/graduation project/Server/server...done.
[New LWP 6425]
[New LWP 6415]

warning: Can't read pathname for load map: Input/output error.
[Thread debugging using libthread_db enabled]
Using host libthread_db library "/lib/x86_64-linux-gnu/libthread_db.so.1".

warning: no loadable sections found in added symbol-file system-supplied DSO at 0x7f4e1afa5000
Core was generated by `./server'.
Program terminated with signal 11, Segmentation fault.
#0 0x00007f4e19143066 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
(gdb) where
#0 0x00007f4e19143066 in ?? () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#1 0x00007f4e19143d7d in _Unwind_Backtrace () from /lib/x86_64-linux-gnu/libgcc_s.so.1
#2 0x00007f4e1a58a108 in backtrace () from /lib/x86_64-linux-gnu/libc.so.6
#3 0x00007f4e1a4f33af in ?? () from /lib/x86_64-linux-gnu/libc.so.6
#4 0x00007f4e1a589f47 in __fortify_fail () from /lib/x86_64-linux-gnu/libc.so.6
#5 0x00007f4e1a589f10 in __stack_chk_fail () from /lib/x86_64-linux-gnu/libc.so.6
#6 0x000000000040196e in insert (conn_ptr=0x603140, data=...) at db_operator.c:49
#7 0x36352e373231202c in ?? ()
#8 0x3233202c33303034 in ?? ()
#9 0x2c3030303935312e in ?? ()
#10 0x302d343130322720 in ?? ()
#11 0x3a35312031302d34 in ?? ()
#12 0x00292733323a3432 in ?? ()
#13 0x4200a2d142ff20c5 in ?? ()
#14 0x2d34302d34313032 in ?? ()
#15 0x34323a3531203130 in ?? ()
#16 0x000000000033323a in ?? ()
#17 0x00007f4e1afa89d8 in _rtld_global () from /lib64/ld-linux-x86-64.so.2
#18 0xffffffffffffffff in ?? ()
#19 0x00007ffffb3fc074 in ?? ()
#20 0x0000000000000000 in ?? ()

...全文
320 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
yiyefangzhou24 2014-04-07
  • 打赏
  • 举报
回复
你直接return 1好了,看一下那个sql的字符串数组是不是越界了,看着像
jhg1204 2014-04-07
  • 打赏
  • 举报
回复
引用 4 楼 yiyefangzhou24 的回复:
你直接return 1好了,看一下那个sql的字符串数组是不是越界了,看着像
非常感谢~果然是数组开小了,越界了。这个问题困扰两天了,一直没注意这个问题。
yiyefangzhou24 2014-04-05
  • 打赏
  • 举报
回复
程序上貌似看不出什么问题,连接什么都正常吗?
jhg1204 2014-04-05
  • 打赏
  • 举报
回复
在线等啊!各位前辈帮忙看看啊。。。
jhg1204 2014-04-05
  • 打赏
  • 举报
回复
引用 1 楼 yiyefangzhou24 的回复:
程序上貌似看不出什么问题,连接什么都正常吗?
数据库连接正常,数据都插入到数据库了,貌似就是在return的时候崩掉了。。。

3,881

社区成员

发帖
与我相关
我的任务
社区描述
C/C++ 其它技术问题
社区管理员
  • 其它技术问题社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧