pespin has uploaded this change for review. (
https://gerrit.osmocom.org/c/libosmocore/+/34042 )
Change subject: sockaddr_str: Introduce macro OSMO_SOCKADDR_STR_FMT_ARGS_NOT_NULL
......................................................................
sockaddr_str: Introduce macro OSMO_SOCKADDR_STR_FMT_ARGS_NOT_NULL
Under certain cases, gcc version 13.1.1 20230714 catches the fact that
the pointer being passed cannot be null, (eg local variable struct
osmo_sockaddr_str addr_str passed as &addr_str), and errors about
checking nullability of a pointer which cannot be null.
"""
/include/osmocom/core/sockaddr_str.h:63:10: error: the address of 'addr_str' will
always evaluate as 'true' [-Werror=address]
63 | ((R) && (R)->af == AF_INET6)? "[" : "", \
| ^
"""
Let's add a macro which can be used for pointers known to be there (tbh,
I'd expect that to be the usual case in most code paths). Using this new
macro should be more optimal in those cases, and avoid gcc erroring.
Change-Id: I59c7b05450cb463d2e87ddb022f0b6ba7109d398
---
M include/osmocom/core/sockaddr_str.h
1 file changed, 33 insertions(+), 4 deletions(-)
git pull ssh://gerrit.osmocom.org:29418/libosmocore refs/changes/42/34042/1
diff --git a/include/osmocom/core/sockaddr_str.h b/include/osmocom/core/sockaddr_str.h
index f474fa0..2d3e7e9 100644
--- a/include/osmocom/core/sockaddr_str.h
+++ b/include/osmocom/core/sockaddr_str.h
@@ -59,11 +59,16 @@
* printf("got " OSMO_SOCKADDR_STR_FMT "\n",
OSMO_SOCKADDR_STR_FMT_ARGS(my_sockaddr_str));
*/
#define OSMO_SOCKADDR_STR_FMT "%s%s%s:%u"
+#define OSMO_SOCKADDR_STR_FMT_ARGS_NOT_NULL(R) \
+ ((R)->af == AF_INET6) ? "[" : "", \
+ (R)->ip, \
+ ((R)->af == AF_INET6) ? "]" : "", \
+ (R)->port : 0
#define OSMO_SOCKADDR_STR_FMT_ARGS(R) \
- ((R) && (R)->af == AF_INET6)? "[" : "", \
- (R)? (R)->ip : "NULL", \
- ((R) && (R)->af == AF_INET6)? "]" : "", \
- (R)? (R)->port : 0
+ ((R) && (R)->af == AF_INET6) ? "[" : "", \
+ (R) ? (R)->ip : "NULL", \
+ ((R) && (R)->af == AF_INET6) ? "]" : "", \
+ (R) ? (R)->port : 0
bool osmo_sockaddr_str_is_set(const struct osmo_sockaddr_str *sockaddr_str);
bool osmo_sockaddr_str_is_nonzero(const struct osmo_sockaddr_str *sockaddr_str);
--
To view, visit
https://gerrit.osmocom.org/c/libosmocore/+/34042
To unsubscribe, or for help writing mail filters, visit
https://gerrit.osmocom.org/settings
Gerrit-Project: libosmocore
Gerrit-Branch: master
Gerrit-Change-Id: I59c7b05450cb463d2e87ddb022f0b6ba7109d398
Gerrit-Change-Number: 34042
Gerrit-PatchSet: 1
Gerrit-Owner: pespin <pespin(a)sysmocom.de>
Gerrit-MessageType: newchange