470,848 Members | 1,610 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,848 developers. It's quick & easy.

Bad Access - Memory Problem?

Hello everyone. I have been spending a few hours on this problem,
reading man pages on strlen and such. Anway, I have the following
function:

void XSendData(char *dataToSend, int socketID) {

// Send the data out.
send(socketID, dataToSend, strlen(dataToSend), XZERO);

}

It works, but not when I pass an integer. Example:

int theNum = 3;
XSendData((char*)theNum, outSocket);

Thats when it crashes. When I run debug it points that strlen is what
reported an EXE_BAD_ACCESS.

What am I doing wrong?

Thanks for your help.

Apr 9 '06 #1
4 2177
I forgot to mention that during debug it showed that dataToSend was
empty.

Apr 9 '06 #2
ca****@gmail.com wrote:
I forgot to mention that during debug it showed that dataToSend was
empty.

Answered on comp.unix.programmer.

--
Ian Collins.
Apr 9 '06 #3
ca****@gmail.com wrote:
Hello everyone. I have been spending a few hours on this problem,
reading man pages on strlen and such. Anway, I have the following
function:

void XSendData(char *dataToSend, int socketID) {

// Send the data out.
send(socketID, dataToSend, strlen(dataToSend), XZERO);

}

It works, but not when I pass an integer. Example:

int theNum = 3;
XSendData((char*)theNum, outSocket);

Thats when it crashes. When I run debug it points that strlen is what
reported an EXE_BAD_ACCESS.

What am I doing wrong?

Thanks for your help.

XSendData() does not accept the length of the buffer to read; it
calculates it in assumption it is given a pointer to a zero-terminated C
string as its 1st argument. In the code, it is passed an integer, which
is not even an pointer at all; but it is coerced to pointer.. and it
probably points to (probably some very intimate on your system) area at
0x03.. trying to ACCESS this area, even if only for reading is usually BAD.
Apr 9 '06 #4
Doh! I see it now.

Thanks.

Apr 10 '06 #5

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Allen | last post: by
12 posts views Thread by James Brown | last post: by
14 posts views Thread by Greg Copeland | last post: by
10 posts views Thread by WannaKatana | last post: by
8 posts views Thread by Gerhard Fiedler | last post: by
39 posts views Thread by Martin | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.