2 ms·
The sanest solution is, surprisingly, snprintf(dst, sizeof(dst), "%s", src).
by Sesse__ 2y ago
The sanest solution is, surprisingly, snprintf(dst, sizeof(dst), "%s", src).
- kragen 2y agoplease don't fill your program with fifty zillion string buffers of arbitrarily chosen sizes and then try to separately pass the right size in seventy zillion string-processing function calls. your code will be hard to read, buggy, and probably insecure
- Sesse__ 2y agoI agree with that statement, but it has nothing to do with snprintf() versus e.g. strcpy_s(), where you have exactly the same requirement to pass the right size. (Separately, there's a discussion about how many bytes you are allowed to read from the _source_, but to fix that, you need something like the Linux kernel's strscpy(), which isn't really widely supported in userspace.)
- kragen 2y agoi agree