@@ -2545,13 +2545,9 @@ struct ondisk_untracked_cache {
2545
2545
struct stat_data info_exclude_stat ;
2546
2546
struct stat_data excludes_file_stat ;
2547
2547
uint32_t dir_flags ;
2548
- unsigned char info_exclude_sha1 [20 ];
2549
- unsigned char excludes_file_sha1 [20 ];
2550
- char exclude_per_dir [FLEX_ARRAY ];
2551
2548
};
2552
2549
2553
2550
#define ouc_offset (x ) offsetof(struct ondisk_untracked_cache, x)
2554
- #define ouc_size (len ) (ouc_offset(exclude_per_dir) + len + 1)
2555
2551
2556
2552
struct write_data {
2557
2553
int index ; /* number of written untracked_cache_dir */
@@ -2634,20 +2630,21 @@ void write_untracked_extension(struct strbuf *out, struct untracked_cache *untra
2634
2630
struct write_data wd ;
2635
2631
unsigned char varbuf [16 ];
2636
2632
int varint_len ;
2637
- size_t len = strlen ( untracked -> exclude_per_dir ) ;
2633
+ const unsigned hashsz = the_hash_algo -> rawsz ;
2638
2634
2639
- FLEX_ALLOC_MEM ( ouc , exclude_per_dir , untracked -> exclude_per_dir , len );
2635
+ ouc = xcalloc ( 1 , sizeof ( * ouc ) );
2640
2636
stat_data_to_disk (& ouc -> info_exclude_stat , & untracked -> ss_info_exclude .stat );
2641
2637
stat_data_to_disk (& ouc -> excludes_file_stat , & untracked -> ss_excludes_file .stat );
2642
- hashcpy (ouc -> info_exclude_sha1 , untracked -> ss_info_exclude .oid .hash );
2643
- hashcpy (ouc -> excludes_file_sha1 , untracked -> ss_excludes_file .oid .hash );
2644
2638
ouc -> dir_flags = htonl (untracked -> dir_flags );
2645
2639
2646
2640
varint_len = encode_varint (untracked -> ident .len , varbuf );
2647
2641
strbuf_add (out , varbuf , varint_len );
2648
2642
strbuf_addbuf (out , & untracked -> ident );
2649
2643
2650
- strbuf_add (out , ouc , ouc_size (len ));
2644
+ strbuf_add (out , ouc , sizeof (* ouc ));
2645
+ strbuf_add (out , untracked -> ss_info_exclude .oid .hash , hashsz );
2646
+ strbuf_add (out , untracked -> ss_excludes_file .oid .hash , hashsz );
2647
+ strbuf_add (out , untracked -> exclude_per_dir , strlen (untracked -> exclude_per_dir ) + 1 );
2651
2648
FREE_AND_NULL (ouc );
2652
2649
2653
2650
if (!untracked -> root ) {
@@ -2834,6 +2831,9 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2834
2831
int ident_len ;
2835
2832
ssize_t len ;
2836
2833
const char * exclude_per_dir ;
2834
+ const unsigned hashsz = the_hash_algo -> rawsz ;
2835
+ const unsigned offset = sizeof (struct ondisk_untracked_cache );
2836
+ const unsigned exclude_per_dir_offset = offset + 2 * hashsz ;
2837
2837
2838
2838
if (sz <= 1 || end [-1 ] != '\0' )
2839
2839
return NULL ;
@@ -2845,23 +2845,23 @@ struct untracked_cache *read_untracked_extension(const void *data, unsigned long
2845
2845
ident = (const char * )next ;
2846
2846
next += ident_len ;
2847
2847
2848
- if (next + ouc_size ( 0 ) > end )
2848
+ if (next + exclude_per_dir_offset + 1 > end )
2849
2849
return NULL ;
2850
2850
2851
2851
uc = xcalloc (1 , sizeof (* uc ));
2852
2852
strbuf_init (& uc -> ident , ident_len );
2853
2853
strbuf_add (& uc -> ident , ident , ident_len );
2854
2854
load_oid_stat (& uc -> ss_info_exclude ,
2855
2855
next + ouc_offset (info_exclude_stat ),
2856
- next + ouc_offset ( info_exclude_sha1 ) );
2856
+ next + offset );
2857
2857
load_oid_stat (& uc -> ss_excludes_file ,
2858
2858
next + ouc_offset (excludes_file_stat ),
2859
- next + ouc_offset ( excludes_file_sha1 ) );
2859
+ next + offset + hashsz );
2860
2860
uc -> dir_flags = get_be32 (next + ouc_offset (dir_flags ));
2861
- exclude_per_dir = (const char * )next + ouc_offset ( exclude_per_dir ) ;
2861
+ exclude_per_dir = (const char * )next + exclude_per_dir_offset ;
2862
2862
uc -> exclude_per_dir = xstrdup (exclude_per_dir );
2863
2863
/* NUL after exclude_per_dir is covered by sizeof(*ouc) */
2864
- next += ouc_size ( strlen (exclude_per_dir )) ;
2864
+ next += exclude_per_dir_offset + strlen (exclude_per_dir ) + 1 ;
2865
2865
if (next >= end )
2866
2866
goto done2 ;
2867
2867
0 commit comments