[pacman-dev] [PATCH 2/2] Avoid false warning from gcc-6

Dave Reisner d at falconindy.com
Wed May 4 13:08:49 UTC 2016


On Wed, May 04, 2016 at 05:42:29PM +1000, Allan McRae wrote:
> The value EAGAIN is allowed by POSIX to be the same as EWOULDBLOCK, but this is
> not guaranteed. Thus on some systems (e.g. glibc Linux), we get a warning that
> the logical OR is being performed on two expressions of the same type. We can
> not get rid of this test in case any system defines these as unique values.
> 
> Use a pragma block to prevent any gcc warning on these tests.
> 
> Signed-off-by: Allan McRae <allan at archlinux.org>
> ---
>  lib/libalpm/util.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c
> index 4a4847d..e105786 100644
> --- a/lib/libalpm/util.c
> +++ b/lib/libalpm/util.c
> @@ -476,7 +476,11 @@ static int _alpm_chroot_write_to_child(alpm_handle_t *handle, int fd,
>  		/* write was successful, remove the written data from the buffer */
>  		*buf_size -= nwrite;
>  		memmove(buf, buf + nwrite, *buf_size);
> +
> +/* EAGAIN may be the same value as EWOULDBLOCK (POSIX.1)  - prevent GCC warning */
> +#pragma GCC diagnostic ignored "-Wlogical-op"
>  	} else if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
> +#pragma GCC diagnostic pop

Instead of repeating this pragma (and the comparison for that matter),
why not just wrap it in a separate function? Something like:

  int should_retry(int errnum) {
    return errnum == EAGAIN
  #if EAGAIN != EWOULDBLOCK
      || errnum == EWOULDBLOCK
  #endif
      || errnum == EINTR;
  }

POSIX requires that constants in errno.h are defined as macros "and
which shall be suitable for use in #if pre-processing directives".

>  		/* nothing written, try again later */
>  	} else {
>  		_alpm_log(handle, ALPM_LOG_ERROR,
> @@ -530,7 +534,11 @@ static int _alpm_chroot_read_from_child(alpm_handle_t *handle, int fd,
>  			_alpm_chroot_process_output(handle, buf);
>  		}
>  		return -1;
> +
> +/* EAGAIN may be the same value as EWOULDBLOCK (POSIX.1) - prevent GCC warning */
> +#pragma GCC diagnostic ignored "-Wlogical-op"
>  	} else if(errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR) {
> +#pragma GCC diagnostic pop
>  		/* nothing read, try again */
>  	} else {
>  		/* read error */
> -- 
> 2.8.2


More information about the pacman-dev mailing list