|
|
|
|
|
by actionfromafar
812 days ago
|
|
if you really want to use standard C string functions, use instead: int ret = snprintf(dst, sizeof dst, "%s", src);
if (ret >= n || ret < 0)
{
/* failed */
}
or as a function: bool ya_strcpy(const char* s, char* d, size_t n)
{
int cp = snprintf(d, n, "%s", s);
bool ok = cp >= 0 && cp < n;
ok ? *s = *s : 0;
return ok;
}
|
|
I think for that to possibly happen, you have to be in a locale with some character encoding in effect and snprintf is asked to print some multi-byte sequence that is invalid for that encoding.
Thus, I suspect, if you don't call that "f...f...frob my C program" function known as setlocale, it will never happen.