Yes, the -fbounds-safety stuff is probably best left up to the builder, just as 
-fsanitize=address etc. are. However, it should be a win to tell the compiler 
about the relationship between xm_max and xm_map, as that can help static 
checking even if -fbounds-safety is not used. Also, it should help when 
-fbounds-safety is used.

I installed the attached to GNU tar to do that. This is a simpler than what was in Jeff's 
proposal. Although I tested it it GCC 16.2 and clang 22.1.8, I haven't tested it with 
experimental Clang's new -fbounds-safety option - Jeff, could you do that? You should be able to 
use something like "./configure CC=clang CFLAGS='-fbounds-safety' && make 
check" to do the test.
From dd12f616285456bd3ed5877111f6fd6860b299ff Mon Sep 17 00:00:00 2001
From: Paul Eggert <[email protected]>
Date: Sat, 12 Sep 2026 14:56:07 -0700
Subject: [PATCH] tar: tell the compiler that xm_max counts xm_map

A simpler alternative to a suggestion by Jeff Bindel in:
https://lists.gnu.org/r/bug-tar/2026-09/msg00006.html
* src/tar.h (struct xattr_map.xm_map):
Move to the end, and declare with _GL_ATTRIBUTE_COUNTED_BY (xm_max).
---
 src/tar.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/tar.h b/src/tar.h
index 390f6b24..9bafa9fc 100644
--- a/src/tar.h
+++ b/src/tar.h
@@ -298,9 +298,9 @@ struct xattr_array
 
 struct xattr_map
 {
-  struct xattr_array *xm_map;
   idx_t xm_size;   /* Size of the xattr map */
   idx_t xm_max;    /* Max. number of entries in xattr_map */
+  struct xattr_array *xm_map _GL_ATTRIBUTE_COUNTED_BY (xm_max);
 };
 
 struct tar_stat_info
-- 
2.53.0

Reply via email to