mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-01-01 07:10:12 +01:00
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.
This commit is contained in:
parent
8a13b02d96
commit
c6809df4cd
1 changed files with 12 additions and 7 deletions
|
|
@ -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,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue