[dm-devel] [PATCH 4/9] libmultipath: use strbuf in dict.c

Martin Wilck mwilck at suse.com
Wed Aug 11 15:27:05 UTC 2021


On Mi, 2021-07-28 at 14:03 -0500, Benjamin Marzinski wrote:
> On Thu, Jul 15, 2021 at 12:52:18PM +0200, mwilck at suse.com wrote:
> > From: Martin Wilck <mwilck at suse.com>
> > 
> > Temporary solution for snprint_keyword(), as print.c hasn't been
> > migrated yet.
> 
> Mostly good. I have some minor issues with this.
> 
> > 
> > Signed-off-by: Martin Wilck <mwilck at suse.com>
> > ---
> >  libmultipath/dict.c    | 313 ++++++++++++++++++-------------------
> > ----
> >  libmultipath/dict.h    |  19 +--
> >  libmultipath/parser.c  |  47 ++++---
> >  libmultipath/parser.h  |  15 +-
> >  libmultipath/propsel.c | 147 +++++++++----------
> >  5 files changed, 253 insertions(+), 288 deletions(-)
> > 
> >  
> > @@ -419,21 +381,18 @@ declare_ovr_snprint(selector, print_str)
> >  declare_mp_handler(selector, set_str)
> >  declare_mp_snprint(selector, print_str)
> >  
> > -static int snprint_uid_attrs(struct config *conf, char *buff, int
> > len,
> > +static int snprint_uid_attrs(struct config *conf, struct strbuf
> > *buff,
> >                              const void *dummy)
> >  {
> > -       char *p = buff;
> > -       int n, j;
> > +       int j, ret;
> >         const char *att;
> >  
> >         vector_foreach_slot(&conf->uid_attrs, att, j) {
> > -               n = snprintf(p, len, "%s%s", j == 0 ? "" : " ",
> > att);
> > -               if (n >= len)
> > -                       return (p - buff) + n;
> > -               p += n;
> > -               len -= n;
> > +               ret = print_strbuf(buff, "%s%s", j == 0 ? "" : " ",
> > att);
> > +               if (ret < 0)
> > +                       return ret;
> >         }
> 
> On success, this should return the amount of data written, instead of
> like the other snprint_* functions, not 0.
> 
> > -       return p - buff;
> > +       return 0;

Right, thanks!


> > +snprint_ble_simple (struct config *conf, struct strbuf *buff,
> > const void *data)
> >  {
> > -       const struct blentry * ble = (const struct blentry *)data;
> > +       const struct blentry *ble = (const struct blentry *)data;
> >  
> > -       return snprintf(buff, len, "\"%s\"", ble->str);
> 
> We should probably quote the regexes when printing them, so either
> append_strbuf_quoted() or, if you're worried about how that would
> handle
> interior quotes, print_strbud with "\"%s\"".
> 
> > +       return print_str(buff, ble->str);

print_str() already calls append_strbuf_quoted(). Am I overlooking
something?

Thanks,
Martin






More information about the dm-devel mailing list