From 64894182ca52963db661ef52fc57b0cd55099f0d Mon Sep 17 00:00:00 2001 From: Thomas Haller Date: Mon, 6 Apr 2020 10:43:07 +0200 Subject: [PATCH] shared/strbuf: expose read only value for "allocated" buffer size We cannot actually mark the field as const, because then you could no longer initialize a variable that contains a NMStrBuf with designated initializers. We also want to keep the "_allocated" alias, for the only places that are allowed to mutate the field: inside "nm-str-buf.h". Add an alias for that field, that is allowed to be read, provided that you don't modify it! The alternative would be a nm_str_buf_get_allocated() accessor, but that seems unnecessarily verbose when you could just access the field. --- shared/nm-glib-aux/nm-str-buf.h | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/shared/nm-glib-aux/nm-str-buf.h b/shared/nm-glib-aux/nm-str-buf.h index 4c015aa43c..564f91c4b5 100644 --- a/shared/nm-glib-aux/nm-str-buf.h +++ b/shared/nm-glib-aux/nm-str-buf.h @@ -16,7 +16,10 @@ typedef struct _NMStrBuf { /*const*/ gsize len; gsize _len; }; - gsize _allocated; + union { + /*const*/ gsize allocated; + gsize _allocated; + }; bool _do_bzero_mem; } NMStrBuf;