@@ -169,12 +169,18 @@ static int range_overlaps(uint32_t start1, uint32_t end1, uint32_t start2,
169169 return !(end1 <= start2 || end2 <= start1 );
170170}
171171
172+ static size_t linker_range_size (const void * start , const void * end )
173+ {
174+ return (size_t )((uintptr_t )end - (uintptr_t )start );
175+ }
176+
172177static int check_memory_ranges ()
173178{
174179 uint32_t wb_start , wb_end ;
175180
176181 wb_start = (uint32_t )WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE ;
177- wb_end = wb_start + (_wolfboot_flash_end - _wolfboot_flash_start );
182+ wb_end = wb_start + (uint32_t )linker_range_size (_wolfboot_flash_start ,
183+ _wolfboot_flash_end );
178184 if (range_overlaps (wb_start , wb_end , (uint32_t )_start_data ,
179185 (uint32_t )_end_data ))
180186 return -1 ;
@@ -210,11 +216,12 @@ static void load_wolfboot(void)
210216 }
211217
212218 wolfboot_start = (uint32_t )WOLFBOOT_LOAD_BASE - IMAGE_HEADER_SIZE ;
213- wolfboot_size = _wolfboot_flash_end - _wolfboot_flash_start ;
219+ wolfboot_size = linker_range_size (_wolfboot_flash_start ,
220+ _wolfboot_flash_end );
214221 x86_log_memory_load (wolfboot_start , wolfboot_start + wolfboot_size ,
215222 "wolfboot" );
216223 memcpy ((uint8_t * )wolfboot_start ,_wolfboot_flash_start , wolfboot_size );
217- bss_size = wb_end_bss - wb_start_bss ;
224+ bss_size = linker_range_size ( wb_start_bss , wb_end_bss ) ;
218225 x86_log_memory_load ((uint32_t )(uintptr_t )wb_start_bss ,
219226 (uint32_t )(uintptr_t )(wb_start_bss + bss_size ),
220227 "wolfboot .bss" );
@@ -338,7 +345,7 @@ static inline void memory_init_data_bss(void)
338345 }
339346 x86_log_memory_load ((uint32_t )(uintptr_t )_start_bss ,
340347 (uint32_t )(uintptr_t )_end_bss , "stage1 .bss" );
341- memset (_start_bss , 0 , ( _end_bss - _start_bss ));
348+ memset (_start_bss , 0 , linker_range_size ( _start_bss , _end_bss ));
342349}
343350
344351static int pci_get_capability (uint8_t bus , uint8_t dev , uint8_t fun ,
@@ -656,7 +663,8 @@ void start(uint32_t stack_base, uint32_t stack_top, uint64_t timestamp,
656663 stage2_params -> tpm_policy = (uint32_t )_start_policy ;
657664
658665 stage2_params -> tpm_policy_size = * _policy_size_u32 ;
659- if (stage2_params -> tpm_policy_size > _end_policy - _start_policy )
666+ if (stage2_params -> tpm_policy_size >
667+ linker_range_size (_start_policy , _end_policy ))
660668 stage2_params -> tpm_policy_size = 0 ;
661669 wolfBoot_printf ("setting policy @%x (%d bytes)\r\n" ,
662670 (uint32_t )(uintptr_t )stage2_params -> tpm_policy ,
0 commit comments