Message ID | 20230201054522.162611-1-shahuang@redhat.com (mailing list archive) |
---|---|
State | New |
Headers | show |
Series | selftests: KVM: Replace optarg with arg in guest_modes_cmdline | expand |
On Tue, Jan 31, 2023 at 9:46 PM <shahuang@redhat.com> wrote: > > From: Shaoqin Huang <shahuang@redhat.com> > > The parameter arg in guest_modes_cmdline not being used now, and the > optarg should be replaced with arg in guest_modes_cmdline. > > Signed-off-by: Shaoqin Huang <shahuang@redhat.com> > --- > tools/testing/selftests/kvm/lib/guest_modes.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c > index 99a575bbbc52..1f2dca4520ab 100644 > --- a/tools/testing/selftests/kvm/lib/guest_modes.c > +++ b/tools/testing/selftests/kvm/lib/guest_modes.c > @@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg) > mode_selected = true; > } > > - mode = strtoul(optarg, NULL, 10); > + mode = strtoul(arg, NULL, 10); While you are at it, can you also change strtoul to atoi_non_negative()? An underflow negative number will print an error message with a wrong positive guest mode ID not passed by the user. > TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode); > guest_modes[mode].enabled = true; > } > -- > 2.39.0 >
On 2/2/23 00:00, Vipin Sharma wrote: > On Tue, Jan 31, 2023 at 9:46 PM <shahuang@redhat.com> wrote: >> From: Shaoqin Huang <shahuang@redhat.com> >> >> The parameter arg in guest_modes_cmdline not being used now, and the >> optarg should be replaced with arg in guest_modes_cmdline. >> >> Signed-off-by: Shaoqin Huang <shahuang@redhat.com> >> --- >> tools/testing/selftests/kvm/lib/guest_modes.c | 2 +- >> 1 file changed, 1 insertion(+), 1 deletion(-) >> >> diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c >> index 99a575bbbc52..1f2dca4520ab 100644 >> --- a/tools/testing/selftests/kvm/lib/guest_modes.c >> +++ b/tools/testing/selftests/kvm/lib/guest_modes.c >> @@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg) >> mode_selected = true; >> } >> >> - mode = strtoul(optarg, NULL, 10); >> + mode = strtoul(arg, NULL, 10); > While you are at it, can you also change strtoul to atoi_non_negative()? > > An underflow negative number will print an error message with a wrong > positive guest mode ID not passed by the user. Of course I can do that. Thanks for you Suggestion. Thanks, Shaoqin >> TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode); >> guest_modes[mode].enabled = true; >> } >> -- >> 2.39.0 >>
diff --git a/tools/testing/selftests/kvm/lib/guest_modes.c b/tools/testing/selftests/kvm/lib/guest_modes.c index 99a575bbbc52..1f2dca4520ab 100644 --- a/tools/testing/selftests/kvm/lib/guest_modes.c +++ b/tools/testing/selftests/kvm/lib/guest_modes.c @@ -127,7 +127,7 @@ void guest_modes_cmdline(const char *arg) mode_selected = true; } - mode = strtoul(optarg, NULL, 10); + mode = strtoul(arg, NULL, 10); TEST_ASSERT(mode < NUM_VM_MODES, "Guest mode ID %d too big", mode); guest_modes[mode].enabled = true; }