check a priority requested before filling tcb
@@ -354,6 +354,14 @@ static int thread_schedsetup(FAR struct tcb_s *tcb, int priority, start_t start,
if (ret == OK) {
/* Save task priority and entry point in the TCB */
+ if (priority < SCHED_PRIORITY_MIN) {
+ svdbg("WARNING: Requested priority is lower than min value (1)\n");
+ priority = SCHED_PRIORITY_MIN;
+ } else if (priority > SCHED_PRIORITY_MAX) {
+ svdbg("WARNING: Requested priority is higher than max value (255)\n");
+ priority = SCHED_PRIORITY_MAX;
+ }
+
tcb->sched_priority = (uint8_t)priority;
#ifdef CONFIG_PRIORITY_INHERITANCE
tcb->base_priority = (uint8_t)priority;
