@@ -65,7 +65,7 @@ static void module_parse_line_table(Module *mod, const uint8_t *data, size_t len
6565
6666static enum ModuleLoadResult module_populate_atoms_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
6767{
68- int atoms_count = READ_32_ALIGNED (table_data + 8 );
68+ int atoms_count = READ_32_UNALIGNED (table_data + 8 );
6969
7070 enum EnsureAtomsOpt ensure_opts = EnsureAtomsNoOpts ;
7171 if (atoms_count < 0 ) {
@@ -95,7 +95,7 @@ static enum ModuleLoadResult module_populate_atoms_table(Module *this_module, ui
9595
9696static enum ModuleLoadResult module_build_imported_functions_table (Module * this_module , uint8_t * table_data , GlobalContext * glb )
9797{
98- int functions_count = READ_32_ALIGNED (table_data + 8 );
98+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
9999
100100 this_module -> imported_funcs = calloc (functions_count , sizeof (struct ExportedFunction * ));
101101 if (IS_NULL_PTR (this_module -> imported_funcs )) {
@@ -104,11 +104,11 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
104104 }
105105
106106 for (int i = 0 ; i < functions_count ; i ++ ) {
107- int local_module_atom_index = READ_32_ALIGNED (table_data + i * 12 + 12 );
108- int local_function_atom_index = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
107+ int local_module_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 12 );
108+ int local_function_atom_index = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
109109 AtomString module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
110110 AtomString function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
111- uint32_t arity = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
111+ uint32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
112112
113113 const struct ExportedFunction * bif = bif_registry_get_handler (module_atom , function_atom , arity );
114114
@@ -140,13 +140,13 @@ static enum ModuleLoadResult module_build_imported_functions_table(Module *this_
140140void module_get_imported_function_module_and_name (const Module * this_module , int index , AtomString * module_atom , AtomString * function_atom , GlobalContext * glb )
141141{
142142 const uint8_t * table_data = (const uint8_t * ) this_module -> import_table ;
143- int functions_count = READ_32_ALIGNED (table_data + 8 );
143+ int functions_count = READ_32_UNALIGNED (table_data + 8 );
144144
145145 if (UNLIKELY (index > functions_count )) {
146146 AVM_ABORT ();
147147 }
148- int local_module_atom_index = READ_32_ALIGNED (table_data + index * 12 + 12 );
149- int local_function_atom_index = READ_32_ALIGNED (table_data + index * 12 + 4 + 12 );
148+ int local_module_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 12 );
149+ int local_function_atom_index = READ_32_UNALIGNED (table_data + index * 12 + 4 + 12 );
150150 * module_atom = module_get_atom_string_by_id (this_module , local_module_atom_index , glb );
151151 * function_atom = module_get_atom_string_by_id (this_module , local_function_atom_index , glb );
152152}
@@ -156,11 +156,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
156156{
157157 int best_label = -1 ;
158158 const uint8_t * export_table_data = (const uint8_t * ) this_module -> export_table ;
159- int exports_count = READ_32_ALIGNED (export_table_data + 8 );
159+ int exports_count = READ_32_UNALIGNED (export_table_data + 8 );
160160 for (int export_index = exports_count - 1 ; export_index >= 0 ; export_index -- ) {
161- int fun_atom_index = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 12 );
162- int fun_arity = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
163- int fun_label = READ_32_ALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
161+ int fun_atom_index = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 12 );
162+ int fun_arity = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 4 + 12 );
163+ int fun_label = READ_32_UNALIGNED (export_table_data + (export_index * 12 ) + 8 + 12 );
164164 if (fun_label <= label && best_label < fun_label ) {
165165 best_label = fun_label ;
166166 * arity = fun_arity ;
@@ -169,11 +169,11 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
169169 }
170170
171171 const uint8_t * local_table_data = (const uint8_t * ) this_module -> local_table ;
172- int locals_count = READ_32_ALIGNED (local_table_data + 8 );
172+ int locals_count = READ_32_UNALIGNED (local_table_data + 8 );
173173 for (int local_index = locals_count - 1 ; local_index >= 0 ; local_index -- ) {
174- int fun_atom_index = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 12 );
175- int fun_arity = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
176- int fun_label = READ_32_ALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
174+ int fun_atom_index = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 12 );
175+ int fun_arity = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 4 + 12 );
176+ int fun_label = READ_32_UNALIGNED (local_table_data + (local_index * 12 ) + 8 + 12 );
177177 if (fun_label <= label && best_label < fun_label ) {
178178 best_label = fun_label ;
179179 * arity = fun_arity ;
@@ -190,7 +190,7 @@ bool module_get_function_from_label(Module *this_module, int label, AtomString *
190190size_t module_get_exported_functions_count (Module * this_module )
191191{
192192 const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
193- size_t functions_count = READ_32_ALIGNED (table_data + 8 );
193+ size_t functions_count = READ_32_UNALIGNED (table_data + 8 );
194194 return functions_count ;
195195}
196196
@@ -200,10 +200,10 @@ uint32_t module_search_exported_function(Module *this_module, AtomString func_na
200200
201201 const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
202202 for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
203- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
204- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
203+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
204+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
205205 if ((func_arity == arity ) && atom_are_equals (func_name , function_atom )) {
206- uint32_t label = READ_32_ALIGNED (table_data + i * 12 + 8 + 12 );
206+ uint32_t label = READ_32_UNALIGNED (table_data + i * 12 + 8 + 12 );
207207 return label ;
208208 }
209209 }
@@ -218,8 +218,8 @@ term module_get_exported_functions(Module *this_module, Heap *heap, GlobalContex
218218
219219 const uint8_t * table_data = (const uint8_t * ) this_module -> export_table ;
220220 for (unsigned int i = 0 ; i < functions_count ; i ++ ) {
221- AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_ALIGNED (table_data + i * 12 + 12 ), glb );
222- int32_t arity = READ_32_ALIGNED (table_data + i * 12 + 4 + 12 );
221+ AtomString function_atom = module_get_atom_string_by_id (this_module , READ_32_UNALIGNED (table_data + i * 12 + 12 ), glb );
222+ int32_t arity = READ_32_UNALIGNED (table_data + i * 12 + 4 + 12 );
223223 term function_tuple = term_alloc_tuple (2 , heap );
224224 term_put_tuple_element (function_tuple , 0 , globalcontext_existing_term_from_atom_string (glb , function_atom ));
225225 term_put_tuple_element (function_tuple , 1 , term_from_int (arity ));
@@ -349,7 +349,7 @@ static bool module_are_literals_compressed(const uint8_t *litT)
349349#ifdef WITH_ZLIB
350350static void * module_uncompress_literals (const uint8_t * litT , int size )
351351{
352- unsigned int required_buf_size = READ_32_ALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
352+ unsigned int required_buf_size = READ_32_UNALIGNED (litT + LITT_UNCOMPRESSED_SIZE_OFFSET );
353353
354354 uint8_t * outBuf = malloc (required_buf_size );
355355 if (IS_NULL_PTR (outBuf )) {
@@ -384,7 +384,7 @@ static void *module_uncompress_literals(const uint8_t *litT, int size)
384384
385385static struct LiteralEntry * module_build_literals_table (const void * literalsBuf )
386386{
387- uint32_t terms_count = READ_32_ALIGNED (literalsBuf );
387+ uint32_t terms_count = READ_32_UNALIGNED (literalsBuf );
388388
389389 const uint8_t * pos = (const uint8_t * ) literalsBuf + sizeof (uint32_t );
390390
0 commit comments