lib: sbi: Fix bug in strncmp function when count is 0
authorDong Du <Dd_nirvana@sjtu.edu.cn>
Wed, 28 Jul 2021 16:15:35 +0000 (00:15 +0800)
committerAnup Patel <anup@brainfault.org>
Sat, 7 Aug 2021 10:10:40 +0000 (15:40 +0530)
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>
lib/sbi/sbi_string.c

index 7805ba4..c87bce9 100644 (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;
 }