diff options
Diffstat (limited to 'src/fs.c')
| -rw-r--r-- | src/fs.c | 10 |
1 files changed, 7 insertions, 3 deletions
@@ -829,10 +829,14 @@ uint8_t *pw_fs_write(struct pw_fs *fs, pw_fd fd, uint32_t len) { w->capacity = capacity; } + // We cannot know for sure that the caller will actually write the + // data to the buffer, which means that it is possible for us to sync + // uninitialized malloc data which would be undefined behaviour. To + // prevent this, always clear the new portions of the buffer. Note that // POSIX requires holes to be filled with 0s (in case the file was - // seeked past the end). - if (s->pos > w->size) { - SDL_memset(w->data + w->size, 0, s->pos - w->size); + // seeked past the end), so we satisfy that as well. + if (end > w->size) { + SDL_memset(w->data + w->size, 0, end - w->size); } uint8_t *buffer = w->data + s->pos; |
