aboutsummaryrefslogtreecommitdiff
path: root/src/fs.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/fs.c')
-rw-r--r--src/fs.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/src/fs.c b/src/fs.c
index 3b450e8..77b34ee 100644
--- a/src/fs.c
+++ b/src/fs.c
@@ -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;