nuttx/sched/sched: fix runtime error UBSan(division by zero)

NuttShell (NSH) NuttX-10.3.0
ap>
ap>
ap> uptime
sched/sched_sysinfo.c:69:37: runtime error: division by zero
[1]    28220 floating point exception  sudo ./nuttx

Signed-off-by: Junbo Zheng <zhengjunbo1@xiaomi.com>
This commit is contained in:
Junbo Zheng 2022-10-12 20:33:58 +08:00 committed by Xiang Xiao
parent 432c438c76
commit 1ab8b921f6
1 changed files with 11 additions and 4 deletions

View File

@ -65,10 +65,17 @@ int sysinfo(FAR struct sysinfo *info)
#ifdef CONFIG_SCHED_CPULOAD #ifdef CONFIG_SCHED_CPULOAD
clock_cpuload(0, &cpuload); clock_cpuload(0, &cpuload);
info->loads[0] = ((cpuload.total - cpuload.active) << /* On the simulator, you may hit cpuload.total == 0, but probably never
SI_LOAD_SHIFT) / cpuload.total; * on real hardware.
info->loads[1] = info->loads[0]; */
info->loads[2] = info->loads[0];
if (cpuload.total)
{
info->loads[0] = ((cpuload.total - cpuload.active) <<
SI_LOAD_SHIFT) / cpuload.total;
info->loads[1] = info->loads[0];
info->loads[2] = info->loads[0];
}
#endif #endif
#ifdef MM_KERNEL_USRHEAP_INIT #ifdef MM_KERNEL_USRHEAP_INIT