Re: I confirmed ONE problem - not sure how to fix it though.
Re: I confirmed ONE problem - not sure how to fix it though.
- Subject: Re: I confirmed ONE problem - not sure how to fix it though.
- From: John Draper <email@hidden>
- Date: Wed, 05 Apr 2006 22:45:06 -0700
Prachi Gauriar wrote:
On Apr 5, 2006, at 10:48 AM, Sean McBride wrote:
On 2006-04-05 01:15, John Draper said:
void
infoServer::setExtIP(char *ip)
{
if (m_MyExtIP == NULL) {
m_MyExtIP = new char(100);
}
strcpy(m_MyExtIP, ip); <---- This causes the crash. The
size of
the string is 16 bytes
}
In addition to what others have said, I would recommend you never never
never use strcpy(), use strncpy() instead, it takes a length parameter.
Though it may not have helped you here, it is good practice. You will
be less likely to have buffer overruns.
Actually, strncpy isn't ideal either because it doesn't necessarily
null-terminate the destination string. One of the big problems with
the C string functions is that the "n" used means different things to
different functions. If you're just deploying on Mac or BSD-based
platforms, it's better to use strlcpy, which always null-terminates
the destination. The "l" is the length of the buffer (including
space for the null character).
So - if I'm maxing it out to 100 bytes, I would use 101 for the length?
John
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Xcode-users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden