From: Alejandro Colomar <alx.manpages@gmail.com>
To: Jakub Wilk <jwilk@jwilk.net>
Cc: linux-man@vger.kernel.org, Michael Kerrisk <mtk.manpages@gmail.com>
Subject: Re: [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.
Date: Tue, 30 Aug 2022 22:55:36 +0200 [thread overview]
Message-ID: <594f6315-e431-4624-8474-d0c504783a67@gmail.com> (raw)
In-Reply-To: <20220830195800.1779-1-jwilk@jwilk.net>
[-- Attachment #1.1: Type: text/plain, Size: 2932 bytes --]
Hi Jakub!
On 8/30/22 21:58, Jakub Wilk wrote:
> major() and minor() return unsigned int,
> so the typecasts to uintmax_t are not needed.
I don't remember all of the details. I remember having discussed
exactly this, but can't find it in the archives.
FreeBSD returns signed int <https://www.freebsd.org/cgi/man.cgi?major>.
Linux returns unsigned int. So the type that can hold values in both
types would be intmax_t.
I guess I used uintmax_t because of the %x conversion specifier, which
requires an unsigned number, and so the only issue will be that the
number will be very high if the original value was negative.
Admittedly, if you pass an int to %x, it's going to work in the same way
as uintmax_t is working right now.
It's not clear if that's Undefined Behavior
<https://stackoverflow.com/q/4664100/6872717>, but it's certainly going
to work, so I'll apply your patch.
Thanks,
Alex
>
> Signed-off-by: Jakub Wilk <jwilk@jwilk.net>
> ---
> man2/ioctl_ns.2 | 12 ++++++------
> man2/stat.2 | 6 +++---
> 2 files changed, 9 insertions(+), 9 deletions(-)
>
> diff --git a/man2/ioctl_ns.2 b/man2/ioctl_ns.2
> index 95b39ccac..02c1dab11 100644
> --- a/man2/ioctl_ns.2
> +++ b/man2/ioctl_ns.2
> @@ -293,9 +293,9 @@ main(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
> printf("Device/Inode of owning user namespace is: "
> - "[%jx,%jx] / %ju\en",
> - (uintmax_t) major(sb.st_dev),
> - (uintmax_t) minor(sb.st_dev),
> + "[%x,%x] / %ju\en",
> + major(sb.st_dev),
> + minor(sb.st_dev),
> (uintmax_t) sb.st_ino);
>
> close(userns_fd);
> @@ -323,9 +323,9 @@ main(int argc, char *argv[])
> perror("fstat\-parentns");
> exit(EXIT_FAILURE);
> }
> - printf("Device/Inode of parent namespace is: [%jx,%jx] / %ju\en",
> - (uintmax_t) major(sb.st_dev),
> - (uintmax_t) minor(sb.st_dev),
> + printf("Device/Inode of parent namespace is: [%x,%x] / %ju\en",
> + major(sb.st_dev),
> + minor(sb.st_dev),
> (uintmax_t) sb.st_ino);
>
> close(parent_fd);
> diff --git a/man2/stat.2 b/man2/stat.2
> index 585a20484..bdd6d15e3 100644
> --- a/man2/stat.2
> +++ b/man2/stat.2
> @@ -481,9 +481,9 @@ main(int argc, char *argv[])
> exit(EXIT_FAILURE);
> }
>
> - printf("ID of containing device: [%jx,%jx]\en",
> - (uintmax_t) major(sb.st_dev),
> - (uintmax_t) minor(sb.st_dev));
> + printf("ID of containing device: [%x,%x]\en",
> + major(sb.st_dev),
> + minor(sb.st_dev));
>
> printf("File type: ");
>
--
Alejandro Colomar
<http://www.alejandro-colomar.es/>
[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
prev parent reply other threads:[~2022-08-30 20:55 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-08-30 19:58 [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts Jakub Wilk
2022-08-30 20:13 ` Jakub Wilk
2022-08-30 20:57 ` Alejandro Colomar
2022-08-30 20:55 ` Alejandro Colomar [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=594f6315-e431-4624-8474-d0c504783a67@gmail.com \
--to=alx.manpages@gmail.com \
--cc=jwilk@jwilk.net \
--cc=linux-man@vger.kernel.org \
--cc=mtk.manpages@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.