473,385 Members | 2,044 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Using mysqlclient library -- odd crash

The code is pasted to the following site:

http://www.rafb.net/paste/results/4Po5gU24.html

Basically, i just wrote wrappers to some mysqclient calls, they all work fine
except when im about to return from main, my stack seems messed up and main
tries to return to 0x00000 and i get a segfault.

I'm compiling with
gcc data.c -c
gcc test.c data.o -lmysqlclient -lz -o t
sl*****@hotmail.com

thanks
Nov 14 '05 #1
2 1715
sl*****@hotmail.com (ZER0K3WL) wrote:
The code is pasted to the following site:

http://www.rafb.net/paste/results/4Po5gU24.html

Basically, i just wrote wrappers to some mysqclient calls, they all work fine
except when im about to return from main, my stack seems messed up and main
tries to return to 0x00000 and i get a segfault.
I don't see anything obviously wrong with your code, maybe you could
post it to a MySQL discussion forum.

You could try and reduce your code to the minimum possible code
that gives the error, this is often a good way of finding bugs.
For example, start with a program that just calls the mysql
functions with fixed strings, and if that works, add in code
slowly, working towards the current situation.

Also since you have symptoms of a memory error, you could try
running a program like 'valgrind' to check for memory leaks
or out-of-bounds accesses. What compiler do you use?

There are 2 odd things in your code: you don't check the return
value of db_init() (if it was NULL then you might get that symptom),
and this code:
char *query;
query = malloc((sizeof(char) *
(strlen(table) + strlen(values) + 32)));
sizeof(char) is always 1, so you can omit it.
You should also check the return value of malloc.
sprintf(query, "INSERT INTO %s VALUES(%s)", table, values); #ifdef DEBUG printf("Adding %s to %s\n", values, table);
printf("Query is: %s\n", query);
printf("Allocated %d bytes\n", (sizeof(char) *
(strlen(table) + strlen(values) + 21)));
#endif


21 is the wrong value here, it should be 22 (21 chars + the zero
terminator). If you had written 21 instead of 32 in the malloc,
then the symptoms you're seeing would be a likely error.
Nov 14 '05 #2

"ZER0K3WL" <sl*****@hotmail.com> wrote in message
news:3b**************************@posting.google.c om...
The code is pasted to the following site:

http://www.rafb.net/paste/results/4Po5gU24.html

Basically, i just wrote wrappers to some mysqclient calls, they all work fine except when im about to return from main, my stack seems messed up and main tries to return to 0x00000 and i get a segfault.

I'm compiling with
gcc data.c -c
gcc test.c data.o -lmysqlclient -lz -o t
sl*****@hotmail.com

thanks

[OT]
see the 3rd user comment at
http://dev.mysql.com/doc/mysql/en/mysql_init.html

You can either figure our what the packing/alignment issues are
OR
if you pass in NULL to mysql_init it will allocate the structure and the you
should have no packing/aligment issues. You do however have to check the
result
to ensure it was able to allocate the structure.

[/OT]

Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Luiz Rafael Culik Guimaraes | last post by:
Dear Friends i´ve just download mysql 4.0.14 where i can find an mysqlclient.lib for borland c++compilers, the one on windows download page is for version 3.23.xx Regards Luiz
0
by: jose | last post by:
Hello. I have installed binary version for aix 5.2 and when i try to compile cyrus-sasl with mysql support it don't find mysqlclient libraries. I use --with-mysql=/usr/local/mysql/ to build but i...
2
by: Andy Fish | last post by:
Hi, I have a single-file aspx file (no codebehind). when I try to do this: <%@ Import Namespace="MySql.Data.MySqlClient" %> I get this: CS0246: The type or namespace name 'MySql' could...
0
by: nthpixel | last post by:
Hey Folks, I am getting the following errors when I try to connect to my db with the MySqlConnection. I added MySql.Data to my Reference list and have the .dll in my bin directory. I also have...
3
by: asadikhan | last post by:
Hi, I am trying to use a datalist to edit data in a MySql database as follows. For now I just want to be able to get the changes to be made on the dataset. Here is my code: using System;...
5
by: msch-prv | last post by:
Hi, I am trying to tie a SQLDataSource control to MySQL without success. The connection string works ok with an ObjectDataSource. (Native asp.net 2.0 MySQL dll loaded in /bin) For some reason,...
72
by: jacob navia | last post by:
We have discussed often the proposition from Microsoft for a safer C library. A rationale document is published here by one of the members of the design team at microsoft:...
5
by: inetquestion | last post by:
when I try to compile php-5.2.1 it gives an error about not being able to find mysqlclient and that it isn't included with mysql anymore. I've checked on the system and indeed they do not exist. ...
1
by: Carmine [www.thetotalsite.it] | last post by:
Hi, I am using ASP.Net 2.0 with the MySQL Connector .Net 5.1.2.2. I added these lines to the web.config to make the connector.net able to handle the SqlConnection object (and so to bind it to a...
14
by: Mohamed Mansour | last post by:
Hey there, this will be somewhat a long post, but any response is appreciated! I have done many PInvoke in the past from C++ to C#, but I did PInvoke within C# not C++/CLI. Can someone explain...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.