futils: fix undefined behavior in O_FSYNC fallback definition

The fallback definition of O_FSYNC uses `(1 << 31)`, which is undefined
behavior in C. The literal `1` is a signed int, and left-shifting into
the sign bit of a signed integer is undefined per the C standard.

This causes crashes on arm64 Linux with musl libc (which doesn't define
O_FSYNC), manifesting as:

    thread panic: left shift of 1 by 31 places cannot be represented in type 'int'

Replace with O_SYNC, which is the POSIX-standard equivalent of O_FSYNC.
Both flags have identical semantics (synchronized I/O file integrity
completion), and O_SYNC is universally available on POSIX systems.
This commit is contained in:
Chris Hoffman
2026-02-10 16:56:20 +08:00
parent 86c7738ca6
commit 554268dfbc

View File

@@ -34,7 +34,7 @@ extern int git_futils_readbuffer_fd(git_str *obj, git_file fd, size_t len);
* support these internally and they will be removed before the `open` call.
*/
#ifndef O_FSYNC
# define O_FSYNC (1 << 31)
# define O_FSYNC O_SYNC
#endif
extern int git_futils_writebuffer(