Fix global array initialization to allocate the correct amount of memory

This commit is contained in:
Jeremiah Orians 2021-06-26 11:58:13 -04:00
parent 99df87bc0d
commit 745998ac13
No known key found for this signature in database
GPG Key ID: 6B3A3F198708F894
3 changed files with 17 additions and 14 deletions

View File

@ -1893,7 +1893,7 @@ void global_static_array(struct type* type_size, struct token_list* name)
}
/* length */
size = strtoint(global_token->s);
size = strtoint(global_token->s) * type_size->size;
/* Ensure properly closed */
global_token = global_token->next;
@ -1957,7 +1957,10 @@ void global_assignment()
*
* declaration:
* CONSTANT identifer value
* typedef identifer type;
* type-name identifier ;
* type-name identifier = value ;
* type-name identifier [ value ];
* type-name identifier ( parameter-list ) ;
* type-name identifier ( parameter-list ) statement
*
@ -2004,13 +2007,6 @@ new_type:
global_symbol_list = sym_declare(global_token->s, type_size, global_symbol_list);
global_token = global_token->next;
/* Deal with global static arrays */
if(match("[", global_token->s))
{
global_static_array(type_size, global_token->prev);
goto new_type;
}
/* Deal with global variables */
if(match(";", global_token->s))
{
@ -2037,6 +2033,13 @@ new_type:
goto new_type;
}
/* Deal with global static arrays */
if(match("[", global_token->s))
{
global_static_array(type_size, global_token->prev);
goto new_type;
}
/* Everything else is just an error */
line_error();
fputs("Received ", stderr);

View File

@ -179,8 +179,8 @@ fc31fc8b2d78bd50a4c89eb0e29149626868a70842a3dcb01ea87bb275a9e3c2 test/results/t
965bdf7049179199b9f423250a186c7b64ea55326c3249127d2daf7d42ae53cc test/results/test0106-knight-native-binary
0a929d6990caee3e93b1188a38fd3041c6f8e46d25a386024647c0f05c33bce7 test/results/test0106-knight-posix-binary
331ffb5284bd824494ad61a3b0b2dff5681a63ab604e9a06100af531ae237148 test/results/test0106-x86-binary
d5aa01efa7a7e5dbda4566df125cb118754077978f42f32ede08b13c10dac50b test/results/test1000-aarch64-binary
932b2f0f22348ada863113ff5259df0709ee222eae54c88183d13b81682ea152 test/results/test1000-amd64-binary
086077e57acc84180e28d3ff34b15107f5fb64d163cb3b80844266b495167ad7 test/results/test1000-armv7l-binary
b1b6e180cc618b2c13f08004e3ea795bccd8434efe9c541740ca8f4d4dbce6b8 test/results/test1000-knight-posix-binary
369f2e0e8804f070bc2a4cb3cd51b8e3033b3efd5a750474e9b82e872256bbfb test/results/test1000-x86-binary
41922435fa5ad4114dec2ae39a6dedcce830597594f159d809736411dc62a9cf test/results/test1000-aarch64-binary
470b5eb38b0c908a7e49bf9e507d9ca602b773e18b0ad7a1ca8aef0ca07a425f test/results/test1000-amd64-binary
c41944996ba8503abefb964a1a021fd1a53832b661141cd56b93d6180f6748c9 test/results/test1000-armv7l-binary
395f9e1a1a5b384fca908a6b82c5d5434f79adc9b6febeef556fef341fa8ca57 test/results/test1000-knight-posix-binary
b34a2f7547980f6a75d38a2f5034e0f34c8d1a912765a5be85dc11a07120489c test/results/test1000-x86-binary

View File

@ -1 +1 @@
a4a8e2c6925974195c7aaab5488943e455e61d9849dbb09035a9ebbd6c7fcc66 test/test1000/proof
b9c346bd7b7a8b41d0caa87209b5aabaaa1b5c95e907d64a73c30667cdcf39b8 test/test1000/proof