aboutsummaryrefslogtreecommitdiff
path: root/src/fs.c
diff options
context:
space:
mode:
authorNicholas Rodrigues Lordello <[email protected]>2026-10-29 13:22:28 +0100
committerNicholas Rodrigues Lordello <[email protected]>2026-10-29 13:33:26 +0100
commit838d75bce98ca5a1f90f762e80d2aa649d4e0642 (patch)
tree06d661dd944d80632aa80a9f605a679779575dc5 /src/fs.c
parente51027a576a07ffb41b6e7d2bfc3aade6ae091d7 (diff)
Minor Fixes
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;