Hi! I have the following source code which seems to compile fine without any errors, however when I try to execute the binary, I get a core dump. The strace output doesn't lead me to think of any foul play.. so I wonder what can be wrong and hence this post directed to you experts![]()
I have reason to believe the error lies in the sprintf function I am using... however I dont quite see why ? Any help would be most appreciated. Kind regrards, ChrisCode:root@chris-desktop:~# gcc my.c -o my -L/usr/mysql/lib -lmysqlclient -lz -ldl root@chris-desktop:~# root@chris-desktop:~# ./my Segmentation fault (core dumped) root@chris-desktop:~#
Code:#include <stdio.h> #include <mysql/mysql.h> #include <pwd.h> int main (int argc, char **argv) { MYSQL *conn; conn = mysql_init (NULL); struct passwd *pwd_ent; #define def_host_name "localhost" /* host to connect to */ #define def_user_name "root" /* user name */ #define def_password "" /* password */ #define def_db_name "history" /* database to use */ if (mysql_real_connect ( conn, /* pointer to connection handler */ def_host_name, /* host to connect to */ def_user_name, /* user name */ def_password, /* password */ def_db_name, /* database to use */ 0, /* port (use default) */ NULL, /* socket (use default) */ 0) /* flags (none) */ == NULL) { fprintf (stderr, "mysql_real_connect() failed:\nError %u (%s)\n", mysql_errno (conn), mysql_error (conn)); } char query[1000]; sprintf(query,"insert into history values('',curdate(),curtime(),'%d','%d','%s','%s')",pwd_ent->pw_uid,pwd_ent->pw_gid,pwd_ent->pw_name,""); /* End Modifications */ }



LinkBack URL
About LinkBacks



