Re: [BlueZ resend 1/9] main: Simplify parse_config_string()

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

 



On Tue, 2024-07-02 at 11:08 -0400, Luiz Augusto von Dentz wrote:
> > 
<snip>
> > -       tmp = g_key_file_get_string(config, group, key, &err);
> > +       g_return_val_if_fail(val, false);
> 
> Nah, let's just use if (!val) return false as we normally do.

g_return_val_if_fail() will print a warning when passed NULL as a
holder for the value, which I think is correct given that it's a
programmer error to pass NULL.

I changed this to open code a warning instead.

> > 
> >  static void parse_general(GKeyFile *config)
> >  {
> > -       parse_config_string(config, "General", "Name",
> > &btd_opts.name);
> > +       char *str = NULL;
> > +
> > +       if (parse_config_string(config, "General", "Name", &str)) {
> > +               g_free(btd_opts.name);
> > +               btd_opts.name = str;
> > +       }
> 
> Yeah, I skip this on purpose, I don't quite like the idea that we
> have
> to do this for 1 specific entry, perhaps the better option is to
> incorporate the default values into the table table so we avoid
> having
> this problem of having to free like this.

It's the only option that has an already set default value that
requires allocating. Look at btd_opts in src/btd.h, and you'll see its
the only string and the only allocated memory in the struct.

This code isn't so different from parse_privacy(),
parse_multi_profile(), or many of the other calls to
parse_config_string().

I don't understand what you mean by incorporating "the default values
into the table table". If you want to have the default values in the
arrays pointed to by valid_groups[], then we would still need a special
case because this entry is the only one that requires memory
allocation.

I can send out this patch with the g_return_if_fail() removal and no
other changes if you'll take it. Otherwise it seems like too big a
change for a static analysis fix to be making, especially when that
change will probably not simplify the code we want to simplify.

> 
> >         parse_config_hex(config, "General", "Class",
> > &btd_opts.class);
> >         parse_config_u32(config, "General", "DiscoverableTimeout",
> >                                                 &btd_opts.discovto,
> > --
> > 2.45.2
> > 
> > 
> 
> 






[Index of Archives]     [Bluez Devel]     [Linux Wireless Networking]     [Linux Wireless Personal Area Networking]     [Linux ATH6KL]     [Linux USB Devel]     [Linux Media Drivers]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [Big List of Linux Books]

  Powered by Linux