summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas Haller <thaller@redhat.com>2020-06-22 21:19:42 +0200
committerThomas Haller <thaller@redhat.com>2020-12-08 15:20:16 +0100
commit10a2e4a0e73805cbcb9b9caa67ae3a0493921e58 (patch)
treea61aa6621e101cd213e4ef9864d11c46808c6777
parent4086261a9fc45c7a7e90da3d4600271b5c0a9616 (diff)
downloadNetworkManager-10a2e4a0e73805cbcb9b9caa67ae3a0493921e58.tar.gz
shared: make NM_STR_BUF_INIT() an inline function
In the previous form, NM_STR_BUF_INIT() was a macro. That makes sense, however it's not really possible to make that a macro without evaluating the reservation length multiple times. That means, NMStrBuf strbuf = NM_STR_BUF_INIT (nmtst_get_rand_uint32 () % 100, FALSE); leads to a crash. That is unfortunate, so instead make it an inline function that returns a NMStrBut struct. Usually, we avoid functions that returns structs, but here we do it. (cherry picked from commit c6809df4cdf2f909ffcd98e842447fca523f1c0b) (cherry picked from commit 3ed95f308f5ef94ffd4289e80592e0567365e5f9)
-rw-r--r--shared/nm-glib-aux/nm-str-buf.h19
1 files changed, 12 insertions, 7 deletions
diff --git a/shared/nm-glib-aux/nm-str-buf.h b/shared/nm-glib-aux/nm-str-buf.h
index 7121ba609a..b582e2c8a6 100644
--- a/shared/nm-glib-aux/nm-str-buf.h
+++ b/shared/nm-glib-aux/nm-str-buf.h
@@ -39,13 +39,18 @@ _nm_str_buf_assert (NMStrBuf *strbuf)
nm_assert (strbuf->_priv_len <= strbuf->_priv_allocated);
}
-#define NM_STR_BUF_INIT(len, do_bzero_mem) \
- ((NMStrBuf) { \
- ._priv_str = (len) ? g_malloc (len) : NULL, \
- ._priv_allocated = (len), \
- ._priv_len = 0, \
- ._priv_do_bzero_mem = (do_bzero_mem), \
- })
+static inline NMStrBuf
+NM_STR_BUF_INIT (gsize allocated, gboolean do_bzero_mem)
+{
+ NMStrBuf strbuf = {
+ ._priv_str = allocated ? g_malloc (allocated) : NULL,
+ ._priv_allocated = allocated,
+ ._priv_len = 0,
+ ._priv_do_bzero_mem = do_bzero_mem,
+ };
+
+ return strbuf;
+}
static inline void
nm_str_buf_init (NMStrBuf *strbuf,