From: Derick H Siddoway Date: March 22 1999 7:36pm Subject: Re: Why the error here? List-Archive: http://lists.mysql.com/mysql/789 Message-Id: <0DDAA36F69BBBAB4*/c=us/admd=attmail/prmd=amex/o=unresolved/ou=HUB1/ou=AMEX/s=Siddoway/g=Derick/i=H/@MHS> Ah, well. I (perhaps foolishly) assumed that the problem would be with the API, not basic C. (Although I did wonder why anyone would use scanf()...) When I type it in, I don't get a segfault at all -- wonder why. -- derick From: sasha%direct1.com@Internet on 03/22/99 10:21 AM To: Derick H Siddoway/TC/TRS/American Express@AMEX cc: tom%bedell.net@Internet, mysql%lists.mysql.com@Internet Subject: Re: Why the error here? Derick H Siddoway wrote: > > You're calling mysql_free_result() on a pointer that has never > been used or initialized. That is, why call mysql_free_result() > when you've never called mysql_store_result()? > > -- > derick This segfaults though before the program gets to any of the mysql calls. sscanf will fail with a segfault as it is trying to store a string at the address of something that was supposed to be a character, and will most likely address something outside of the allowed limits > > From: tom%bedell.net@Internet on 03/21/99 08:21 PM > To: mysql%lists.mysql.com@Internet > cc: (bcc: Derick H Siddoway/TC/TRS/American Express) > Subject: Why the error here? > > Hello, > > I am trying to use: > > mysql_create_db in a C program. It compiles and links OK. But when you > execute the program, I get the following error. > > #include "mysql.h" > #include "mysql.h" > #include > #include > > MYSQL mysql; > MYSQL_RES *res; > MYSQL_ROW row; > char *db = "db"; > > void exiterr(int exitcode) > { > fprintf( stderr, "%s\n", mysql_error(&mysql) ); exit( exitcode ); > } > > main() > { > char db; > printf("Enter a name for your new database\n\n"); scanf("%s", &db); > if (!(mysql_connect(&mysql,"localhost","root",""))) exiterr(1); > if (mysql_create_db(&mysql, &db)) > exiterr(2); > > mysql_free_result(res); > mysql_close(&mysql); > } > > When I run my code here is what I get: > [root@oscar mysql_c]# ./connect > Enter a name for your new database > > homes > Segmentation fault > BUT.... The database is added to mysql. I can connect to it, and view the > "empty set". Why the segmentation fault??? > Thank you in andvance. > > Tom Bedell > Tom@stripped > -- Sasha Pachev http://www.sashanet.com/ (home) http://www.direct1.com/ (work)