Skip to content

Commit 5aea030

Browse files
authored
Merge pull request #29 from daltomi/string-truncation
Fix GCC >=8.0 warning: -Wstringop-truncation
2 parents 940d074 + a598e0c commit 5aea030

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

src/main.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -623,7 +623,11 @@ im_printf(char *str, struct tm *tm,
623623
struct stat st;
624624

625625
ret[0] = '\0';
626-
strftime(strf, 4095, str, tm);
626+
627+
if (strftime(strf, 4095, str, tm) == 0) {
628+
fprintf(stderr, "strftime returned 0\n");
629+
exit(EXIT_FAILURE);
630+
}
627631

628632
for (c = strf; *c != '\0'; c++) {
629633
if (*c == '$') {
@@ -700,8 +704,11 @@ im_printf(char *str, struct tm *tm,
700704
strncat(ret, c, 1);
701705
break;
702706
}
703-
} else
704-
strncat(ret, c, 1);
707+
} else {
708+
const size_t len = strlen(ret);
709+
ret[len] = *c;
710+
ret[len + 1] = '\0';
711+
}
705712
}
706713
return gib_estrdup(ret);
707714
}

0 commit comments

Comments
 (0)