Skip to contentSkip to conversation

lib: sbi: Fix bug in strncmp function

PATCH New Dong Du 4 participants 5 messages Jul 28, 2021 – Aug 7, 2021

lore
Share & tools
lore

Dong Du

author
#0 lore raw

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
index 7805ba4..c87bce9 100644
@@ -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
#1 lore raw

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.

---
 lib/sbi/sbi_string.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/sbi/sbi_string.c +0 -0
index 7805ba4..c87bce9 100644

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

#2 lore raw

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.

---
 lib/sbi/sbi_string.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/sbi/sbi_string.c +0 -0
index 7805ba4..c87bce9 100644
@@ -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."
#3 lore raw

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.

---
 lib/sbi/sbi_string.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/sbi/sbi_string.c +0 -0
index 7805ba4..c87bce9 100644
@@ -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:

Applied
#4 lore raw

PATCH 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.

---
 lib/sbi/sbi_string.c | 4 ++++
 1 file changed, 4 insertions(+)
lib/sbi/sbi_string.c +0 -0
index 7805ba4..c87bce9 100644

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"

Quoted 6 lines
Quoted 1 line

Which this patch duly implements.

Ah, yes. Maybe we should update the comment to make it clear.

Anyway:

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