git » libfiu » commit 37f6a98

preload/posix: Pass an appropriate promoted type to va_arg()

author Alberto Bertogli
2010-03-21 18:43:43 UTC
committer Alberto Bertogli
2010-03-21 18:52:52 UTC
parent 1862bedc03daf55418c7a91119ee796ba72e4cb8

preload/posix: Pass an appropriate promoted type to va_arg()

va_arg() can only take a promoted type, which that means just an int in this
case.

On some platforms passing mode_t works, but on others (like Debian's kFreeBSD
amd64) causes a compile-time warning and a run-time error, as reported by
Serafeim Zanikolas on Debian bug 574752.

This patch fixes this by passing int as the argument to va_arg(), instead of
mode_t.

It also fixes the "mode" variable's type, which was int when it should have
been mode_t.

Signed-off-by: Alberto Bertogli <albertito@blitiri.com.ar>

preload/posix/modules/posix.custom.c +9 -2

diff --git a/preload/posix/modules/posix.custom.c b/preload/posix/modules/posix.custom.c
index 5caff6f..1c709cd 100644
--- a/preload/posix/modules/posix.custom.c
+++ b/preload/posix/modules/posix.custom.c
@@ -37,12 +37,19 @@ int open(const char *pathname, int flags, ...)
 
 	/* Differences from the generated code begin here */
 
-	int mode;
+	mode_t mode;
 	va_list l;
 
 	if (flags & O_CREAT) {
 		va_start(l, flags);
-		mode = va_arg(l, mode_t);
+
+		/* va_arg() can only take fully promoted types, and mode_t
+		 * sometimes is smaller than an int, so we should always pass
+		 * int to it, and not mode_t. Not doing so would may result in
+		 * a compile-time warning and run-time error. We asume that it
+		 * is never bigger than an int, which holds in practise. */
+		mode = va_arg(l, int);
+
 		va_end(l);
 	} else {
 		/* set it to 0, it's ignored anyway */