]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/: strerrno(): Use statement expression to perform lvalue conversion
authorAlejandro Colomar <alx@kernel.org>
Tue, 25 Nov 2025 21:51:28 +0000 (22:51 +0100)
committerSerge Hallyn <serge@hallyn.com>
Fri, 28 Nov 2025 03:26:49 +0000 (21:26 -0600)
Compound literals are lvalues.  This means it's possible to take their
address.  That is, it would be possible (albeit nonsensical) to do

&strerrno();

It is also possible to assign to them (albeit also nonsensical):

strerrno() = NULL;

The statement expression performs lvalue conversion, which turns the
lvalue into an "rvalue", as expected, and disallows all those issues.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/strerrno.h

index b82e1015c4a578c35e5ebff335cc04ca35c12607..9f28a86a492d55b29f36d641a7c3db9a9337051c 100644 (file)
@@ -13,7 +13,7 @@
 
 
 // strerrno - string errno
-#define strerrno()  ((const char *){strerror(errno)})
+#define strerrno()  ({(const char *){strerror(errno)};})
 
 
 #endif  // include guard