From 0f9664f4177d9d5b888acef2b4492bc4f22ed920 Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Thu, 9 Jan 2020 11:48:18 +0100 Subject: [PATCH] shared: use static array indices in function parameter declarations of _nm_utils_inet[46]_ntop() This should give the compiler more possibilities to warn about wrong use of the API. In practice, my current compiler wouldn't flag any issues. However, some compilers (or compile options) might. --- shared/nm-glib-aux/nm-shared-utils.h | 4 ++-- src/nm-core-utils.c | 3 ++- src/nm-core-utils.h | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/shared/nm-glib-aux/nm-shared-utils.h b/shared/nm-glib-aux/nm-shared-utils.h index abe263c6bd..2d4054f7c2 100644 --- a/shared/nm-glib-aux/nm-shared-utils.h +++ b/shared/nm-glib-aux/nm-shared-utils.h @@ -183,13 +183,13 @@ nm_utils_inet_ntop (int addr_family, gconstpointer addr, char *dst) } static inline const char * -_nm_utils_inet4_ntop (in_addr_t addr, char *dst) +_nm_utils_inet4_ntop (in_addr_t addr, char dst[static INET_ADDRSTRLEN]) { return nm_utils_inet_ntop (AF_INET, &addr, dst); } static inline const char * -_nm_utils_inet6_ntop (const struct in6_addr *addr, char *dst) +_nm_utils_inet6_ntop (const struct in6_addr *addr, char dst[static INET6_ADDRSTRLEN]) { return nm_utils_inet_ntop (AF_INET6, addr, dst); } diff --git a/src/nm-core-utils.c b/src/nm-core-utils.c index 03dbbcf81f..cbbac2816b 100644 --- a/src/nm-core-utils.c +++ b/src/nm-core-utils.c @@ -2999,7 +2999,8 @@ nm_utils_ipv6_interface_identifier_get_from_token (NMUtilsIPv6IfaceId *iid, * Returns: the input buffer filled with the id as string. */ const char * -nm_utils_inet6_interface_identifier_to_token (NMUtilsIPv6IfaceId iid, char *buf) +nm_utils_inet6_interface_identifier_to_token (NMUtilsIPv6IfaceId iid, + char buf[static INET6_ADDRSTRLEN]) { struct in6_addr i6_token = { .s6_addr = { 0, } }; diff --git a/src/nm-core-utils.h b/src/nm-core-utils.h index 7d63d06afc..fbb7987573 100644 --- a/src/nm-core-utils.h +++ b/src/nm-core-utils.h @@ -316,7 +316,7 @@ gboolean nm_utils_ipv6_interface_identifier_get_from_token (NMUtilsIPv6IfaceId * const char *token); const char *nm_utils_inet6_interface_identifier_to_token (NMUtilsIPv6IfaceId iid, - char *buf); + char buf[static INET6_ADDRSTRLEN]); gboolean nm_utils_get_ipv6_interface_identifier (NMLinkType link_type, const guint8 *hwaddr,