From: Bruno Haible Date: Sun, 3 May 2026 11:52:05 +0000 (+0200) Subject: array-omap: Use the counted_by attribute. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ee56d8bca55a0d841d622a76382dfd3025884942;p=thirdparty%2Fgnulib.git array-omap: Use the counted_by attribute. * lib/gl_array_omap.c (struct gl_omap_impl): Mark the pairs field as counted_by count. Swap these fields (needed for clang). (gl_array_nx_add_at): Increase map->count before writing into map->pairs. --- diff --git a/ChangeLog b/ChangeLog index 212bdd4514..36c0ec442b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2026-05-03 Bruno Haible + + array-omap: Use the counted_by attribute. + * lib/gl_array_omap.c (struct gl_omap_impl): Mark the pairs field as + counted_by count. Swap these fields (needed for clang). + (gl_array_nx_add_at): Increase map->count before writing into + map->pairs. + 2026-05-03 Bruno Haible array-map: Use the counted_by attribute. diff --git a/lib/gl_array_omap.c b/lib/gl_array_omap.c index 600ac472c8..be1b9151ad 100644 --- a/lib/gl_array_omap.c +++ b/lib/gl_array_omap.c @@ -37,10 +37,11 @@ struct pair struct gl_omap_impl { struct gl_omap_impl_base base; + size_t count; /* An array of ALLOCATED pairs, of which the first COUNT are used. 0 <= COUNT <= ALLOCATED. */ - struct pair *pairs; - size_t count; + struct pair *pairs + _GL_ATTRIBUTE_COUNTED_BY (count); size_t allocated; }; @@ -205,11 +206,11 @@ gl_array_nx_add_at (gl_omap_t map, size_t position, if (grow (map) < 0) return -1; struct pair *pairs = map->pairs; + map->count = count + 1; for (size_t i = count; i > position; i--) pairs[i] = pairs[i - 1]; pairs[position].key = key; pairs[position].value = value; - map->count = count + 1; return 1; }