lib: sbi: Fix bug in strncmp function
PATCH v2 1/1 lib: sbi: Fix bug in strncmp function
No need to compare characters when the count turns to 0. Fix the issue in sbi_strncmp.
--- lib/sbi/sbi_string.c | 4 ++++ 1 file changed, 4 insertions(+)
lib/sbi/sbi_string.c +4 -0
@@ -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; }
Signature · 1 line
2.31.1
PATCH v2 1/1 lib: sbi: Fix bug in strncmp function
Hi Dong,
Quoted 14 lines · Dong Du
No need to compare characters when the count turns to 0. Fix the issue in
sbi_strncmp.Signed-off-by Dong Du <[email protected]>--- lib/sbi/sbi_string.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_string.c +0
-0
lib/sbi/sbi_string.c int sbi_strncmp(const char *a, const char *b, size_t count) · line 42
Quoted 10 lines
lib/sbi/sbi_string.c +4
-0@@ -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; }
Your original patch is also needed: "strncmp should return 0 when the count is 0"
Regards,
Bin
PATCH v2 1/1 lib: sbi: Fix bug in strncmp function
Quoted 20 lines · Bin Meng
Hi Dong,
Quoted 17 lines · Dong Du
No need to compare characters when the count turns to 0. Fix the issue in
sbi_strncmp.Signed-off-by Dong Du <[email protected]>--- lib/sbi/sbi_string.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_string.c +0
-0@@ -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--) ;
Quoted 10 lines
lib/sbi/sbi_string.c int sbi_strncmp(const char *a, const char *b, size_t count) · line 42
Quoted 7 lines
lib/sbi/sbi_string.c +4
-0+/* No difference till the end */ +if (!count) +return 0 ; +return *a - *b; }Your original patch is also needed: "strncmp should return 0 when the count is 0"
Which this patch duly implements.
Andreas.
Signature · 3 lines
Andreas Schwab, schwab at linux-m68k.org GPG Key fingerprint = 7578 EB47 D4E5 4D69 2510 2552 DF73 E780 A9DA AEC1 "And now for something completely different."
PATCH v2 1/1 lib: sbi: Fix bug in strncmp function
Quoted 34 lines · Andreas Schwab
Quoted 20 lines · Bin Meng
Hi Dong,
Quoted 17 lines · Dong Du
No need to compare characters when the count turns to 0. Fix the issue in
sbi_strncmp.Signed-off-by Dong Du <[email protected]>--- lib/sbi/sbi_string.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_string.c +0
-0@@ -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--) ;Quoted 10 lines
lib/sbi/sbi_string.c int sbi_strncmp(const char *a, const char *b, size_t count) · line 42
Quoted 7 lines
lib/sbi/sbi_string.c +4
-0+/* No difference till the end */ +if (!count) +return 0 ; +return *a - *b; }Your original patch is also needed: "strncmp should return 0 when the count is 0"
Quoted 1 line
Which this patch duly implements.
Ah, yes. Maybe we should update the comment to make it clear.
Anyway:
Anup Patel
AppliedPATCH v2 1/1 lib: sbi: Fix bug in strncmp function
Quoted 36 lines · Bin Meng
Quoted 34 lines · Andreas Schwab
Quoted 30 lines · Bin Meng
Hi Dong,
Quoted 14 lines · Dong Du
No need to compare characters when the count turns to 0. Fix the issue in
sbi_strncmp.Signed-off-by Dong Du <[email protected]>--- lib/sbi/sbi_string.c | 4 ++++ 1 file changed, 4 insertions(+)lib/sbi/sbi_string.c +0
-0lib/sbi/sbi_string.c int sbi_strncmp(const char *a, const char *b, size_t count) · line 42
Quoted 10 lines
lib/sbi/sbi_string.c +4
-0@@ -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; }Your original patch is also needed: "strncmp should return 0 when the count is 0"
Quoted 6 lines
Quoted 1 line
Which this patch duly implements.
Ah, yes. Maybe we should update the comment to make it clear.
Anyway:
Reviewed-by Bin Meng <[email protected]>
Looks good to me.
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
Quoted 5 lines
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi