[pacman-dev] [PATCH 1/2] Fix warnings not usually emitted (CFLAGS not in configure.ac)
-Wbad-function-cast:
* casting long int to pmpkgreason_t unecessarily
* casting pmpkgreason_t to long unecessarily
* casting off_t (signed integral) to float before division
unecessarily
-Wshadow:
* shadowing "handle" variables renamed to "new_handle" and
"local_handle" shadowing "filestr" renamed to "pkgfilestr"
* shadowing "remove" renamed to "remove_pkgs"
* shadowing "sync" renamed to "syncpkg"
* Removed redundant declarations
* shadowing "prefix" renamed to "entry_prefix"
* shadowing "pipe" renamed to "pipe_handle"
-Wconversion:
* explicitely cast nread to size_t from ssize_t in dload.c
(guaranteed not to be negative at this point)
* use size_t, as opposed to int, for string length and byte sizes
* use signed int in alpm_list_count as advertised by API (should
probably be changed to usngiend int or size_t, but requires an API
change)
Signed-off-by: Sebastian Nowicki
Signed-off-by: Sebastian Nowicki
On 13/09/10 00:01, Sebastian Nowicki wrote:
-Wbad-function-cast: * casting long int to pmpkgreason_t unecessarily * casting pmpkgreason_t to long unecessarily * casting off_t (signed integral) to float before division unecessarily
-Wshadow: * shadowing "handle" variables renamed to "new_handle" and "local_handle" shadowing "filestr" renamed to "pkgfilestr" * shadowing "remove" renamed to "remove_pkgs" * shadowing "sync" renamed to "syncpkg" * Removed redundant declarations * shadowing "prefix" renamed to "entry_prefix" * shadowing "pipe" renamed to "pipe_handle"
-Wconversion: * explicitely cast nread to size_t from ssize_t in dload.c (guaranteed not to be negative at this point) * use size_t, as opposed to int, for string length and byte sizes * use signed int in alpm_list_count as advertised by API (should probably be changed to usngiend int or size_t, but requires an API change)
Signed-off-by: Sebastian Nowicki
I tried having a look at this but kept getting lost in what part of the patch fixed what warnings. e.g. I can not find the casting off_t to float change for -Wbad-function-cast. I think it would be much better to split these up a bit more. Splitting by error type would be fine for me.
--- Some of these warnings are quite pedantic and wouldn't really cause issues, so they might not be desired.
The change in alpm_list_count is backwards in my opinion - the API should be changed to use unsigned int (or size_t). I didn't want to change the API though.
I can not see why this ever returned a signed int. Allan
On Wed, Sep 15, 2010 at 8:07 AM, Allan McRae
On 13/09/10 00:01, Sebastian Nowicki wrote:
-Wbad-function-cast: * casting long int to pmpkgreason_t unecessarily * casting pmpkgreason_t to long unecessarily * casting off_t (signed integral) to float before division unecessarily
-Wshadow: * shadowing "handle" variables renamed to "new_handle" and "local_handle" shadowing "filestr" renamed to "pkgfilestr" * shadowing "remove" renamed to "remove_pkgs" * shadowing "sync" renamed to "syncpkg" * Removed redundant declarations * shadowing "prefix" renamed to "entry_prefix" * shadowing "pipe" renamed to "pipe_handle"
-Wconversion: * explicitely cast nread to size_t from ssize_t in dload.c (guaranteed not to be negative at this point) * use size_t, as opposed to int, for string length and byte sizes * use signed int in alpm_list_count as advertised by API (should probably be changed to usngiend int or size_t, but requires an API change)
Signed-off-by: Sebastian Nowicki
I tried having a look at this but kept getting lost in what part of the patch fixed what warnings. e.g. I can not find the casting off_t to float change for -Wbad-function-cast.
I think it would be much better to split these up a bit more. Splitting by error type would be fine for me.
+1; if you could do one patch for each warning that would be awesome. I know it is a bit more work but it makes it a lot easier to see what you've done (as well as prevent it from sneaking in again in the future).
--- Some of these warnings are quite pedantic and wouldn't really cause issues, so they might not be desired.
The change in alpm_list_count is backwards in my opinion - the API should be changed to use unsigned int (or size_t). I didn't want to change the API though.
I can not see why this ever returned a signed int.
This should really be size_t, just like strlen(), etc. If we want to change it in a major version release, we haven't shied away from it in the past, so I'd be for it. In most cases it wouldn't break code or built applications anyway. -Dan
On Sun, Sep 12, 2010 at 9:01 AM, Sebastian Nowicki
Signed-off-by: Sebastian Nowicki
Looks good, thanks!
--- lib/libalpm/package.c | 16 +++++++++++++--- 1 files changed, 13 insertions(+), 3 deletions(-)
diff --git a/lib/libalpm/package.c b/lib/libalpm/package.c index 0060300..717d32c 100644 --- a/lib/libalpm/package.c +++ b/lib/libalpm/package.c @@ -488,12 +488,15 @@ void SYMEXPORT *alpm_pkg_changelog_open(pmpkg_t *pkg)
/** * Read data from an open changelog 'file stream'. Similar to fread in - * functionality, this function takes a buffer and amount of data to read. + * functionality, this function takes a buffer and amount of data to read. If an + * error occurs pm_errno will be set. + * * @param ptr a buffer to fill with raw changelog data * @param size the size of the buffer * @param pkg the package that the changelog is being read from * @param fp a 'file stream' to the package changelog - * @return the number of characters read, or 0 if there is no more data + * @return the number of characters read, or 0 if there is no more data or an + * error occurred. */ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, const pmpkg_t *pkg, const void *fp) @@ -502,7 +505,14 @@ size_t SYMEXPORT alpm_pkg_changelog_read(void *ptr, size_t size, if(pkg->origin == PKG_FROM_CACHE) { ret = fread(ptr, 1, size, (FILE*)fp); } else if(pkg->origin == PKG_FROM_FILE) { - ret = archive_read_data((struct archive*)fp, ptr, size); + ssize_t sret = archive_read_data((struct archive*)fp, ptr, size); + /* Report error (negative values) */ + if(sret < 0) { + pm_errno = PM_ERR_LIBARCHIVE; + ret = 0; + } else { + ret = (size_t)sret; + } } return(ret); } -- 1.7.2.2
The following have been renamed to avoid shadowing:
* conflict.c
- filestr -> pkgfilestr
- remove -> remove_pkgs
* deps.c
- index -> pkg_index
- remove -> remove_pkgs
- time -> epoch
* diskspace.c
- abort -> should_abort
* handle.c
- handle -> local_handle / new_handle
* package.c
- i -> deps
* sync.c (alpm)
- current -> current_pkg
- remove -> remove_pkgs
- ret -> gpg_ret
- sync -> syncpkg
* trans.c
- handle -> local_handle
* util.c (alpm)
- pipe -> pipefh
- prefix -> entry_prefix
* callback.c
- p -> ptr
* util.c (pacman)
- dup -> p
In some instance duplicate declarations were removed.
Signed-off-by: Sebastian Nowicki
On 03/04/11 20:49, Sebastian Nowicki wrote:
The following have been renamed to avoid shadowing:
* conflict.c - filestr -> pkgfilestr - remove -> remove_pkgs * deps.c - index -> pkg_index - remove -> remove_pkgs - time -> epoch * diskspace.c - abort -> should_abort * handle.c - handle -> local_handle / new_handle * package.c - i -> deps * sync.c (alpm) - current -> current_pkg - remove -> remove_pkgs - ret -> gpg_ret - sync -> syncpkg * trans.c - handle -> local_handle * util.c (alpm) - pipe -> pipefh - prefix -> entry_prefix * callback.c - p -> ptr * util.c (pacman) - dup -> p
In some instance duplicate declarations were removed.
Signed-off-by: Sebastian Nowicki
--- This is a follow up for an earlier patch I sent back in December. Apologies for not following up sooner. The feedback was to split the patch up. This is the first patch from the split. The API for alpm_checkdeps is slightly modified (a parameter is renamed). I'm not sure whether this is a backwards incompatible change or not.
Sorry for the size, I don't think it can be split up much further without it turning into a dozen patches.
This patch was generated against the master branch.
lib/libalpm/Makefile.am | 2 +- lib/libalpm/alpm.h | 2 +- lib/libalpm/conflict.c | 8 +++--- lib/libalpm/deps.c | 18 ++++++++-------- lib/libalpm/diskspace.c | 8 +++--- lib/libalpm/dload.c | 6 ++-- lib/libalpm/handle.c | 50 +++++++++++++++++++++++----------------------- lib/libalpm/package.c | 6 ++-- lib/libalpm/sync.c | 37 ++++++++++++++++----------------- lib/libalpm/trans.c | 18 ++++++++-------- lib/libalpm/util.c | 20 +++++++++--------- src/pacman/Makefile.am | 2 +- src/pacman/callback.c | 10 ++++---- src/pacman/query.c | 2 +- src/pacman/sync.c | 4 +-- src/pacman/upgrade.c | 1 - src/pacman/util.c | 14 ++++++------ 17 files changed, 102 insertions(+), 106 deletions(-)
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index fb224a5..21f7057 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -7,7 +7,7 @@ include_HEADERS = alpm_list.h alpm.h
DEFS = -DLOCALEDIR=\"@localedir@\" @DEFS@
-AM_CFLAGS = -pedantic -D_GNU_SOURCE +AM_CFLAGS = -pedantic -Wshadow -D_GNU_SOURCE
I have not gone through all of these changes... I think adding extra warnings etc should be done in configure.ac and only when --enable-debug is specified (as is currently done with stack protector, -Werror etc). But do we really want to add all these warnings in there? I use all of these: -Wclobbered -Wempty-body -Wfloat-equal -Wignored-qualifiers -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wold-style-declaration -Woverride-init -Wsign-compare -Wstrict-prototypes -Wtype-limits -Wuninitialized I'm not sure anybody wants that... Allan
On Mon, Apr 4, 2011 at 7:26 AM, Allan McRae
On 03/04/11 20:49, Sebastian Nowicki wrote:
The following have been renamed to avoid shadowing:
* conflict.c - filestr -> pkgfilestr - remove -> remove_pkgs * deps.c - index -> pkg_index - remove -> remove_pkgs - time -> epoch * diskspace.c - abort -> should_abort * handle.c - handle -> local_handle / new_handle * package.c - i -> deps * sync.c (alpm) - current -> current_pkg - remove -> remove_pkgs - ret -> gpg_ret - sync -> syncpkg * trans.c - handle -> local_handle * util.c (alpm) - pipe -> pipefh - prefix -> entry_prefix * callback.c - p -> ptr * util.c (pacman) - dup -> p
In some instance duplicate declarations were removed.
Signed-off-by: Sebastian Nowicki
--- This is a follow up for an earlier patch I sent back in December. Apologies for not following up sooner. The feedback was to split the patch up. This is the first patch from the split. The API for alpm_checkdeps is slightly modified (a parameter is renamed). I'm not sure whether this is a backwards incompatible change or not.
Sorry for the size, I don't think it can be split up much further without it turning into a dozen patches.
This patch was generated against the master branch.
lib/libalpm/Makefile.am | 2 +- lib/libalpm/alpm.h | 2 +- lib/libalpm/conflict.c | 8 +++--- lib/libalpm/deps.c | 18 ++++++++-------- lib/libalpm/diskspace.c | 8 +++--- lib/libalpm/dload.c | 6 ++-- lib/libalpm/handle.c | 50 +++++++++++++++++++++++----------------------- lib/libalpm/package.c | 6 ++-- lib/libalpm/sync.c | 37 ++++++++++++++++----------------- lib/libalpm/trans.c | 18 ++++++++-------- lib/libalpm/util.c | 20 +++++++++--------- src/pacman/Makefile.am | 2 +- src/pacman/callback.c | 10 ++++---- src/pacman/query.c | 2 +- src/pacman/sync.c | 4 +-- src/pacman/upgrade.c | 1 - src/pacman/util.c | 14 ++++++------ 17 files changed, 102 insertions(+), 106 deletions(-)
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index fb224a5..21f7057 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -7,7 +7,7 @@ include_HEADERS = alpm_list.h alpm.h
DEFS = -DLOCALEDIR=\"@localedir@\" @DEFS@
-AM_CFLAGS = -pedantic -D_GNU_SOURCE +AM_CFLAGS = -pedantic -Wshadow -D_GNU_SOURCE
I have not gone through all of these changes... I think adding extra warnings etc should be done in configure.ac and only when --enable-debug is specified (as is currently done with stack protector, -Werror etc).
But do we really want to add all these warnings in there? I use all of these:
-Wclobbered -Wempty-body -Wfloat-equal -Wignored-qualifiers -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wold-style-declaration -Woverride-init -Wsign-compare -Wstrict-prototypes -Wtype-limits -Wuninitialized
I'm not sure anybody wants that...
Allan
I wasn't going to add it initially, but thought this would prevent shadowing sneaking back in again. I don't really mind either way though.
Allan McRae wrote:
But do we really want to add all these warnings in there? I use all of these:
-Wclobbered -Wempty-body -Wfloat-equal -Wignored-qualifiers -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wold-style-declaration -Woverride-init -Wsign-compare -Wstrict-prototypes -Wtype-limits -Wuninitialized
I'm not sure anybody wants that...
If they pass (or close to), why not ? Developers should follow the same rules to not break something that was respected before and to keep a consistent codebase.
On Sun, Apr 3, 2011 at 6:26 PM, Allan McRae
On 03/04/11 20:49, Sebastian Nowicki wrote:
The following have been renamed to avoid shadowing:
* conflict.c - filestr -> pkgfilestr - remove -> remove_pkgs * deps.c - index -> pkg_index - remove -> remove_pkgs - time -> epoch * diskspace.c - abort -> should_abort * handle.c - handle -> local_handle / new_handle * package.c - i -> deps * sync.c (alpm) - current -> current_pkg - remove -> remove_pkgs - ret -> gpg_ret - sync -> syncpkg * trans.c - handle -> local_handle * util.c (alpm) - pipe -> pipefh - prefix -> entry_prefix * callback.c - p -> ptr * util.c (pacman) - dup -> p
In some instance duplicate declarations were removed.
Signed-off-by: Sebastian Nowicki
--- diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index fb224a5..21f7057 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -7,7 +7,7 @@ include_HEADERS = alpm_list.h alpm.h
DEFS = -DLOCALEDIR=\"@localedir@\" @DEFS@
-AM_CFLAGS = -pedantic -D_GNU_SOURCE +AM_CFLAGS = -pedantic -Wshadow -D_GNU_SOURCE
I have not gone through all of these changes... I think adding extra warnings etc should be done in configure.ac and only when --enable-debug is specified (as is currently done with stack protector, -Werror etc). Yes, this is the only place they belong, definitely not in the Makefile (and only in the libalpm Makefile, why?).
But do we really want to add all these warnings in there? I use all of these:
-Wclobbered -Wempty-body -Wfloat-equal -Wignored-qualifiers -Wmissing-declarations -Wmissing-parameter-type -Wmissing-prototypes -Wold-style-declaration -Woverride-init -Wsign-compare -Wstrict-prototypes -Wtype-limits -Wuninitialized
I'm not sure anybody wants that...
I'm not against it, provided: 1. When it is checked in, the compile doesn't break. 2. When someone uses "exotic" compiliers such as icc, gcc 3.x, whatever Cygwin has, and clang, we don't blow up or make the output that much worse for them. -Dan
On Tue, Apr 5, 2011 at 1:37 PM, Dan McGee
On Sun, Apr 3, 2011 at 6:26 PM, Allan McRae
wrote: On 03/04/11 20:49, Sebastian Nowicki wrote:
diff --git a/lib/libalpm/Makefile.am b/lib/libalpm/Makefile.am index fb224a5..21f7057 100644 --- a/lib/libalpm/Makefile.am +++ b/lib/libalpm/Makefile.am @@ -7,7 +7,7 @@ include_HEADERS = alpm_list.h alpm.h
DEFS = -DLOCALEDIR=\"@localedir@\" @DEFS@
-AM_CFLAGS = -pedantic -D_GNU_SOURCE +AM_CFLAGS = -pedantic -Wshadow -D_GNU_SOURCE
I have not gone through all of these changes... I think adding extra warnings etc should be done in configure.ac and only when --enable-debug is specified (as is currently done with stack protector, -Werror etc). Yes, this is the only place they belong, definitely not in the Makefile (and only in the libalpm Makefile, why?).
It was added to the pacman Makefile as well (later down in the patch), wasn't really sure where to put it since I couldn't find other warning flags (aside from -Wall). I guess I'll just put it in the configure.ac script for now. It can always be removed later if it causes issues. Might even check if icc produces different results.
participants (4)
-
Allan McRae
-
Dan McGee
-
Sebastian Nowicki
-
Xavier