@@ -81,7 +81,6 @@ static void t_read_file(void)
81
81
int n , err ;
82
82
char * * names = NULL ;
83
83
const char * want [] = { "line1" , "line2" , "line3" };
84
- int i = 0 ;
85
84
86
85
check_int (fd , > , 0 );
87
86
n = write_in_full (fd , out , strlen (out ));
@@ -92,9 +91,8 @@ static void t_read_file(void)
92
91
err = read_lines (fn , & names );
93
92
check (!err );
94
93
95
- for (i = 0 ; names [i ]; i ++ ) {
94
+ for (size_t i = 0 ; names [i ]; i ++ )
96
95
check_str (want [i ], names [i ]);
97
- }
98
96
free_names (names );
99
97
(void ) remove (fn );
100
98
}
@@ -123,7 +121,7 @@ static void write_n_ref_tables(struct reftable_stack *st,
123
121
};
124
122
125
123
strbuf_reset (& buf );
126
- strbuf_addf (& buf , "refs/heads/branch-%04u" , (unsigned ) i );
124
+ strbuf_addf (& buf , "refs/heads/branch-%04" PRIuMAX , (uintmax_t ) i );
127
125
ref .refname = buf .buf ;
128
126
set_test_hash (ref .value .val1 , i );
129
127
@@ -164,12 +162,12 @@ static void t_reftable_stack_add_one(void)
164
162
.value_type = REFTABLE_REF_SYMREF ,
165
163
.value .symref = (char * ) "master" ,
166
164
};
167
- struct reftable_ref_record dest = { NULL };
165
+ struct reftable_ref_record dest = { 0 };
168
166
struct stat stat_result = { 0 };
169
167
err = reftable_new_stack (& st , dir , & opts );
170
168
check (!err );
171
169
172
- err = reftable_stack_add (st , & write_test_ref , & ref );
170
+ err = reftable_stack_add (st , write_test_ref , & ref );
173
171
check (!err );
174
172
175
173
err = reftable_stack_read_ref (st , ref .refname , & dest );
@@ -234,16 +232,16 @@ static void t_reftable_stack_uptodate(void)
234
232
err = reftable_new_stack (& st2 , dir , & opts );
235
233
check (!err );
236
234
237
- err = reftable_stack_add (st1 , & write_test_ref , & ref1 );
235
+ err = reftable_stack_add (st1 , write_test_ref , & ref1 );
238
236
check (!err );
239
237
240
- err = reftable_stack_add (st2 , & write_test_ref , & ref2 );
238
+ err = reftable_stack_add (st2 , write_test_ref , & ref2 );
241
239
check_int (err , = = , REFTABLE_OUTDATED_ERROR );
242
240
243
241
err = reftable_stack_reload (st2 );
244
242
check (!err );
245
243
246
- err = reftable_stack_add (st2 , & write_test_ref , & ref2 );
244
+ err = reftable_stack_add (st2 , write_test_ref , & ref2 );
247
245
check (!err );
248
246
reftable_stack_destroy (st1 );
249
247
reftable_stack_destroy (st2 );
@@ -264,7 +262,7 @@ static void t_reftable_stack_transaction_api(void)
264
262
.value_type = REFTABLE_REF_SYMREF ,
265
263
.value .symref = (char * ) "master" ,
266
264
};
267
- struct reftable_ref_record dest = { NULL };
265
+ struct reftable_ref_record dest = { 0 };
268
266
269
267
err = reftable_new_stack (& st , dir , & opts );
270
268
check (!err );
@@ -274,7 +272,7 @@ static void t_reftable_stack_transaction_api(void)
274
272
err = reftable_stack_new_addition (& add , st );
275
273
check (!err );
276
274
277
- err = reftable_addition_add (add , & write_test_ref , & ref );
275
+ err = reftable_addition_add (add , write_test_ref , & ref );
278
276
check (!err );
279
277
280
278
err = reftable_addition_commit (add );
@@ -298,20 +296,21 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
298
296
struct reftable_write_options opts = {0 };
299
297
struct reftable_addition * add = NULL ;
300
298
struct reftable_stack * st = NULL ;
301
- int i , n = 20 , err ;
299
+ size_t n = 20 ;
300
+ int err ;
302
301
303
302
err = reftable_new_stack (& st , dir , & opts );
304
303
check (!err );
305
304
306
- for (i = 0 ; i <= n ; i ++ ) {
305
+ for (size_t i = 0 ; i <= n ; i ++ ) {
307
306
struct reftable_ref_record ref = {
308
307
.update_index = reftable_stack_next_update_index (st ),
309
308
.value_type = REFTABLE_REF_SYMREF ,
310
309
.value .symref = (char * ) "master" ,
311
310
};
312
311
char name [100 ];
313
312
314
- snprintf (name , sizeof (name ), "branch%04d" , i );
313
+ snprintf (name , sizeof (name ), "branch%04" PRIuMAX , ( uintmax_t ) i );
315
314
ref .refname = name ;
316
315
317
316
/*
@@ -324,7 +323,7 @@ static void t_reftable_stack_transaction_api_performs_auto_compaction(void)
324
323
err = reftable_stack_new_addition (& add , st );
325
324
check (!err );
326
325
327
- err = reftable_addition_add (add , & write_test_ref , & ref );
326
+ err = reftable_addition_add (add , write_test_ref , & ref );
328
327
check (!err );
329
328
330
329
err = reftable_addition_commit (add );
@@ -355,7 +354,7 @@ static void t_reftable_stack_auto_compaction_fails_gracefully(void)
355
354
.value_type = REFTABLE_REF_VAL1 ,
356
355
.value .val1 = {0x01 },
357
356
};
358
- struct reftable_write_options opts = {0 };
357
+ struct reftable_write_options opts = { 0 };
359
358
struct reftable_stack * st ;
360
359
struct strbuf table_path = STRBUF_INIT ;
361
360
char * dir = get_tmp_dir (__LINE__ );
@@ -417,10 +416,10 @@ static void t_reftable_stack_update_index_check(void)
417
416
err = reftable_new_stack (& st , dir , & opts );
418
417
check (!err );
419
418
420
- err = reftable_stack_add (st , & write_test_ref , & ref1 );
419
+ err = reftable_stack_add (st , write_test_ref , & ref1 );
421
420
check (!err );
422
421
423
- err = reftable_stack_add (st , & write_test_ref , & ref2 );
422
+ err = reftable_stack_add (st , write_test_ref , & ref2 );
424
423
check_int (err , = = , REFTABLE_API_ERROR );
425
424
reftable_stack_destroy (st );
426
425
clear_dir (dir );
@@ -436,7 +435,7 @@ static void t_reftable_stack_lock_failure(void)
436
435
err = reftable_new_stack (& st , dir , & opts );
437
436
check (!err );
438
437
for (i = -1 ; i != REFTABLE_EMPTY_TABLE_ERROR ; i -- ) {
439
- err = reftable_stack_add (st , & write_error , & i );
438
+ err = reftable_stack_add (st , write_error , & i );
440
439
check_int (err , = = , i );
441
440
}
442
441
@@ -446,7 +445,6 @@ static void t_reftable_stack_lock_failure(void)
446
445
447
446
static void t_reftable_stack_add (void )
448
447
{
449
- int i = 0 ;
450
448
int err = 0 ;
451
449
struct reftable_write_options opts = {
452
450
.exact_log_message = 1 ,
@@ -455,18 +453,18 @@ static void t_reftable_stack_add(void)
455
453
};
456
454
struct reftable_stack * st = NULL ;
457
455
char * dir = get_tmp_dir (__LINE__ );
458
- struct reftable_ref_record refs [2 ] = { { NULL } };
459
- struct reftable_log_record logs [2 ] = { { NULL } };
456
+ struct reftable_ref_record refs [2 ] = { 0 };
457
+ struct reftable_log_record logs [2 ] = { 0 };
460
458
struct strbuf path = STRBUF_INIT ;
461
459
struct stat stat_result ;
462
- int N = ARRAY_SIZE (refs );
460
+ size_t i , N = ARRAY_SIZE (refs );
463
461
464
462
err = reftable_new_stack (& st , dir , & opts );
465
463
check (!err );
466
464
467
465
for (i = 0 ; i < N ; i ++ ) {
468
466
char buf [256 ];
469
- snprintf (buf , sizeof (buf ), "branch%02d" , i );
467
+ snprintf (buf , sizeof (buf ), "branch%02" PRIuMAX , ( uintmax_t ) i );
470
468
refs [i ].refname = xstrdup (buf );
471
469
refs [i ].update_index = i + 1 ;
472
470
refs [i ].value_type = REFTABLE_REF_VAL1 ;
@@ -480,7 +478,7 @@ static void t_reftable_stack_add(void)
480
478
}
481
479
482
480
for (i = 0 ; i < N ; i ++ ) {
483
- int err = reftable_stack_add (st , & write_test_ref , & refs [i ]);
481
+ int err = reftable_stack_add (st , write_test_ref , & refs [i ]);
484
482
check (!err );
485
483
}
486
484
@@ -489,15 +487,15 @@ static void t_reftable_stack_add(void)
489
487
.log = & logs [i ],
490
488
.update_index = reftable_stack_next_update_index (st ),
491
489
};
492
- int err = reftable_stack_add (st , & write_test_log , & arg );
490
+ int err = reftable_stack_add (st , write_test_log , & arg );
493
491
check (!err );
494
492
}
495
493
496
494
err = reftable_stack_compact_all (st , NULL );
497
495
check (!err );
498
496
499
497
for (i = 0 ; i < N ; i ++ ) {
500
- struct reftable_ref_record dest = { NULL };
498
+ struct reftable_ref_record dest = { 0 };
501
499
502
500
int err = reftable_stack_read_ref (st , refs [i ].refname , & dest );
503
501
check (!err );
@@ -507,7 +505,7 @@ static void t_reftable_stack_add(void)
507
505
}
508
506
509
507
for (i = 0 ; i < N ; i ++ ) {
510
- struct reftable_log_record dest = { NULL };
508
+ struct reftable_log_record dest = { 0 };
511
509
int err = reftable_stack_read_log (st , refs [i ].refname , & dest );
512
510
check (!err );
513
511
check (reftable_log_record_equal (& dest , logs + i ,
@@ -575,11 +573,11 @@ static void t_reftable_stack_log_normalize(void)
575
573
check (!err );
576
574
577
575
input .value .update .message = (char * ) "one\ntwo" ;
578
- err = reftable_stack_add (st , & write_test_log , & arg );
576
+ err = reftable_stack_add (st , write_test_log , & arg );
579
577
check_int (err , = = , REFTABLE_API_ERROR );
580
578
581
579
input .value .update .message = (char * ) "one" ;
582
- err = reftable_stack_add (st , & write_test_log , & arg );
580
+ err = reftable_stack_add (st , write_test_log , & arg );
583
581
check (!err );
584
582
585
583
err = reftable_stack_read_log (st , input .refname , & dest );
@@ -588,7 +586,7 @@ static void t_reftable_stack_log_normalize(void)
588
586
589
587
input .value .update .message = (char * ) "two\n" ;
590
588
arg .update_index = 2 ;
591
- err = reftable_stack_add (st , & write_test_log , & arg );
589
+ err = reftable_stack_add (st , write_test_log , & arg );
592
590
check (!err );
593
591
err = reftable_stack_read_log (st , input .refname , & dest );
594
592
check (!err );
@@ -602,16 +600,15 @@ static void t_reftable_stack_log_normalize(void)
602
600
603
601
static void t_reftable_stack_tombstone (void )
604
602
{
605
- int i = 0 ;
606
603
char * dir = get_tmp_dir (__LINE__ );
607
604
struct reftable_write_options opts = { 0 };
608
605
struct reftable_stack * st = NULL ;
609
606
int err ;
610
- struct reftable_ref_record refs [2 ] = { { NULL } };
611
- struct reftable_log_record logs [2 ] = { { NULL } };
612
- int N = ARRAY_SIZE (refs );
613
- struct reftable_ref_record dest = { NULL };
614
- struct reftable_log_record log_dest = { NULL };
607
+ struct reftable_ref_record refs [2 ] = { 0 };
608
+ struct reftable_log_record logs [2 ] = { 0 };
609
+ size_t i , N = ARRAY_SIZE (refs );
610
+ struct reftable_ref_record dest = { 0 };
611
+ struct reftable_log_record log_dest = { 0 };
615
612
616
613
err = reftable_new_stack (& st , dir , & opts );
617
614
check (!err );
@@ -637,7 +634,7 @@ static void t_reftable_stack_tombstone(void)
637
634
}
638
635
}
639
636
for (i = 0 ; i < N ; i ++ ) {
640
- int err = reftable_stack_add (st , & write_test_ref , & refs [i ]);
637
+ int err = reftable_stack_add (st , write_test_ref , & refs [i ]);
641
638
check (!err );
642
639
}
643
640
@@ -646,7 +643,7 @@ static void t_reftable_stack_tombstone(void)
646
643
.log = & logs [i ],
647
644
.update_index = reftable_stack_next_update_index (st ),
648
645
};
649
- int err = reftable_stack_add (st , & write_test_log , & arg );
646
+ int err = reftable_stack_add (st , write_test_log , & arg );
650
647
check (!err );
651
648
}
652
649
@@ -695,12 +692,12 @@ static void t_reftable_stack_hash_id(void)
695
692
struct reftable_stack * st32 = NULL ;
696
693
struct reftable_write_options opts_default = { 0 };
697
694
struct reftable_stack * st_default = NULL ;
698
- struct reftable_ref_record dest = { NULL };
695
+ struct reftable_ref_record dest = { 0 };
699
696
700
697
err = reftable_new_stack (& st , dir , & opts );
701
698
check (!err );
702
699
703
- err = reftable_stack_add (st , & write_test_ref , & ref );
700
+ err = reftable_stack_add (st , write_test_ref , & ref );
704
701
check (!err );
705
702
706
703
/* can't read it with the wrong hash ID. */
@@ -743,21 +740,20 @@ static void t_reflog_expire(void)
743
740
char * dir = get_tmp_dir (__LINE__ );
744
741
struct reftable_write_options opts = { 0 };
745
742
struct reftable_stack * st = NULL ;
746
- struct reftable_log_record logs [20 ] = { { NULL } };
747
- int N = ARRAY_SIZE (logs ) - 1 ;
748
- int i = 0 ;
743
+ struct reftable_log_record logs [20 ] = { 0 };
744
+ size_t i , N = ARRAY_SIZE (logs ) - 1 ;
749
745
int err ;
750
746
struct reftable_log_expiry_config expiry = {
751
747
.time = 10 ,
752
748
};
753
- struct reftable_log_record log = { NULL };
749
+ struct reftable_log_record log = { 0 };
754
750
755
751
err = reftable_new_stack (& st , dir , & opts );
756
752
check (!err );
757
753
758
754
for (i = 1 ; i <= N ; i ++ ) {
759
755
char buf [256 ];
760
- snprintf (buf , sizeof (buf ), "branch%02d" , i );
756
+ snprintf (buf , sizeof (buf ), "branch%02" PRIuMAX , ( uintmax_t ) i );
761
757
762
758
logs [i ].refname = xstrdup (buf );
763
759
logs [i ].update_index = i ;
@@ -772,7 +768,7 @@ static void t_reflog_expire(void)
772
768
.log = & logs [i ],
773
769
.update_index = reftable_stack_next_update_index (st ),
774
770
};
775
- int err = reftable_stack_add (st , & write_test_log , & arg );
771
+ int err = reftable_stack_add (st , write_test_log , & arg );
776
772
check (!err );
777
773
}
778
774
@@ -800,9 +796,8 @@ static void t_reflog_expire(void)
800
796
801
797
/* cleanup */
802
798
reftable_stack_destroy (st );
803
- for (i = 0 ; i <= N ; i ++ ) {
799
+ for (i = 0 ; i <= N ; i ++ )
804
800
reftable_log_record_release (& logs [i ]);
805
- }
806
801
clear_dir (dir );
807
802
reftable_log_record_release (& log );
808
803
}
@@ -824,7 +819,7 @@ static void t_empty_add(void)
824
819
err = reftable_new_stack (& st , dir , & opts );
825
820
check (!err );
826
821
827
- err = reftable_stack_add (st , & write_nothing , NULL );
822
+ err = reftable_stack_add (st , write_nothing , NULL );
828
823
check (!err );
829
824
830
825
err = reftable_new_stack (& st2 , dir , & opts );
@@ -851,8 +846,8 @@ static void t_reftable_stack_auto_compaction(void)
851
846
};
852
847
struct reftable_stack * st = NULL ;
853
848
char * dir = get_tmp_dir (__LINE__ );
854
- int err , i ;
855
- int N = 100 ;
849
+ int err ;
850
+ size_t i , N = 100 ;
856
851
857
852
err = reftable_new_stack (& st , dir , & opts );
858
853
check (!err );
@@ -865,9 +860,9 @@ static void t_reftable_stack_auto_compaction(void)
865
860
.value_type = REFTABLE_REF_SYMREF ,
866
861
.value .symref = (char * ) "master" ,
867
862
};
868
- snprintf (name , sizeof (name ), "branch%04d" , i );
863
+ snprintf (name , sizeof (name ), "branch%04" PRIuMAX , ( uintmax_t ) i );
869
864
870
- err = reftable_stack_add (st , & write_test_ref , & ref );
865
+ err = reftable_stack_add (st , write_test_ref , & ref );
871
866
check (!err );
872
867
873
868
err = reftable_stack_auto_compact (st );
@@ -929,7 +924,8 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
929
924
struct reftable_stack * st = NULL ;
930
925
struct strbuf refname = STRBUF_INIT ;
931
926
char * dir = get_tmp_dir (__LINE__ );
932
- int err , i , n = 20 ;
927
+ int err ;
928
+ size_t i , n = 20 ;
933
929
934
930
err = reftable_new_stack (& st , dir , & opts );
935
931
check (!err );
@@ -949,10 +945,10 @@ static void t_reftable_stack_add_performs_auto_compaction(void)
949
945
st -> opts .disable_auto_compact = i != n ;
950
946
951
947
strbuf_reset (& refname );
952
- strbuf_addf (& refname , "branch-%04d" , i );
948
+ strbuf_addf (& refname , "branch-%04" PRIuMAX , ( uintmax_t ) i );
953
949
ref .refname = refname .buf ;
954
950
955
- err = reftable_stack_add (st , & write_test_ref , & ref );
951
+ err = reftable_stack_add (st , write_test_ref , & ref );
956
952
check (!err );
957
953
958
954
/*
0 commit comments