From: Dong Du Date: Wed, 28 Jul 2021 16:15:35 +0000 (+0800) Subject: lib: sbi: Fix bug in strncmp function when count is 0 X-Git-Tag: v1.3~460 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d244f3dbd6cfd241dc1db611c0325daedfcab9c6;p=platform%2Fkernel%2Fopensbi-spacemit.git 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 Reviewed-by: Bin Meng Reviewed-by: Anup Patel --- 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; }