Anastasia Klimchuk submitted this change.

View Change


Approvals: build bot (Jenkins): Verified Thomas Heijligen: Looks good to me, approved Peter Marheine: Looks good to me, but someone else must approve
tests: Fix mode_t argument conversion for va_arg

Patch fixes the error:
error: second argument to 'va_arg' is of promotable type 'mode_t'
(aka 'unsigned short'); this va_arg has undefined behavior because
arguments will be promoted to 'int' [-Werror,-Wvarargs]

Discovered and tested on:
FreeBSD clang version 13.0.0
gcc 8.3.0 "cc 8.3 [DragonFly] Release/2019-02-22"
Also tested on:
gcc 11.3.0 "cc (Ubuntu 11.3.0-1ubuntu1~22.04) 11.3.0"

Change-Id: I95b7c8dafdf4e7664c48a952acd7f8eaedb59ba7
Signed-off-by: Anastasia Klimchuk <aklm@chromium.org>
Reviewed-on: https://review.coreboot.org/c/flashrom/+/74202
Reviewed-by: Peter Marheine <pmarheine@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Thomas Heijligen <src@posteo.de>
---
M tests/tests.c
1 file changed, 34 insertions(+), 9 deletions(-)

diff --git a/tests/tests.c b/tests/tests.c
index d296a98..159b79f 100644
--- a/tests/tests.c
+++ b/tests/tests.c
@@ -101,40 +101,40 @@
int __wrap_open(const char *pathname, int flags, ...)
{
LOG_ME;
- mode_t mode = 0;
+ int mode = 0;
if (flags & O_CREAT) {
va_list ap;
va_start(ap, flags);
- mode = va_arg(ap, mode_t);
+ mode = va_arg(ap, int);
va_end(ap);
}
- return mock_open(pathname, flags, mode);
+ return mock_open(pathname, flags, (mode_t) mode);
}

int __wrap_open64(const char *pathname, int flags, ...)
{
LOG_ME;
- mode_t mode = 0;
+ int mode = 0;
if (flags & O_CREAT) {
va_list ap;
va_start(ap, flags);
- mode = va_arg(ap, mode_t);
+ mode = va_arg(ap, int);
va_end(ap);
}
- return mock_open(pathname, flags, mode);
+ return mock_open(pathname, flags, (mode_t) mode);
}

int __wrap___open64_2(const char *pathname, int flags, ...)
{
LOG_ME;
- mode_t mode = 0;
+ int mode = 0;
if (flags & O_CREAT) {
va_list ap;
va_start(ap, flags);
- mode = va_arg(ap, mode_t);
+ mode = va_arg(ap, int);
va_end(ap);
}
- return mock_open(pathname, flags, mode);
+ return mock_open(pathname, flags, (mode_t) mode);
}

int __wrap_ioctl(int fd, unsigned long int request, ...)

To view, visit change 74202. To unsubscribe, or for help writing mail filters, visit settings.

Gerrit-Project: flashrom
Gerrit-Branch: master
Gerrit-Change-Id: I95b7c8dafdf4e7664c48a952acd7f8eaedb59ba7
Gerrit-Change-Number: 74202
Gerrit-PatchSet: 3
Gerrit-Owner: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Anastasia Klimchuk <aklm@chromium.org>
Gerrit-Reviewer: Peter Marheine <pmarheine@chromium.org>
Gerrit-Reviewer: Thomas Heijligen <src@posteo.de>
Gerrit-Reviewer: build bot (Jenkins) <no-reply@coreboot.org>
Gerrit-CC: Idwer Vollering <vidwer@gmail.com>
Gerrit-MessageType: merged