Merge pull request #505 from res2k/fix-mi_strlcat

Replace mi_strlcpy() and mi_strlcat() with versions written from scratch
This commit is contained in:
Daan 2021-12-19 09:52:09 -08:00 committed by GitHub
commit 625c3f3eaa
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -400,14 +400,27 @@ void _mi_error_message(int err, const char* fmt, ...) {
// --------------------------------------------------------
static void mi_strlcpy(char* dest, const char* src, size_t dest_size) {
dest[0] = 0;
strncpy(dest, src, dest_size - 1);
dest[dest_size - 1] = 0;
if (dest_size == 0)
return;
// Copy until end of 'src' or dest is (almost) full
while (*src && (dest_size > 1)) {
*dest++ = *src++;
--dest_size;
}
// Null-terminate dest
*dest = 0;
}
static void mi_strlcat(char* dest, const char* src, size_t dest_size) {
strncat(dest, src, dest_size - 1);
dest[dest_size - 1] = 0;
// Skip existing data in 'dest'
while (*dest && (dest_size > 1)) {
++dest;
--dest_size;
}
// Concatenate src
mi_strlcpy(dest, src, dest_size);
}
#ifdef MI_NO_GETENV