diff options
author | Dan McGee <dan@archlinux.org> | 2012-04-07 13:01:13 -0500 |
---|---|---|
committer | Dave Reisner <dreisner@archlinux.org> | 2012-04-08 22:28:45 -0400 |
commit | a8a1b093eb23450244418232c9e30c4be035fc0b (patch) | |
tree | 632a47273f1c4678984d66ecce0c41b6cb7ece1d | |
parent | ec91133e38cb7c486ec995d4183f30e84f3ca736 (diff) | |
download | pacman-a8a1b093eb23450244418232c9e30c4be035fc0b.tar.xz |
Various tweaks to support building with excessive GCC warning flags
This fixes a bunch of small issues in order to enable a clean
successful build with a crazy number of GCC warning flags. A lot of
these changes are covered by -Wshadow, -Wformat-security, and
-Wstrict-overflow=5.
Signed-off-by: Dan McGee <dan@archlinux.org>
-rw-r--r-- | lib/libalpm/deps.c | 10 | ||||
-rw-r--r-- | lib/libalpm/trans.c | 7 | ||||
-rw-r--r-- | lib/libalpm/util.c | 17 | ||||
-rw-r--r-- | lib/libalpm/util.h | 2 | ||||
-rw-r--r-- | src/pacman/conf.c | 6 | ||||
-rw-r--r-- | src/pacman/pacman.c | 9 | ||||
-rw-r--r-- | src/pacman/sync.c | 4 | ||||
-rw-r--r-- | src/pacman/util.c | 2 |
8 files changed, 33 insertions, 24 deletions
diff --git a/lib/libalpm/deps.c b/lib/libalpm/deps.c index 6069f5e6..98519bd0 100644 --- a/lib/libalpm/deps.c +++ b/lib/libalpm/deps.c @@ -158,15 +158,17 @@ alpm_list_t *_alpm_sortbydeps(alpm_handle_t *handle, else if(nextchild->state == -1) { alpm_pkg_t *vertexpkg = vertex->data; alpm_pkg_t *childpkg = nextchild->data; - const char *message; _alpm_log(handle, ALPM_LOG_WARNING, _("dependency cycle detected:\n")); if(reverse) { - message =_("%s will be removed after its %s dependency\n"); + _alpm_log(handle, ALPM_LOG_WARNING, + _("%s will be removed after its %s dependency\n"), + vertexpkg->name, childpkg->name); } else { - message =_("%s will be installed before its %s dependency\n"); + _alpm_log(handle, ALPM_LOG_WARNING, + _("%s will be installed before its %s dependency\n"), + vertexpkg->name, childpkg->name); } - _alpm_log(handle, ALPM_LOG_WARNING, message, vertexpkg->name, childpkg->name); } } if(!found) { diff --git a/lib/libalpm/trans.c b/lib/libalpm/trans.c index 4309c07e..08f70dd7 100644 --- a/lib/libalpm/trans.c +++ b/lib/libalpm/trans.c @@ -276,8 +276,8 @@ static int grep(const char *fn, const char *needle) int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath, const char *script, const char *ver, const char *oldver, int is_archive) { - char cmdline[PATH_MAX]; - char *argv[] = { SCRIPTLET_SHELL, "-c", cmdline, NULL }; + char arg0[64], arg1[3], cmdline[PATH_MAX]; + char *argv[] = { arg0, arg1, cmdline, NULL }; char *tmpdir, *scriptfn = NULL, *scriptpath; int retval = 0; size_t len; @@ -293,6 +293,9 @@ int _alpm_runscriptlet(alpm_handle_t *handle, const char *filepath, return 0; } + strcpy(arg0, SCRIPTLET_SHELL); + strcpy(arg1, "-c"); + /* create a directory in $root/tmp/ for copying/extracting the scriptlet */ len = strlen(handle->root) + strlen("tmp/alpm_XXXXXX") + 1; MALLOC(tmpdir, len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index 22e9e359..a392c773 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -621,7 +621,9 @@ int _alpm_ldconfig(alpm_handle_t *handle) if(access(line, F_OK) == 0) { snprintf(line, PATH_MAX, "%ssbin/ldconfig", handle->root); if(access(line, X_OK) == 0) { - char *argv[] = { "ldconfig", NULL }; + char arg0[32]; + char *argv[] = { arg0, NULL }; + strcpy(arg0, "ldconfig"); return _alpm_run_chroot(handle, "/sbin/ldconfig", argv); } } @@ -676,7 +678,8 @@ const char *_alpm_filecache_setup(alpm_handle_t *handle) { struct stat buf; alpm_list_t *i; - char *cachedir, *tmpdir; + char *cachedir; + const char *tmpdir; /* Loop through the cache dirs until we find a usable directory */ for(i = handle->cachedirs; i; i = i->next) { @@ -995,13 +998,13 @@ int _alpm_archive_fgets(struct archive *a, struct archive_read_buffer *b) } if(needed > b->line_size) { /* need to realloc + copy data to fit total length */ - char *new; - CALLOC(new, needed, sizeof(char), b->ret = -ENOMEM; goto cleanup); - memcpy(new, b->line, b->line_size); + char *new_line; + CALLOC(new_line, needed, sizeof(char), b->ret = -ENOMEM; goto cleanup); + memcpy(new_line, b->line, b->line_size); b->line_size = needed; - b->line_offset = new + (b->line_offset - b->line); + b->line_offset = new_line + (b->line_offset - b->line); free(b->line); - b->line = new; + b->line = new_line; } } diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index e6747827..e35e35b9 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -87,7 +87,7 @@ #endif #define OPEN(fd, path, flags) do { fd = open(path, flags | O_BINARY); } while(fd == -1 && errno == EINTR) -#define CLOSE(fd) do { int ret; do { ret = close(fd); } while(ret == -1 && errno == EINTR); } while(0) +#define CLOSE(fd) do { int _ret; do { _ret = close(fd); } while(_ret == -1 && errno == EINTR); } while(0) /** * Used as a buffer/state holder for _alpm_archive_fgets(). diff --git a/src/pacman/conf.c b/src/pacman/conf.c index 4c3d063b..2632d18f 100644 --- a/src/pacman/conf.c +++ b/src/pacman/conf.c @@ -202,14 +202,14 @@ static int download_with_xfercommand(const char *url, const char *localpath, cleanup: /* restore the old cwd if we have it */ if(cwdfd >= 0) { - int ret; + int close_ret; if(fchdir(cwdfd) != 0) { pm_printf(ALPM_LOG_ERROR, _("could not restore working directory (%s)\n"), strerror(errno)); } do { - ret = close(cwdfd); - } while(ret == -1 && errno == EINTR); + close_ret = close(cwdfd); + } while(close_ret == -1 && errno == EINTR); } if(ret == -1) { diff --git a/src/pacman/pacman.c b/src/pacman/pacman.c index 1e6797c9..73d5be94 100644 --- a/src/pacman/pacman.c +++ b/src/pacman/pacman.c @@ -808,12 +808,13 @@ int main(int argc, char *argv[]) /* we support reading targets from stdin if a cmdline parameter is '-' */ if(!isatty(fileno(stdin)) && alpm_list_find_str(pm_targets, "-")) { - size_t current_size = PATH_MAX, i = 0; + size_t current_size = PATH_MAX; char *line = malloc(current_size); /* remove the '-' from the list */ pm_targets = alpm_list_remove_str(pm_targets, "-", NULL); + i = 0; while((line[i] = (char)fgetc(stdin)) != EOF) { if(isspace((unsigned char)line[i])) { /* avoid adding zero length arg when multiple spaces separate args */ @@ -885,13 +886,13 @@ int main(int argc, char *argv[]) #endif if(config->verbose > 0) { - alpm_list_t *i; + alpm_list_t *j; printf("Root : %s\n", alpm_option_get_root(config->handle)); printf("Conf File : %s\n", config->configfile); printf("DB Path : %s\n", alpm_option_get_dbpath(config->handle)); printf("Cache Dirs: "); - for(i = alpm_option_get_cachedirs(config->handle); i; i = alpm_list_next(i)) { - printf("%s ", (const char *)i->data); + for(j = alpm_option_get_cachedirs(config->handle); j; j = alpm_list_next(j)) { + printf("%s ", (const char *)j->data); } printf("\n"); printf("Lock File : %s\n", alpm_option_get_lockfile(config->handle)); diff --git a/src/pacman/sync.c b/src/pacman/sync.c index 5165dca1..9c17f45f 100644 --- a/src/pacman/sync.c +++ b/src/pacman/sync.c @@ -307,12 +307,12 @@ static int sync_cleancache(int level) static int sync_synctree(int level, alpm_list_t *syncs) { alpm_list_t *i; - int success = 0, ret; + unsigned int success = 0; for(i = syncs; i; i = alpm_list_next(i)) { alpm_db_t *db = i->data; - ret = alpm_db_update((level < 2 ? 0 : 1), db); + int ret = alpm_db_update((level < 2 ? 0 : 1), db); if(ret < 0) { pm_printf(ALPM_LOG_ERROR, _("failed to update %s (%s)\n"), alpm_db_get_name(db), alpm_strerror(alpm_errno(config->handle))); diff --git a/src/pacman/util.c b/src/pacman/util.c index f2ab163b..be8fc308 100644 --- a/src/pacman/util.c +++ b/src/pacman/util.c @@ -258,7 +258,7 @@ void indentprint(const char *str, unsigned short indent, unsigned short cols) { wchar_t *wcstr; const wchar_t *p; - int len, cidx; + size_t len, cidx; if(!str) { return; |