|
-
December 23rd, 2002, 01:29 AM
#1
Member
C Buffer Overruns
Just a quick comment about how to avoid a buffer overrun while programming in C. Instead of using the string copy command, try to use the string n command.
For instance:
char *strncpy(char *dst, char *src, unsigned n)
{
for(unsigned i = 0; i < ; i++)
{
*(dst++) = *(src++);
if(*(dst-1) == '\0')
break;
}
return src;
}
This should truncate a long string.
Pardon me if there are any code error's, it's been a long day.
sgx
--Aku. Soku. Zan.--
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
|