[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH 1/2] Check return value of pk_str_concat
From: |
Tim Rühsen |
Subject: |
Re: [PATCH 1/2] Check return value of pk_str_concat |
Date: |
Thu, 7 May 2020 12:04:12 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.7.0 |
On 07.05.20 11:44, Jose E. Marchesi wrote:
>
> >
> > Hi Tim.
> >
> > diff --git a/poke/poke.c b/poke/poke.c
> > index f6d46351..798adb2b 100644
> > --- a/poke/poke.c
> > +++ b/poke/poke.c
> > @@ -446,6 +446,11 @@ initialize_user (void)
> > if (homedir != NULL)
> > {
> > char *pokerc = pk_str_concat (homedir, "/.pokerc", NULL);
> > + if (!pokerc)
> > + {
> > + pk_printf (_("out of memory\n"));
> > + exit (EXIT_FAILURE);
> > + }
> >
> > if (pk_file_readable (pokerc) == NULL)
> > {
> > @@ -479,6 +484,11 @@ initialize_user (void)
> > xdg_config_dirs = "/etc/xdg";
> >
> > char *config_path = pk_str_concat (xdg_config_dirs, ":",
> xdg_config_home, NULL);
> > + if (!config_path)
> > + {
> > + pk_printf (_("out of memory\n"));
> > + exit (EXIT_FAILURE);
> > + }
> >
> > char *dir = strtok (config_path, ":");
> > do
> > @@ -490,6 +500,11 @@ initialize_user (void)
> > /* Mount the full path and determine whether the resulting
> > file is readable. */
> > char *config_filename = pk_str_concat (dir,
> "/poke/pokerc.conf", NULL);
> > + if (!config_path)
> > + {
> > + pk_printf (_("out of memory\n"));
> > + exit (EXIT_FAILURE);
> > + }
> >
> > if (pk_file_readable (config_filename) == NULL)
> > {
> >
> >
> > What about having a function defined in poke/poke.c, like
> > poke_out_of_memory, that would take care of emitting the diagnostic
> > message and then exit with EXIT_FAILURE?
>
> Maybe a static inline like assert_alloc() ?
> Like in
> char *config_path = pk_str_concat ...
> assert_alloc(config_path);
>
> You might have a better name, though.
>
> Even better :)
> assert_alloc sounds good.
>
> BTW, i just see an error above:
> char *config_filename = pk_str_concat (dir, "/poke/pokerc.conf", NULL);
> if (!config_path)
>
Let's keep it simple and first push this (config_path corrected) commit.
I prepared another commit with pk_assert_alloc (), which possibly needs
more discussion. But it's possibly not the best idea to mix it all up
here :) WDYT ?
Regards, Tim
signature.asc
Description: OpenPGP digital signature