1
0
Fork 0

Memory overrun and C++11 updates

- Limit write length into buffer, and add comment about corner-case
- Use C++11's syntax to explicitly remove private copy and assignment operators
- Use C++11 container loop syntax to shorting a cleanup function
This commit is contained in:
krcroft 2019-12-07 09:36:37 -08:00 committed by Patryk Obara
parent 959417f6de
commit 8c6758c8d1
3 changed files with 56 additions and 47 deletions

View file

@ -51,8 +51,8 @@
template<size_t N>
char * safe_strcpy(char (& dst)[N], const char * src) noexcept {
snprintf(dst, N, "%s", src);
return & dst[0];
snprintf(dst, N, "%s", src);
return & dst[0];
}
#define safe_strncpy(a,b,n) do { strncpy((a),(b),(n)-1); (a)[(n)-1] = 0; } while (0)