diff mbox series

[kvm-unit-tests,3/9] s390x: topology: Fix parsing loop

Message ID 20231011085635.1996346-4-nsg@linux.ibm.com (mailing list archive)
State New, archived
Headers show
Series s390x: topology: Fixes and extension | expand

Commit Message

Nina Schoetterl-Glausch Oct. 11, 2023, 8:56 a.m. UTC
Without a comparison the loop is infinite.

Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
---
 s390x/topology.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

Comments

Janosch Frank Oct. 11, 2023, 11:07 a.m. UTC | #1
On 10/11/23 10:56, Nina Schoetterl-Glausch wrote:
> Without a comparison the loop is infinite.
> 
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Wait, how did this work before this change?
Did the strcmp effectively end the loop?

> ---
>   s390x/topology.c | 2 +-
>   1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/s390x/topology.c b/s390x/topology.c
> index e1bb6014..49d6dfeb 100644
> --- a/s390x/topology.c
> +++ b/s390x/topology.c
> @@ -466,7 +466,7 @@ static void parse_topology_args(int argc, char **argv)
>   		if (flag[0] != '-')
>   			report_abort("Argument is expected to begin with '-'");
>   		flag++;
> -		for (level = 0; ARRAY_SIZE(levels); level++) {
> +		for (level = 0; level < ARRAY_SIZE(levels); level++) {
>   			if (!strcmp(levels[level], flag))
>   				break;
>   		}
Nina Schoetterl-Glausch Oct. 11, 2023, 11:16 a.m. UTC | #2
On Wed, 2023-10-11 at 13:07 +0200, Janosch Frank wrote:
> On 10/11/23 10:56, Nina Schoetterl-Glausch wrote:
> > Without a comparison the loop is infinite.
> > 
> > Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>
> 
> Wait, how did this work before this change?
> Did the strcmp effectively end the loop?

Yes, it only worked because the test was passed correct arguments.
> 
> > ---
> >   s390x/topology.c | 2 +-
> >   1 file changed, 1 insertion(+), 1 deletion(-)
> > 
> > diff --git a/s390x/topology.c b/s390x/topology.c
> > index e1bb6014..49d6dfeb 100644
> > --- a/s390x/topology.c
> > +++ b/s390x/topology.c
> > @@ -466,7 +466,7 @@ static void parse_topology_args(int argc, char **argv)
> >   		if (flag[0] != '-')
> >   			report_abort("Argument is expected to begin with '-'");
> >   		flag++;
> > -		for (level = 0; ARRAY_SIZE(levels); level++) {
> > +		for (level = 0; level < ARRAY_SIZE(levels); level++) {
> >   			if (!strcmp(levels[level], flag))
> >   				break;
> >   		}
>
Nico Boehr Oct. 12, 2023, 2:46 p.m. UTC | #3
Quoting Nina Schoetterl-Glausch (2023-10-11 10:56:26)
> Without a comparison the loop is infinite.
> 
> Signed-off-by: Nina Schoetterl-Glausch <nsg@linux.ibm.com>

Reviewed-by: Nico Boehr <nrb@linux.ibm.com>
diff mbox series

Patch

diff --git a/s390x/topology.c b/s390x/topology.c
index e1bb6014..49d6dfeb 100644
--- a/s390x/topology.c
+++ b/s390x/topology.c
@@ -466,7 +466,7 @@  static void parse_topology_args(int argc, char **argv)
 		if (flag[0] != '-')
 			report_abort("Argument is expected to begin with '-'");
 		flag++;
-		for (level = 0; ARRAY_SIZE(levels); level++) {
+		for (level = 0; level < ARRAY_SIZE(levels); level++) {
 			if (!strcmp(levels[level], flag))
 				break;
 		}