From 89ecbdcaab6ad1510a9f2058c4585ab4c17be743 Mon Sep 17 00:00:00 2001 From: Ron Yorston Date: Sat, 22 Jun 2024 17:19:28 +0100 Subject: win32: only access mode argument of open(2) if required The wrapper function 'mingw_open()' should only read the optional third argument if the 'O_CREAT' flag bit is set. Adds 16 bytes. (GitHub issue #425) --- win32/mingw.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/win32/mingw.c b/win32/mingw.c index 49e1bcfa4..6ad514ad4 100644 --- a/win32/mingw.c +++ b/win32/mingw.c @@ -239,9 +239,11 @@ int mingw_open (const char *filename, int oflags, ...) return fd; } - va_start(args, oflags); - mode = va_arg(args, int); - va_end(args); + if ((oflags & O_CREAT)) { + va_start(args, oflags); + mode = va_arg(args, int); + va_end(args); + } pmode = ((mode & S_IWUSR) ? _S_IWRITE : 0) | ((mode & S_IRUSR) ? _S_IREAD : 0); -- cgit v1.2.3-55-g6feb