diff options
author | Thomas Haller <thaller@redhat.com> | 2020-06-22 21:19:42 +0200 |
---|---|---|
committer | Thomas Haller <thaller@redhat.com> | 2020-06-22 21:20:03 +0200 |
commit | c6809df4cdf2f909ffcd98e842447fca523f1c0b (patch) | |
tree | 10e383c7d39b7ded3afaa10413712223b5a672f9 /shared | |
parent | 8a13b02d9642c4f8208c6ee0078a28d6127d84d4 (diff) | |
download | NetworkManager-c6809df4cdf2f909ffcd98e842447fca523f1c0b.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.
Diffstat (limited to 'shared')
-rw-r--r-- | shared/nm-glib-aux/nm-str-buf.h | 19 |
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, |