qemu-devel
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [PATCH v4 1/9] qapi: Make qapi_bool_parse() gracefully handle NULL v


From: Ilya Leoshkevich
Subject: Re: [PATCH v4 1/9] qapi: Make qapi_bool_parse() gracefully handle NULL value
Date: Fri, 10 Jan 2025 14:03:09 +0100
User-agent: Evolution 3.52.4 (3.52.4-2.fc40)

On Fri, 2025-01-10 at 11:33 +0000, Daniel P. Berrangé wrote:
> On Wed, Jan 08, 2025 at 09:04:56PM +0100, Ilya Leoshkevich wrote:
> > Use g_strcmp0(), so that NULL is considered an invalid parameter
> > value.
> 
> Why are we calling qapi_bool_parse with a NULL value in the first
> place ? IMHO this is a sign of a bug higher up the call chain
> that ought to be fixed, as in general all our input parsing code
> would expect non-NULL input values.

The intended use case is the following (patch 7/9):

    g_auto(GStrv) tokens = g_strsplit(*arg, "=", 2);
    Error *err = NULL;

    if (g_strcmp0(tokens[0], "suspend") == 0) {
        if (!qapi_bool_parse(tokens[0], tokens[1], &suspend, &err)) {
            warn_report_err(err);
            [...]

The idea is to uniformly handle "suspend=y", "suspend=invalid" and
"suspend"; the latter requires checking whether token[1] is NULL.
Of course, this can be special-cased in the caller, but this would be
less elegant.

[...]
> 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]