lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 14 Apr 2021 00:41:27 -0700
From:   Michael Forney <mforney@...rney.org>
To:     linux-ext4@...r.kernel.org
Subject: [PATCH 1/2] libext2fs: use statement-expression for container_of only on GNU-compatible compilers

Functionally, the statement-expression is not necessary here; it
just gives a bit of type-safety to make sure the pointer really
does have a compatible type with the specified member of the struct.

When statement expressions are not available, we can just use a
portable fallback macro that skips this member type check.

Signed-off-by: Michael Forney <mforney@...rney.org>
---
 lib/ext2fs/compiler.h | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/ext2fs/compiler.h b/lib/ext2fs/compiler.h
index 9aa9b4ec..03c35ab8 100644
--- a/lib/ext2fs/compiler.h
+++ b/lib/ext2fs/compiler.h
@@ -14,9 +14,14 @@
 #define offsetof(TYPE, MEMBER) ((size_t) &((TYPE *)0)->MEMBER)
 #endif
 
+#ifdef __GNUC__
 #define container_of(ptr, type, member) ({			\
 	const __typeof__( ((type *)0)->member ) *__mptr = (ptr);	\
 	(type *)( (char *)__mptr - offsetof(type,member) );})
+#else
+#define container_of(ptr, type, member)				\
+	((type *)((char *)(ptr) - offsetof(type, member)))
+#endif
 
 
 #endif /* _EXT2FS_COMPILER_H */
-- 
2.30.1

Powered by blists - more mailing lists