From 2ca899c30deed86ff546fdc8f26c973c67696740 Mon Sep 17 00:00:00 2001
From: Mooffie <mooffie@gmail.com>
Date: Wed, 16 Mar 2016 00:22:27 +0200
Subject: [PATCH] Ticket #3617: (mc_open): handle varargs mode_t promotion
issue.
On systems where 'mode_t' is smaller than 'int', doing 'va_arg (ap, mode_t)' is
wrong because of C's "default argument promotions". GCC 4 creates crashing code
in this case.
We pick the solution described in the "va_arg" page of Gnulib's manual:
https://www.gnu.org/software/gnulib/manual/html_node/va_005farg.html
A slightly different solution is to define a PROMOTED_MODE_T macro in the
configuration stage, as demonstrated here:
https://lists.gnu.org/archive/html/bug-gnulib/2009-05/msg00231.html
(If any of the URLs above no longer works, simply search the web for the
mentioned words.)
---
lib/vfs/interface.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/lib/vfs/interface.c b/lib/vfs/interface.c
index 64acb96..f1a4171 100644
a
|
b
|
mc_open (const vfs_path_t * vpath, int flags, ...) |
200 | 200 | { |
201 | 201 | va_list ap; |
202 | 202 | va_start (ap, flags); |
203 | | mode = va_arg (ap, mode_t); |
| 203 | /* Handle varargs mode_t promotion issue. See the "va_arg" page of Gnulib's manual. */ |
| 204 | if (sizeof (mode_t) < sizeof (int)) |
| 205 | mode = va_arg (ap, int); |
| 206 | else |
| 207 | mode = va_arg (ap, mode_t); |
204 | 208 | va_end (ap); |
205 | 209 | } |
206 | 210 | |