@@ -215,13 +215,14 @@ static int gf_gen_decode_matrix(unsigned char *encode_matrix,
215
215
216
216
int main (int argc , char * argv [])
217
217
{
218
- int re = 0 ;
218
+ int re = -1 ;
219
219
int i , j , p , rtest , m , k ;
220
220
int nerrs , nsrcerrs ;
221
221
void * buf ;
222
222
unsigned int decode_index [MMAX ];
223
- unsigned char * temp_buffs [TEST_SOURCES ], * buffs [TEST_SOURCES ];
224
- unsigned char * encode_matrix , * decode_matrix , * invert_matrix , * g_tbls ;
223
+ unsigned char * temp_buffs [TEST_SOURCES ] = { NULL }, * buffs [TEST_SOURCES ] = { NULL };
224
+ unsigned char * encode_matrix = NULL , * decode_matrix = NULL , * invert_matrix =
225
+ NULL , * g_tbls = NULL ;
225
226
unsigned char src_in_err [TEST_SOURCES ], src_err_list [TEST_SOURCES ];
226
227
unsigned char * recov [TEST_SOURCES ];
227
228
@@ -238,15 +239,15 @@ int main(int argc, char *argv[])
238
239
for (i = 0 ; i < TEST_SOURCES ; i ++ ) {
239
240
if (posix_memalign (& buf , 64 , TEST_LEN )) {
240
241
printf ("alloc error: Fail" );
241
- return -1 ;
242
+ goto exit ;
242
243
}
243
244
buffs [i ] = buf ;
244
245
}
245
246
246
247
for (i = 0 ; i < TEST_SOURCES ; i ++ ) {
247
248
if (posix_memalign (& buf , 64 , TEST_LEN )) {
248
249
printf ("alloc error: Fail" );
249
- return -1 ;
250
+ goto exit ;
250
251
}
251
252
temp_buffs [i ] = buf ;
252
253
}
@@ -260,13 +261,15 @@ int main(int argc, char *argv[])
260
261
if (encode_matrix == NULL || decode_matrix == NULL
261
262
|| invert_matrix == NULL || g_tbls == NULL ) {
262
263
printf ("Test failure! Error with malloc\n" );
263
- return -1 ;
264
+ goto exit ;
264
265
}
265
266
// Pick a first test
266
267
m = 9 ;
267
268
k = 5 ;
268
- if (m > MMAX || k > KMAX )
269
- return -1 ;
269
+ if (m > MMAX || k > KMAX ) {
270
+ re = -1 ;
271
+ goto exit ;
272
+ }
270
273
271
274
// Make random data
272
275
for (i = 0 ; i < k ; i ++ )
@@ -295,7 +298,7 @@ int main(int argc, char *argv[])
295
298
nerrs , nsrcerrs , k , m );
296
299
if (re != 0 ) {
297
300
printf ("Fail to gf_gen_decode_matrix\n" );
298
- return -1 ;
301
+ goto exit ;
299
302
}
300
303
// Pack recovery array as list of valid sources
301
304
// Its order must be the same as the order
@@ -327,15 +330,18 @@ int main(int argc, char *argv[])
327
330
dump (temp_buffs [k + i ], 25 );
328
331
printf ("orig :" );
329
332
dump (buffs [src_err_list [i ]], 25 );
330
- return -1 ;
333
+ re = -1 ;
334
+ goto exit ;
331
335
}
332
336
}
333
337
334
338
// Pick a first test
335
339
m = 9 ;
336
340
k = 5 ;
337
- if (m > MMAX || k > KMAX )
338
- return -1 ;
341
+ if (m > MMAX || k > KMAX ) {
342
+ re = -1 ;
343
+ goto exit ;
344
+ }
339
345
340
346
// Make random data
341
347
for (i = 0 ; i < k ; i ++ )
@@ -363,7 +369,7 @@ int main(int argc, char *argv[])
363
369
nerrs , nsrcerrs , k , m );
364
370
if (re != 0 ) {
365
371
printf ("Fail to gf_gen_decode_matrix\n" );
366
- return -1 ;
372
+ goto exit ;
367
373
}
368
374
// Pack recovery array as list of valid sources
369
375
// Its order must be the same as the order
@@ -395,7 +401,8 @@ int main(int argc, char *argv[])
395
401
dump (temp_buffs [k + i ], 25 );
396
402
printf ("orig :" );
397
403
dump (buffs [src_err_list [i ]], 25 );
398
- return -1 ;
404
+ re = -1 ;
405
+ goto exit ;
399
406
}
400
407
}
401
408
@@ -433,7 +440,7 @@ int main(int argc, char *argv[])
433
440
src_in_err , nerrs , nsrcerrs , k , m );
434
441
if (re != 0 ) {
435
442
printf ("Fail to gf_gen_decode_matrix\n" );
436
- return -1 ;
443
+ goto exit ;
437
444
}
438
445
// Pack recovery array as list of valid sources
439
446
// Its order must be the same as the order
@@ -468,7 +475,8 @@ int main(int argc, char *argv[])
468
475
dump (buffs [src_err_list [i ]], 25 );
469
476
printf ("recov %d:" , src_err_list [i ]);
470
477
dump (temp_buffs [k + i ], 25 );
471
- return -1 ;
478
+ re = -1 ;
479
+ goto exit ;
472
480
}
473
481
}
474
482
#ifdef TEST_VERBOSE
@@ -479,13 +487,17 @@ int main(int argc, char *argv[])
479
487
// Run tests at end of buffer for Electric Fence
480
488
k = 16 ;
481
489
align = (LEN_ALIGN_CHK_B != 0 ) ? 1 : 16 ;
482
- if (k > KMAX )
483
- return -1 ;
490
+ if (k > KMAX ) {
491
+ re = -1 ;
492
+ goto exit ;
493
+ }
484
494
485
495
for (rows = 1 ; rows <= 16 ; rows ++ ) {
486
496
m = k + rows ;
487
- if (m > MMAX )
488
- return -1 ;
497
+ if (m > MMAX ) {
498
+ re = -1 ;
499
+ goto exit ;
500
+ }
489
501
490
502
// Make random data
491
503
for (i = 0 ; i < k ; i ++ )
@@ -518,7 +530,7 @@ int main(int argc, char *argv[])
518
530
src_in_err , nerrs , nsrcerrs , k , m );
519
531
if (re != 0 ) {
520
532
printf ("Fail to gf_gen_decode_matrix\n" );
521
- return -1 ;
533
+ goto exit ;
522
534
}
523
535
// Pack recovery array as list of valid sources
524
536
// Its order must be the same as the order
@@ -558,7 +570,8 @@ int main(int argc, char *argv[])
558
570
dump (temp_buffs [k + i ], align );
559
571
printf ("orig :" );
560
572
dump (efence_buffs [src_err_list [i ]], align );
561
- return -1 ;
573
+ re = -1 ;
574
+ goto exit ;
562
575
}
563
576
}
564
577
}
@@ -610,7 +623,7 @@ int main(int argc, char *argv[])
610
623
src_in_err , nerrs , nsrcerrs , k , m );
611
624
if (re != 0 ) {
612
625
printf ("Fail to gf_gen_decode_matrix\n" );
613
- return -1 ;
626
+ goto exit ;
614
627
}
615
628
// Pack recovery array as list of valid sources
616
629
// Its order must be the same as the order
@@ -645,7 +658,8 @@ int main(int argc, char *argv[])
645
658
dump (ubuffs [src_err_list [i ]], 25 );
646
659
printf ("recov %d:" , src_err_list [i ]);
647
660
dump (temp_ubuffs [k + i ], 25 );
648
- return -1 ;
661
+ re = -1 ;
662
+ goto exit ;
649
663
}
650
664
}
651
665
@@ -658,13 +672,15 @@ int main(int argc, char *argv[])
658
672
659
673
if (memcmp (buffs [i ], temp_buffs [0 ], offset )) {
660
674
printf ("Fail rand ualign encode pad start\n" );
661
- return -1 ;
675
+ re = -1 ;
676
+ goto exit ;
662
677
}
663
678
if (memcmp
664
679
(buffs [i ] + offset + size , temp_buffs [0 ],
665
680
PTR_ALIGN_CHK_B - offset )) {
666
681
printf ("Fail rand ualign encode pad end\n" );
667
- return -1 ;
682
+ re = -1 ;
683
+ goto exit ;
668
684
}
669
685
}
670
686
@@ -673,13 +689,15 @@ int main(int argc, char *argv[])
673
689
offset = temp_ubuffs [k + i ] - temp_buffs [k + i ];
674
690
if (memcmp (temp_buffs [k + i ], temp_buffs [0 ], offset )) {
675
691
printf ("Fail rand ualign decode pad start\n" );
676
- return -1 ;
692
+ re = -1 ;
693
+ goto exit ;
677
694
}
678
695
if (memcmp
679
696
(temp_buffs [k + i ] + offset + size , temp_buffs [0 ],
680
697
PTR_ALIGN_CHK_B - offset )) {
681
698
printf ("Fail rand ualign decode pad end\n" );
682
- return -1 ;
699
+ re = -1 ;
700
+ goto exit ;
683
701
}
684
702
}
685
703
@@ -723,7 +741,7 @@ int main(int argc, char *argv[])
723
741
src_in_err , nerrs , nsrcerrs , k , m );
724
742
if (re != 0 ) {
725
743
printf ("Fail to gf_gen_decode_matrix\n" );
726
- return -1 ;
744
+ goto exit ;
727
745
}
728
746
// Pack recovery array as list of valid sources
729
747
// Its order must be the same as the order
@@ -758,11 +776,26 @@ int main(int argc, char *argv[])
758
776
dump (buffs [src_err_list [i ]], 25 );
759
777
printf ("recov %d:" , src_err_list [i ]);
760
778
dump (temp_buffs [k + i ], 25 );
761
- return -1 ;
779
+ re = -1 ;
780
+ goto exit ;
762
781
}
763
782
}
764
783
}
765
784
766
785
printf ("done EC tests: Pass\n" );
767
- return 0 ;
786
+ re = 0 ;
787
+
788
+ exit :
789
+ for (i = 0 ; i < TEST_SOURCES ; i ++ ) {
790
+ if (buffs [i ])
791
+ aligned_free (buffs [i ]);
792
+ if (temp_buffs [i ])
793
+ aligned_free (temp_buffs [i ]);
794
+ }
795
+ free (encode_matrix );
796
+ free (decode_matrix );
797
+ free (invert_matrix );
798
+ free (g_tbls );
799
+
800
+ return re ;
768
801
}
0 commit comments