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 652b90f8999 sched/irq: avoid casting from signed int to unsigned int
652b90f8999 is described below
commit 652b90f8999ae851a9639b8fc5b3cfe4031dc9ee
Author: pangzhen1 <[email protected]>
AuthorDate: Mon Aug 11 20:19:36 2025 +0800
sched/irq: avoid casting from signed int to unsigned int
casting from signed int to unsigned int is not safe and should not be
allowed
Signed-off-by: pangzhen1 <[email protected]>
---
sched/irq/irq_attach.c | 2 +-
sched/irq/irq_attach_thread.c | 4 ++--
sched/irq/irq_attach_wqueue.c | 4 ++--
sched/irq/irq_dispatch.c | 4 ++--
4 files changed, 7 insertions(+), 7 deletions(-)
diff --git a/sched/irq/irq_attach.c b/sched/irq/irq_attach.c
index a992c927931..690d059ad99 100644
--- a/sched/irq/irq_attach.c
+++ b/sched/irq/irq_attach.c
@@ -111,7 +111,7 @@ int irq_attach(int irq, xcpt_t isr, FAR void *arg)
#if NR_IRQS > 0
int ret = -EINVAL;
- if ((unsigned)irq < NR_IRQS)
+ if (irq >= 0 && irq < NR_IRQS)
{
int ndx = IRQ_TO_NDX(irq);
irqstate_t flags;
diff --git a/sched/irq/irq_attach_thread.c b/sched/irq/irq_attach_thread.c
index ef5f98e599c..02d47b58505 100644
--- a/sched/irq/irq_attach_thread.c
+++ b/sched/irq/irq_attach_thread.c
@@ -99,7 +99,7 @@ static int isr_thread_main(int argc, FAR char *argv[])
info.arg = arg;
info.handler = isr;
- nxsem_init(&sem, 0, 0);
+ nxsem_init(&sem, 0, 0u);
irq_attach(irq, irq_thread_default_handler, &info);
@@ -159,7 +159,7 @@ int irq_attach_thread(int irq, xcpt_t isr, xcpt_t
isrthread, FAR void *arg,
pid_t pid;
int ndx;
- if ((unsigned)irq >= NR_IRQS)
+ if (irq < 0 || irq >= NR_IRQS)
{
return -EINVAL;
}
diff --git a/sched/irq/irq_attach_wqueue.c b/sched/irq/irq_attach_wqueue.c
index fc1eb11539d..7f7b33ed9b4 100644
--- a/sched/irq/irq_attach_wqueue.c
+++ b/sched/irq/irq_attach_wqueue.c
@@ -138,7 +138,7 @@ static int irq_default_handler(int irq, FAR void *regs, FAR
void *arg)
if (ret == IRQ_WAKE_THREAD)
{
- work_queue_wq(info->wqueue, &info->work, irq_work_handler, info, 0);
+ work_queue_wq(info->wqueue, &info->work, irq_work_handler, info, 0u);
ret = OK;
}
@@ -179,7 +179,7 @@ int irq_attach_wqueue(int irq, xcpt_t isr, xcpt_t isrwork,
#if NR_IRQS > 0
int ndx;
- if ((unsigned)irq >= NR_IRQS)
+ if (irq < 0 || irq >= NR_IRQS)
{
return -EINVAL;
}
diff --git a/sched/irq/irq_dispatch.c b/sched/irq/irq_dispatch.c
index 71dc5a14762..0b8cde958d6 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;
+ int ndx = irq;
#if NR_IRQS > 0
- if ((unsigned)irq < NR_IRQS)
+ if (irq >= 0 && irq < NR_IRQS)
{
#ifdef CONFIG_ARCH_MINIMAL_VECTORTABLE
ndx = g_irqmap[irq];