5353static pthread_mutex_t mutex = PTHREAD_MUTEX_INITIALIZER ;
5454static int nrErrors = 0 ;
5555
56- #define LARGE_NUMBER 16000
57-
5856static void found_error (void ) {
5957 pthread_mutex_lock (& mutex );
6058 ++ nrErrors ;
@@ -788,7 +786,7 @@ static int get_territory_robustness_tests(void) {
788786 int nrTests = 0 ;
789787 int i ;
790788 char s1 [1 ];
791- char largeString [LARGE_NUMBER ];
789+ char largeString [16000 ];
792790
793791 nrTests += check_incorrect_get_territory_code_test ("UNKNOWN" );
794792 nrTests += check_incorrect_get_territory_code_test ("A" );
@@ -808,9 +806,10 @@ static int get_territory_robustness_tests(void) {
808806 s1 [0 ] = 0 ;
809807 nrTests += check_incorrect_get_territory_code_test (s1 );
810808
811- for (i = 0 ; i < sizeof (largeString ); ++ i ) {
809+ for (i = 0 ; i < sizeof (largeString ) - 1 ; ++ i ) {
812810 largeString [i ] = (char ) ((i % 223 ) + 32 );
813811 }
812+ largeString [sizeof (largeString ) - 1 ] = 0 ;
814813 nrTests += check_incorrect_get_territory_code_test (largeString );
815814 return nrTests ;
816815}
@@ -950,7 +949,7 @@ static int decode_robustness_tests(void) {
950949 int nrTests = 0 ;
951950 int i ;
952951 char s1 [1 ];
953- char largeString [LARGE_NUMBER ];
952+ char largeString [16000 ];
954953
955954 int tc = getTerritoryCode ("NLD" , 0 );
956955 nrTests += check_incorrect_decode_test ("" , 0 );
@@ -967,9 +966,10 @@ static int decode_robustness_tests(void) {
967966 nrTests += check_incorrect_decode_test (s1 , 0 );
968967 nrTests += check_incorrect_decode_test (s1 , tc );
969968
970- for (i = 0 ; i < sizeof (largeString ); ++ i ) {
969+ for (i = 0 ; i < sizeof (largeString ) - 1 ; ++ i ) {
971970 largeString [i ] = (char ) ((i % 223 ) + 32 );
972971 }
972+ largeString [sizeof (largeString ) - 1 ] = 0 ;
973973 nrTests += check_incorrect_decode_test (s1 , 0 );
974974 nrTests += check_incorrect_decode_test (s1 , tc );
975975 return nrTests ;
@@ -992,34 +992,47 @@ static int alphabet_robustness_tests(void) {
992992 int i ;
993993 int a ;
994994 char s1 [1 ];
995- char largeString [LARGE_NUMBER ];
995+ char largeString1 [20000 ];
996+ char largeString2 [10000 ];
996997 char * ps ;
997998 UWORD u1 [1 ];
998- UWORD largeUnicodeString [LARGE_NUMBER ];
999+ UWORD largeUnicodeString1 [10000 ];
1000+ UWORD largeUnicodeString2 [20000 ];
9991001 UWORD * pu ;
10001002
10011003 s1 [0 ] = 0 ;
1002- for (i = 0 ; i < sizeof (largeString ) - 1 ; ++ i ) {
1003- largeString [i ] = (char ) ((i % 223 ) + 32 );
1004+ for (i = 0 ; i < sizeof (largeString1 ) - 1 ; ++ i ) {
1005+ largeString1 [i ] = (char ) ((i % 223 ) + 32 );
10041006 }
1005- largeString [sizeof (largeString ) - 1 ] = 0 ;
1007+ largeString1 [sizeof (largeString1 ) - 1 ] = 0 ;
1008+ for (i = 0 ; i < sizeof (largeString2 ) - 1 ; ++ i ) {
1009+ largeString1 [2 ] = (char ) ((i % 223 ) + 32 );
1010+ }
1011+ largeString2 [sizeof (largeString2 ) - 1 ] = 0 ;
10061012
10071013 for (a = 0 ; a < MAPCODE_ALPHABETS_TOTAL ; a ++ ) {
10081014
1009- pu = convertToAlphabet (u1 , sizeof (u1 ), "" , a );
1015+ pu = convertToAlphabet (u1 , sizeof (u1 ) / sizeof ( u1 [ 0 ]) , "" , a );
10101016 nrTests += check_alphabet_assertion ("convertToAlphabet cannot return 0" , pu != 0 , "alphabet=%d" , a );
10111017 nrTests += check_alphabet_assertion ("convertToAlphabet must return empty string" , pu [0 ] == 0 , "alphabet=%d" , a );
10121018
1013- ps = convertToRoman (s1 , sizeof (s1 ), u1 );
1019+ ps = convertToRoman (s1 , sizeof (s1 ) / sizeof ( s1 [ 0 ]) , u1 );
10141020 nrTests += check_alphabet_assertion ("convertToRoman cannot return 0" , ps != 0 , "alphabet=%d" , a );
10151021 nrTests += check_alphabet_assertion ("convertToRoman must return empty string" , ps [0 ] == 0 , "alphabet=%d" , a );
10161022
1017- pu = convertToAlphabet (largeUnicodeString , sizeof (largeUnicodeString ) / sizeof (largeUnicodeString [0 ]), largeString , 0 );
1023+ pu = convertToAlphabet (largeUnicodeString1 , sizeof (largeUnicodeString1 ) / sizeof (largeUnicodeString1 [0 ]), largeString1 , 0 );
1024+ nrTests += check_alphabet_assertion ("convertToAlphabet cannot return 0" , pu != 0 , "alphabet=%d" , a );
1025+
1026+ ps = convertToRoman (largeString1 , sizeof (largeString1 ) / sizeof (largeString1 [0 ]), pu );
1027+ nrTests += check_alphabet_assertion ("convertToRoman cannot return 0" , ps != 0 , "alphabet=%d" , a );
1028+ nrTests += check_alphabet_assertion ("convertToRoman must return size" , strlen (ps ) < (sizeof (largeString1 ) / sizeof (largeString1 [0 ])), "alphabet=%d" , a );
1029+
1030+ pu = convertToAlphabet (largeUnicodeString2 , sizeof (largeUnicodeString2 ) / sizeof (largeUnicodeString2 [0 ]), largeString2 , 0 );
10181031 nrTests += check_alphabet_assertion ("convertToAlphabet cannot return 0" , pu != 0 , "alphabet=%d" , a );
10191032
1020- ps = convertToRoman (largeString , sizeof (largeString ) / sizeof (largeString [0 ]), pu );
1033+ ps = convertToRoman (largeString2 , sizeof (largeString2 ) / sizeof (largeString2 [0 ]), pu );
10211034 nrTests += check_alphabet_assertion ("convertToRoman cannot return 0" , ps != 0 , "alphabet=%d" , a );
1022- nrTests += check_alphabet_assertion ("convertToRoman must return size" , strlen (ps ) < sizeof (largeString ), "alphabet=%d" , a );
1035+ nrTests += check_alphabet_assertion ("convertToRoman must return size" , strlen (ps ) < ( sizeof (largeString2 ) / sizeof ( largeString2 [ 0 ]) ), "alphabet=%d" , a );
10231036 }
10241037 return nrTests ;
10251038}
0 commit comments