[pacman-dev] [PATCH 1/6] pacman.c: remove unnecessary optarg checks
getopt takes care of making sure that options that require a value have
one. These checks were only added to silence clang, which no longer
complains about optarg being unchecked, and newer options already use
optarg unchecked.
Signed-off-by: Andrew Gregory
Plugs a memory leak when values were passed twice.
Signed-off-by: Andrew Gregory
On 14/01/14 14:01, Andrew Gregory wrote:
Plugs a memory leak when values were passed twice.
I'd much prefer we aborted instead. Specifying options twice is a sign of an error on the users behalf. Allan
Signed-off-by: Andrew Gregory
--- src/pacman/pacman.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 1fb447c..748bc54 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -443,9 +443,11 @@ static int parsearg_global(int opt) config->noprogressbar = 1; break; case OP_GPGDIR: + free(config->gpgdir); config->gpgdir = strdup(optarg); break; case OP_LOGFILE: + free(config->logfile); config->logfile = strndup(optarg, PATH_MAX); break; case OP_NOCONFIRM: @@ -453,10 +455,12 @@ static int parsearg_global(int opt) break; case OP_DBPATH: case 'b': + free(config->dbpath); config->dbpath = strdup(optarg); break; case OP_ROOT: case 'r': + free(config->rootdir); config->rootdir = strdup(optarg); break; case OP_VERBOSE: @@ -623,6 +627,7 @@ static int parsearg_trans(int opt) break; case OP_PRINTFORMAT: config->print = 1; + free(config->print_format); config->print_format = strdup(optarg); break; default:
I can't think of another command line application that has that behaviour on parsing command line arguments.
Yes, please don't do that, it breaks alias chains.
J. Leclanche
On Wed, Jan 15, 2014 at 4:08 PM, Simon Gomizelj
I can't think of another command line application that has that behaviour on parsing command line arguments.
The user requesting usage or version information is not an error.
Signed-off-by: Andrew Gregory
On Mon, Jan 13, 2014 at 10:01 PM, Andrew Gregory wrote: The user requesting usage or version information is not an error. Signed-off-by: Andrew Gregory $ git grep 'return 2;' src/ | cat
src/pacman/pacman.c: return 2;
src/pacman/pacman.c: return 2;
src/util/pacsort.c: return 2;
src/util/vercmp.c: return 2;
I'd broaden the scope of your patch a bit; might want to check the non-C
utilities too.
-Dan
The user requesting usage or version information is not an error.
Signed-off-by: Andrew Gregory
On 29/01/14 12:40, Andrew Gregory wrote:
The user requesting usage or version information is not an error.
Signed-off-by: Andrew Gregory
Ack.
We only care that packages are being installed from a repo, not how
many.
Signed-off-by: Andrew Gregory
Commit e47eb9a7 commented out base64_encode, which left base64_enc_map
unused, causing warnings under clang.
Signed-off-by: Andrew Gregory
Now, I'm not a dev, but this piqued my curiosity. Since this code is
under version control, why comment it out instead of just deleting it?
On Tue, Jan 14, 2014 at 1:01 PM, Andrew Gregory
Commit e47eb9a7 commented out base64_encode, which left base64_enc_map unused, causing warnings under clang.
Signed-off-by: Andrew Gregory
--- lib/libalpm/base64.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lib/libalpm/base64.c b/lib/libalpm/base64.c index 32c4445..31ecca1 100644 --- a/lib/libalpm/base64.c +++ b/lib/libalpm/base64.c @@ -36,6 +36,7 @@
#include "base64.h"
+#if 0 static const unsigned char base64_enc_map[64] = { 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', @@ -46,6 +47,7 @@ static const unsigned char base64_enc_map[64] = 'y', 'z', '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', '+', '/' }; +#endif
static const unsigned char base64_dec_map[128] = { -- 1.8.5.2
On 14/01/14 18:16, Emil Lundberg wrote:
Now, I'm not a dev, but this piqued my curiosity. Since this code is under version control, why comment it out instead of just deleting it?
This file is taken from another source. Just committing it out will prevent us pulling the code back in when where merge an upstream update. A
It's a boolean, so signedness doesn't matter, and the public API already
exposes it as an int through alpm_pkg_has_scriptlet().
Signed-off-by: Andrew Gregory
On Mon, Jan 13, 2014 at 10:01 PM, Andrew Gregory wrote: It's a boolean, so signedness doesn't matter, and the public API already
exposes it as an int through alpm_pkg_has_scriptlet(). Signed-off-by: Andrew Gregory This snuck in on my last patch set, whoops. lib/libalpm/package.h | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/package.h b/lib/libalpm/package.h
index 228fca3..a972d12 100644
--- a/lib/libalpm/package.h
+++ b/lib/libalpm/package.h
@@ -131,7 +131,7 @@ struct __alpm_pkg_t {
alpm_pkgvalidation_t validation;
alpm_pkgfrom_t origin;
alpm_pkgreason_t reason;
- unsigned int scriptlet;
+ int scriptlet;
}; alpm_file_t *_alpm_file_copy(alpm_file_t *dest, const alpm_file_t *src);
--
1.8.5.2
On 14/01/14 14:01, Andrew Gregory wrote:
getopt takes care of making sure that options that require a value have one. These checks were only added to silence clang, which no longer complains about optarg being unchecked, and newer options already use optarg unchecked.
Signed-off-by: Andrew Gregory
--- I haven't been able to find a warning flag that makes clang complain anyway.
These were added in commit b8b8c786 at the end of 2009. I'd bet this stopped used without initialization warnings. That would be in the days of clang 2.6. I'm fine with removing this given the gpgdir config option uses optarg without this check, so the clang issue must have been fixed a while ago. Allan
src/pacman/pacman.c | 11 ----------- 1 file changed, 11 deletions(-)
diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 6bf94e9..1fb447c 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -321,8 +321,6 @@ static void handler(int signum) cleanup(128 + signum); }
-#define check_optarg() if(!optarg) { return 1; } - static void invalid_opt(int used, const char *opt1, const char *opt2) { if(used) { @@ -337,7 +335,6 @@ static int parsearg_util_addlist(alpm_list_t **list) { char *i, *save;
- check_optarg();
for(i = strtok_r(optarg, ",", &save); i; i = strtok_r(NULL, ",", &save)) { *list = alpm_list_add(*list, strdup(i)); @@ -393,16 +390,13 @@ static int parsearg_global(int opt) { switch(opt) { case OP_ARCH: - check_optarg(); config_set_arch(optarg); break; case OP_ASK: - check_optarg(); config->noask = 1; config->ask = (unsigned int)atoi(optarg); break; case OP_CACHEDIR: - check_optarg(); config->cachedirs = alpm_list_add(config->cachedirs, strdup(optarg)); break; case OP_COLOR: @@ -420,7 +414,6 @@ static int parsearg_global(int opt) enable_colors(config->color); break; case OP_CONFIG: - check_optarg(); if(config->configfile) { free(config->configfile); } @@ -453,7 +446,6 @@ static int parsearg_global(int opt) config->gpgdir = strdup(optarg); break; case OP_LOGFILE: - check_optarg(); config->logfile = strndup(optarg, PATH_MAX); break; case OP_NOCONFIRM: @@ -461,12 +453,10 @@ static int parsearg_global(int opt) break; case OP_DBPATH: case 'b': - check_optarg(); config->dbpath = strdup(optarg); break; case OP_ROOT: case 'r': - check_optarg(); config->rootdir = strdup(optarg); break; case OP_VERBOSE: @@ -632,7 +622,6 @@ static int parsearg_trans(int opt) config->print = 1; break; case OP_PRINTFORMAT: - check_optarg(); config->print = 1; config->print_format = strdup(optarg); break;
participants (6)
-
Allan McRae
-
Andrew Gregory
-
Dan McGee
-
Emil Lundberg
-
Jerome Leclanche
-
Simon Gomizelj