LibC: Make sure FILE's buffer does not get overflown

This commit is contained in:
Bananymous 2025-08-26 15:26:06 +03:00
parent c6946d0145
commit 32afa33a06
1 changed files with 6 additions and 0 deletions

View File

@ -779,11 +779,17 @@ int putc_unlocked(int c, FILE* file)
return (unsigned char)c;
}
if (file->buffer_idx >= file->buffer_size)
if (fflush(file) == EOF)
return EOF;
file->buffer[file->buffer_idx] = c;
file->buffer_idx++;
if ((file->buffer_type == _IOLBF && c == '\n') || file->buffer_idx >= file->buffer_size)
if (fflush(file) == EOF)
return EOF;
return (unsigned char)c;
}