Skip to content

Commit f8599de

Browse files
committed
Fix undefined behavior from signed left-shift in MSVC-MingW port
Replace `( 1 << n )` with `( 1UL << n )` in all left-shift expressions in portable/MSVC-MingW/port.c. Shifting a signed int by >= 31 is undefined behavior per ISO C11 §6.5.7.
1 parent d1f551e commit f8599de

1 file changed

Lines changed: 5 additions & 5 deletions

File tree

portable/MSVC-MingW/port.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static void prvProcessSimulatedInterrupts( void )
408408

409409
/* Create a pending tick to ensure the first task is started as soon as
410410
* this thread pends. */
411-
ulPendingInterrupts |= ( 1 << portINTERRUPT_TICK );
411+
ulPendingInterrupts |= ( 1UL << portINTERRUPT_TICK );
412412
SetEvent( pvInterruptEvent );
413413

414414
while( xPortRunning == pdTRUE )
@@ -447,7 +447,7 @@ static void prvProcessSimulatedInterrupts( void )
447447
if( ulIsrHandler[ i ]() != pdFALSE )
448448
{
449449
/* A bit mask is used purely to help debugging. */
450-
ulSwitchRequired |= ( 1 << i );
450+
ulSwitchRequired |= ( 1UL << i );
451451
}
452452
}
453453

@@ -580,7 +580,7 @@ void vPortCloseRunningThread( void * pvTaskToDelete,
580580
if( pvInterruptEventMutex != NULL )
581581
{
582582
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
583-
ulPendingInterrupts |= ( 1 << portINTERRUPT_YIELD );
583+
ulPendingInterrupts |= ( 1UL << portINTERRUPT_YIELD );
584584
ReleaseMutex( pvInterruptEventMutex );
585585
}
586586

@@ -604,7 +604,7 @@ void vPortGenerateSimulatedInterrupt( uint32_t ulInterruptNumber )
604604
if( ( ulInterruptNumber < portMAX_INTERRUPTS ) && ( pvInterruptEventMutex != NULL ) )
605605
{
606606
WaitForSingleObject( pvInterruptEventMutex, INFINITE );
607-
ulPendingInterrupts |= ( 1 << ulInterruptNumber );
607+
ulPendingInterrupts |= ( 1UL << ulInterruptNumber );
608608

609609
/* The simulated interrupt is now held pending, but don't actually
610610
* process it yet if this call is within a critical section. It is
@@ -645,7 +645,7 @@ void vPortGenerateSimulatedInterruptFromWindowsThread( uint32_t ulInterruptNumbe
645645

646646
/* Pending a user defined interrupt to be handled in simulated interrupt
647647
* handler thread. */
648-
ulPendingInterrupts |= ( 1 << ulInterruptNumber );
648+
ulPendingInterrupts |= ( 1UL << ulInterruptNumber );
649649

650650
/* The interrupt is now pending - notify the simulated interrupt
651651
* handler thread. Must be outside of a critical section to get here so

0 commit comments

Comments
 (0)