* [PATCH v2] lib: sbi: Fix bug in strncmp function
@ 2021-07-28 16:15 Dong Du
2021-08-05 8:39 ` Bin Meng
0 siblings, 1 reply; 5+ messages in thread
From: Dong Du @ 2021-07-28 16:15 UTC (permalink / raw)
To: opensbi
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>
---
lib/sbi/sbi_string.c | 4 ++++
1 file changed, 4 insertions(+)
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;
}
--
2.31.1
^ permalink raw reply related [flat|nested] 5+ messages in thread
* [PATCH v2] lib: sbi: Fix bug in strncmp function
2021-07-28 16:15 [PATCH v2] lib: sbi: Fix bug in strncmp function Dong Du
@ 2021-08-05 8:39 ` Bin Meng
2021-08-05 8:46 ` Andreas Schwab
0 siblings, 1 reply; 5+ messages in thread
From: Bin Meng @ 2021-08-05 8:39 UTC (permalink / raw)
To: opensbi
Hi Dong,
On Thu, Jul 29, 2021 at 12:23 AM Dong Du <Dd_nirvana@sjtu.edu.cn> wrote:
>
> 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>
> ---
> lib/sbi/sbi_string.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> 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;
> }
>
Your original patch is also needed: "strncmp should return 0 when the
count is 0"
Regards,
Bin
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] lib: sbi: Fix bug in strncmp function
2021-08-05 8:39 ` Bin Meng
@ 2021-08-05 8:46 ` Andreas Schwab
2021-08-05 9:18 ` Bin Meng
0 siblings, 1 reply; 5+ messages in thread
From: Andreas Schwab @ 2021-08-05 8:46 UTC (permalink / raw)
To: opensbi
On Aug 05 2021, Bin Meng wrote:
> Hi Dong,
>
> On Thu, Jul 29, 2021 at 12:23 AM Dong Du <Dd_nirvana@sjtu.edu.cn> wrote:
>>
>> 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>
>> ---
>> lib/sbi/sbi_string.c | 4 ++++
>> 1 file changed, 4 insertions(+)
>>
>> 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;
>> }
>>
>
> Your original patch is also needed: "strncmp should return 0 when the
> count is 0"
Which this patch duly implements.
Andreas.
--
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."
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] lib: sbi: Fix bug in strncmp function
2021-08-05 8:46 ` Andreas Schwab
@ 2021-08-05 9:18 ` Bin Meng
2021-08-07 10:18 ` Anup Patel
0 siblings, 1 reply; 5+ messages in thread
From: Bin Meng @ 2021-08-05 9:18 UTC (permalink / raw)
To: opensbi
On Thu, Aug 5, 2021 at 4:46 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
>
> On Aug 05 2021, Bin Meng wrote:
>
> > Hi Dong,
> >
> > On Thu, Jul 29, 2021 at 12:23 AM Dong Du <Dd_nirvana@sjtu.edu.cn> wrote:
> >>
> >> 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>
> >> ---
> >> lib/sbi/sbi_string.c | 4 ++++
> >> 1 file changed, 4 insertions(+)
> >>
> >> 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;
> >> }
> >>
> >
> > Your original patch is also needed: "strncmp should return 0 when the
> > count is 0"
>
> Which this patch duly implements.
Ah, yes. Maybe we should update the comment to make it clear.
Anyway:
Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
^ permalink raw reply [flat|nested] 5+ messages in thread
* [PATCH v2] lib: sbi: Fix bug in strncmp function
2021-08-05 9:18 ` Bin Meng
@ 2021-08-07 10:18 ` Anup Patel
0 siblings, 0 replies; 5+ messages in thread
From: Anup Patel @ 2021-08-07 10:18 UTC (permalink / raw)
To: opensbi
On Thu, Aug 5, 2021 at 2:49 PM Bin Meng <bmeng.cn@gmail.com> wrote:
>
> On Thu, Aug 5, 2021 at 4:46 PM Andreas Schwab <schwab@linux-m68k.org> wrote:
> >
> > On Aug 05 2021, Bin Meng wrote:
> >
> > > Hi Dong,
> > >
> > > On Thu, Jul 29, 2021 at 12:23 AM Dong Du <Dd_nirvana@sjtu.edu.cn> wrote:
> > >>
> > >> 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>
> > >> ---
> > >> lib/sbi/sbi_string.c | 4 ++++
> > >> 1 file changed, 4 insertions(+)
> > >>
> > >> 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;
> > >> }
> > >>
> > >
> > > Your original patch is also needed: "strncmp should return 0 when the
> > > count is 0"
> >
> > Which this patch duly implements.
>
> Ah, yes. Maybe we should update the comment to make it clear.
>
> Anyway:
> Reviewed-by: Bin Meng <bmeng.cn@gmail.com>
Looks good to me.
Reviewed-by: Anup Patel <anup.patel@wdc.com>
Applied this patch to the riscv/opensbi repo.
Thanks,
Anup
>
> --
> opensbi mailing list
> opensbi at lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/opensbi
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-08-07 10:18 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2021-07-28 16:15 [PATCH v2] lib: sbi: Fix bug in strncmp function Dong Du
2021-08-05 8:39 ` Bin Meng
2021-08-05 8:46 ` Andreas Schwab
2021-08-05 9:18 ` Bin Meng
2021-08-07 10:18 ` Anup Patel
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox