lib: sbi: Fix bug in strncmp function when count is 0

No need to compare characters when the count turns to 0.
Fix the issue in sbi_strncmp.

Signed-off-by: Dong Du <Dd_nirvana@sjtu.edu.cn>
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Reviewed-by: Anup Patel <anup.patel@wdc.com>
This commit is contained in:
Dong Du 2021-07-29 00:15:35 +08:00 committed by Anup Patel
parent e928472e67
commit d244f3dbd6
1 changed files with 4 additions and 0 deletions

View File

@ -33,6 +33,10 @@ int sbi_strncmp(const char *a, const char *b, size_t count)
for (; count > 0 && *a == *b && *a != '\0'; a++, b++, count--)
;
/* No difference till the end */
if (!count)
return 0;
return *a - *b;
}