[pacman-dev] [PATCH] Signed/unsigned mixup fixup

Xavier shiningxc at gmail.com
Wed Sep 30 02:46:07 EDT 2009


On Wed, Sep 30, 2009 at 5:52 AM, Dan McGee <dan at archlinux.org> wrote:
> After our recent screwup with size_t and ssize_t in the download code, I
> found the `-Wsign-conversion` flag to GCC to see if we were doing anything
> else boneheaded. I didn't find anything quite as bad, but we did have some
> goofups- most of our public unsigned methods would return -1 on error, which
> is a bit odd in an unsigned context.
>
> Signed-off-by: Dan McGee <dan at archlinux.org>

Welcome to typing hell :)

>
> -       pkg_count = alpm_list_count(trans->add);
> +       pkg_count = (int)alpm_list_count(trans->add);
>        pkg_current = 1;
>

There are many changes like that, but I am confused.
In which cases do we use :
int pkgcount = (int)alpm_list_count(list)
and which cases do we use :
unsigned int pkgcount = alpm_list_count(list)
?

>
> -void SYMEXPORT alpm_option_set_usesyslog(unsigned short usesyslog)
> +void SYMEXPORT alpm_option_set_usesyslog(int usesyslog)
>  {
>        handle->usesyslog = usesyslog;
>  }
> @@ -536,7 +545,7 @@ void SYMEXPORT alpm_option_set_arch(const char *arch)
>        if(arch) handle->arch = strdup(arch);
>  }
>
> -void SYMEXPORT alpm_option_set_usedelta(unsigned short usedelta)
> +void SYMEXPORT alpm_option_set_usedelta(int usedelta)
>  {
>        handle->usedelta = usedelta;
>  }

For these two, it should not make much difference right ?
I guess we use them like : if (usesyslog) ... if (usedelta) ...
And if we give a negative values, whether we keep the sign or convert
it to unsigned, in both cases, it will be non-zero, right?

> diff --git a/src/pacman/conf.h b/src/pacman/conf.h
> index 3c588a7..598657c 100644
> --- a/src/pacman/conf.h
> +++ b/src/pacman/conf.h
> @@ -64,7 +64,7 @@ typedef struct __config_t {
>        unsigned short group;
>        pmtransflag_t flags;
>        unsigned short noask;
> -       unsigned int ask;
> +       pmtransprog_t ask;
>

I think unsigned int was right here. Also ask deals with pmtransconv_t
values rather than pmtransprog_t, but it might not be a simple value
of that enum, it can also be an addition of several of them.
Then we do things like :
if (ask & PM_TRANS_CONV_REMOVE_PKGS) ...
(instead of ask == ...)

Also the user can always enter any values he wants on the command
line, but we can't really control that.

I didn't understand or try to understand all the changes, this typing
stuff has always annoyed me :P


More information about the pacman-dev mailing list