Fix crash in c_vsnprintf

PUBLISHED_FROM=020d1b9ea66862f71b08232b827cdd6e97528765
This commit is contained in:
Alexander Alashkin 2016-02-11 16:13:14 +01:00 committed by rojer
parent 96c023df41
commit 148e1926e8

View File

@ -1773,9 +1773,12 @@ int c_vsnprintf(char *buf, size_t buf_size, const char *fmt, va_list ap) {
C_SNPRINTF_APPEND_CHAR(' ');
}
/* Ignore negative and 0 precisions */
for (j = 0; (precision <= 0 || j < precision) && s[j] != '\0'; j++) {
C_SNPRINTF_APPEND_CHAR(s[j]);
/* `s` may be NULL in case of %.*s */
if (s != NULL) {
/* Ignore negative and 0 precisions */
for (j = 0; (precision <= 0 || j < precision) && s[j] != '\0'; j++) {
C_SNPRINTF_APPEND_CHAR(s[j]);
}
}
} else if (ch == 'c') {
ch = va_arg(ap, int); /* Always fetch parameter */