[PATCH v2] Print the package arch using the %a format specifier.

Morgan Adamiec morganamilo at archlinux.org
Mon Sep 27 20:35:31 UTC 2021



On 26/09/2021 14:57, Jonathan Sköld wrote:
> Was pointed out in the IRC channel that package arch may be NULL. Revised the 
> patch to include a NULL check before trying to replace string.
> 
> Signed-off-by: Jonathan Sköld <arch at skold.dev>
> ---
>  src/pacman/util.c | 10 ++++++++++
>  1 file changed, 10 insertions(+)
> 
> diff --git a/src/pacman/util.c b/src/pacman/util.c
> index 5486e7a5..70df6128 100644
> --- a/src/pacman/util.c
> +++ b/src/pacman/util.c
> @@ -1146,6 +1146,16 @@ void print_packages(const alpm_list_t *packages)
>  		alpm_pkg_t *pkg = i->data;
>  		char *string = strdup(config->print_format);
>  		char *temp = string;
> +		/* %a : pkgarch */
> +		if(strstr(temp, "%a")) {
> +			const char *arch = alpm_pkg_get_arch(pkg);
> +			if(arch == NULL) {
> +				arch = "";
> +			}
> +			string = strreplace(temp, "%a", arch);
> +			free(temp);
> +			temp = string;
> +		}
>  		/* %n : pkgname */
>  		if(strstr(temp, "%n")) {
>  			string = strreplace(temp, "%n", alpm_pkg_get_name(pkg));
> 

Looks good to me. Though in future the bit about irc should be a comment
instead of inside the commit message.

You can write --- in the commit message and everything below it will be
a comment when sent as a patch.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: OpenPGP_signature
Type: application/pgp-signature
Size: 840 bytes
Desc: OpenPGP digital signature
URL: <https://lists.archlinux.org/pipermail/pacman-dev/attachments/20210927/3310aa2f/attachment.sig>


More information about the pacman-dev mailing list