Rather than chancing calling strchr when @err_noinfo == NULL or
calling virErrorTestMsgFormatInfoOne when @err_info == NULL, both
of which would fail, let's just return -1 immediately when we
encounter an error.
Signed-off-by: John Ferlan <jferlan@redhat.com>
---
tests/virerrortest.c | 11 +++++------
1 file changed, 5 insertions(+), 6 deletions(-)
diff --git a/tests/virerrortest.c b/tests/virerrortest.c
index eebf259343..48b4848b44 100644
--- a/tests/virerrortest.c
+++ b/tests/virerrortest.c
@@ -58,7 +58,6 @@ virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED)
const char *err_noinfo;
const char *err_info;
size_t i;
- int ret = 0;
for (i = 1; i < VIR_ERR_NUMBER_LAST; i++) {
err_noinfo = virErrorMsg(i, NULL);
@@ -66,25 +65,25 @@ virErrorTestMsgs(const void *opaque ATTRIBUTE_UNUSED)
if (!err_noinfo) {
VIR_TEST_VERBOSE("\nmissing string without info for error id %zu\n", i);
- ret = -1;
+ return -1;
}
if (!err_info) {
VIR_TEST_VERBOSE("\nmissing string with info for error id %zu\n", i);
- ret = -1;
+ return -1;
}
if (strchr(err_noinfo, '%')) {
VIR_TEST_VERBOSE("\nerror message id %zu contains formatting characters: '%s'\n",
i, err_noinfo);
- ret = -1;
+ return -1;
}
if (virErrorTestMsgFormatInfoOne(err_info) < 0)
- ret = -1;
+ return -1;
}
- return ret;
+ return 0;
}
--
2.17.2
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Mon, Dec 17, 2018 at 09:55:46 -0500, John Ferlan wrote: > Rather than chancing calling strchr when @err_noinfo == NULL or > calling virErrorTestMsgFormatInfoOne when @err_info == NULL, both > of which would fail, let's just return -1 immediately when we > encounter an error. > > Signed-off-by: John Ferlan <jferlan@redhat.com> > --- > tests/virerrortest.c | 11 +++++------ > 1 file changed, 5 insertions(+), 6 deletions(-) This would make the test hard to diagnose as it spits out one failure at time. I prefer you add the checks explicitly. -- libvir-list mailing list libvir-list@redhat.com https://www.redhat.com/mailman/listinfo/libvir-list
On 12/18/18 5:34 AM, Peter Krempa wrote:
> On Mon, Dec 17, 2018 at 09:55:46 -0500, John Ferlan wrote:
>> Rather than chancing calling strchr when @err_noinfo == NULL or
>> calling virErrorTestMsgFormatInfoOne when @err_info == NULL, both
>> of which would fail, let's just return -1 immediately when we
>> encounter an error.
>>
>> Signed-off-by: John Ferlan <jferlan@redhat.com>
>> ---
>> tests/virerrortest.c | 11 +++++------
>> 1 file changed, 5 insertions(+), 6 deletions(-)
>
> This would make the test hard to diagnose as it spits out one failure at
> time. I prefer you add the checks explicitly.
>
To avoid wasting steps/time w/ multiple iterations, you would rather
have the "err_noinfo &&" be a gate to strchr and "err_info &&" be a gate
to virErrorTestMsgFormatInfoOne?
So that the only diffs are:
- if (strchr(err_noinfo, '%')) {
+ if (err_noinfo && strchr(err_noinfo, '%')) {
and
- if (virErrorTestMsgFormatInfoOne(err_info) < 0)
+ if (err_info && virErrorTestMsgFormatInfoOne(err_info) < 0)
Tks -
John
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
On Tue, Dec 18, 2018 at 08:21:08 -0500, John Ferlan wrote:
>
>
> On 12/18/18 5:34 AM, Peter Krempa wrote:
> > On Mon, Dec 17, 2018 at 09:55:46 -0500, John Ferlan wrote:
> >> Rather than chancing calling strchr when @err_noinfo == NULL or
> >> calling virErrorTestMsgFormatInfoOne when @err_info == NULL, both
> >> of which would fail, let's just return -1 immediately when we
> >> encounter an error.
> >>
> >> Signed-off-by: John Ferlan <jferlan@redhat.com>
> >> ---
> >> tests/virerrortest.c | 11 +++++------
> >> 1 file changed, 5 insertions(+), 6 deletions(-)
> >
> > This would make the test hard to diagnose as it spits out one failure at
> > time. I prefer you add the checks explicitly.
> >
>
> To avoid wasting steps/time w/ multiple iterations, you would rather
> have the "err_noinfo &&" be a gate to strchr and "err_info &&" be a gate
> to virErrorTestMsgFormatInfoOne?
Yes exactly.
>
> So that the only diffs are:
>
> - if (strchr(err_noinfo, '%')) {
> + if (err_noinfo && strchr(err_noinfo, '%')) {
>
> and
>
> - if (virErrorTestMsgFormatInfoOne(err_info) < 0)
> + if (err_info && virErrorTestMsgFormatInfoOne(err_info) < 0)
>
>
> Tks -
ACK to that version
--
libvir-list mailing list
libvir-list@redhat.com
https://www.redhat.com/mailman/listinfo/libvir-list
© 2016 - 2026 Red Hat, Inc.