Skip to content

Commit 4808ef7

Browse files
committed
small rewrite of PR #505
1 parent babe57a commit 4808ef7

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

src/options.c

Lines changed: 11 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -415,26 +415,24 @@ void _mi_error_message(int err, const char* fmt, ...) {
415415
// --------------------------------------------------------
416416

417417
static void mi_strlcpy(char* dest, const char* src, size_t dest_size) {
418-
if (dest_size == 0)
419-
return;
420-
421-
// Copy until end of 'src' or dest is (almost) full
422-
while (*src && (dest_size > 1)) {
418+
if (dest==NULL || src==NULL || dest_size == 0) return;
419+
// copy until end of src, or when dest is (almost) full
420+
while (*src != 0 && dest_size > 1) {
423421
*dest++ = *src++;
424-
--dest_size;
422+
dest_size--;
425423
}
426-
// Null-terminate dest
424+
// always zero terminate
427425
*dest = 0;
428426
}
429427

430428
static void mi_strlcat(char* dest, const char* src, size_t dest_size) {
431-
// Skip existing data in 'dest'
432-
while (*dest && (dest_size > 1)) {
433-
++dest;
434-
--dest_size;
429+
if (dest==NULL || src==NULL || dest_size == 0) return;
430+
// find end of string in the dest buffer
431+
while (*dest != 0 && dest_size > 1) {
432+
dest++;
433+
dest_size--;
435434
}
436-
437-
// Concatenate src
435+
// and catenate
438436
mi_strlcpy(dest, src, dest_size);
439437
}
440438

0 commit comments

Comments
 (0)