summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDong Du <Dd_nirvana@sjtu.edu.cn>2021-07-28 19:15:35 +0300
committerAnup Patel <anup@brainfault.org>2021-08-07 13:10:40 +0300
commitd244f3dbd6cfd241dc1db611c0325daedfcab9c6 (patch)
tree2efab53955b3a7c3d119d051c58b43bc5b3aca5d
parente928472e67f86d73c00537dfa6d5cef5d646426d (diff)
downloadopensbi-d244f3dbd6cfd241dc1db611c0325daedfcab9c6.tar.xz
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>
-rw-r--r--lib/sbi/sbi_string.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/lib/sbi/sbi_string.c b/lib/sbi/sbi_string.c
index 7805ba4..c87bce9 100644
--- a/lib/sbi/sbi_string.c
+++ b/lib/sbi/sbi_string.c
@@ -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;
}