'Stack-Based Overflow Error(strcpy and strncpy)
I have the below code, where the compiler is complaining:
int len = strlen(prgpath);
char* ptr = strrchr(prgpath, '/');
char prgname[64];
memset(prgname, 0, sizeof(prgname));
if (ptr==NULL)
strcpy(prgname, prgpath);
else
strncpy(prgname, (ptr+1), len-(ptr-prgpath));
Compiler gives the below warning:
"This call to strcpy() and strncpy() contains a buffer overflow. The source string
has an allocated size of (unavailable) bytes, and the destination buffer is 64
bytes."
How should I replace the above "strcpy" and "strncpy" to resolve the warning. Should I use strlcpy or any other API's present?
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
