Message ID | 20180211041513.18835-5-iff@escondida.tk |
---|---|
State | Superseded, archived |
Delegated to: | Andrew Gregory |
Headers | show |
Series | [pacman-dev,v3,1/5] pacman-conf.c: accept short options | expand |
On 02/10/18 at 10:15pm, iff@escondida.tk wrote: > From: Ivy Foster <iff@escondida.tk> > > Previously, it also parsed the config file instead of simply setting > the (global) config_file variable I think the original purpose of this patch is fundamentally unnecessary, but it does (accidentally, I assume) fix a bug if parsing the config file fails. > Signed-off-by: Ivy Foster <iff@escondida.tk> > --- > src/pacman/pacman-conf.c | 14 +++++++++----- > 1 file changed, 9 insertions(+), 5 deletions(-) > > diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c > index 51df8803..4828dfec 100644 > --- a/src/pacman/pacman-conf.c > +++ b/src/pacman/pacman-conf.c > @@ -100,10 +100,6 @@ static void parse_opts(int argc, char **argv) > exit(EXIT_FAILURE); > } > } > - > - if(parseconfigfile(config_file) != 0 || setdefaults(config) != 0) { > - fprintf(stderr, "error parsing '%s'\n", config_file); > - } > } > > static void list_repos(void) > @@ -403,8 +399,16 @@ int main(int argc, char **argv) > return EXIT_FAILURE; > } > > - config = config_new(); > parse_opts(argc, argv); config must be initialized before parse_opts because parse_opts modifies it. > + > + if(!(config = config_new())) { > + /* config_new prints the appropriate error message */ > + return EXIT_FAILURE; > + } > + if(parseconfigfile(config_file) != 0 || setdefaults(config) != 0) { > + fprintf(stderr, "error parsing '%s'\n", config_file); > + return EXIT_FAILURE; > + } > if(!config) { > return EXIT_FAILURE; > } > -- > 2.16.1
diff --git a/src/pacman/pacman-conf.c b/src/pacman/pacman-conf.c index 51df8803..4828dfec 100644 --- a/src/pacman/pacman-conf.c +++ b/src/pacman/pacman-conf.c @@ -100,10 +100,6 @@ static void parse_opts(int argc, char **argv) exit(EXIT_FAILURE); } } - - if(parseconfigfile(config_file) != 0 || setdefaults(config) != 0) { - fprintf(stderr, "error parsing '%s'\n", config_file); - } } static void list_repos(void) @@ -403,8 +399,16 @@ int main(int argc, char **argv) return EXIT_FAILURE; } - config = config_new(); parse_opts(argc, argv); + + if(!(config = config_new())) { + /* config_new prints the appropriate error message */ + return EXIT_FAILURE; + } + if(parseconfigfile(config_file) != 0 || setdefaults(config) != 0) { + fprintf(stderr, "error parsing '%s'\n", config_file); + return EXIT_FAILURE; + } if(!config) { return EXIT_FAILURE; }