This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new ce743a22ee0 sched/irq: Fix type mismatch in irq_dispatch (MISRA C-2012 
Rule 10.3)
ce743a22ee0 is described below

commit ce743a22ee0bc470f39c9079ec04f72830eb20f9
Author: pangzhen1 <[email protected]>
AuthorDate: Thu Aug 28 20:46:19 2025 +0800

    sched/irq: Fix type mismatch in irq_dispatch (MISRA C-2012 Rule 10.3)
    
    IRQ_TO_NDX() returns int (can be negative on error), but was assigned
    to unsigned int variable 'ndx', violating MISRA C-2012 Rule 10.3.
    
    This also improves the condition check: instead of checking 'irq >= 0 && 
irq < NR_IRQS',
    we now check 'ndx >= 0' which properly handles the error case where 
IRQ_TO_NDX()
    returns a negative error code.
    
    Changes:
    - Change 'ndx' type from unsigned int to int
    - Simplify condition from 'irq >= 0 && irq < NR_IRQS' to 'ndx >= 0'
    
    This ensures type correctness and proper error handling.
    
    Signed-off-by: pangzhen1 <[email protected]>
---
 sched/irq/irq_dispatch.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c
index 4885e771f8f..fc6d2746a6a 100644
--- a/sched/irq/irq_dispatch.c
+++ b/sched/irq/irq_dispatch.c
@@ -102,10 +102,10 @@ void irq_dispatch(int irq, FAR void *context)
 #endif
   xcpt_t vector = irq_unexpected_isr;
   FAR void *arg = NULL;
-  unsigned int ndx = IRQ_TO_NDX(irq);
+  int ndx = IRQ_TO_NDX(irq);
 
 #if NR_IRQS > 0
-  if (irq >= 0 && irq < NR_IRQS)
+  if (ndx >= 0)
     {
 #ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
       if (ndx < CONFIG_ARCH_NUSER_INTERRUPTS)

Reply via email to