All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.
@ 2022-08-30 19:58 Jakub Wilk
  2022-08-30 20:13 ` Jakub Wilk
  2022-08-30 20:55 ` Alejandro Colomar
  0 siblings, 2 replies; 4+ messages in thread
From: Jakub Wilk @ 2022-08-30 19:58 UTC (permalink / raw)
  To: Michael Kerrisk, Alejandro Colomar; +Cc: linux-man

major() and minor() return unsigned int,
so the typecasts to uintmax_t are not needed.

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:                ");
 
-- 
2.37.2


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.
  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
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Wilk @ 2022-08-30 20:13 UTC (permalink / raw)
  To: Michael Kerrisk, Alejandro Colomar; +Cc: linux-man

Oops, that's not how I wanted the subject to look like.
If it not too much work, please make it s/drop/Drop/ and remove the 
trailing full stop.

-- 
Jakub Wilk

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.
  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:55 ` Alejandro Colomar
  1 sibling, 0 replies; 4+ messages in thread
From: Alejandro Colomar @ 2022-08-30 20:55 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: linux-man, Michael Kerrisk


[-- 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 --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.
  2022-08-30 20:13 ` Jakub Wilk
@ 2022-08-30 20:57   ` Alejandro Colomar
  0 siblings, 0 replies; 4+ messages in thread
From: Alejandro Colomar @ 2022-08-30 20:57 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: linux-man, Michael Kerrisk


[-- Attachment #1.1: Type: text/plain, Size: 332 bytes --]

Hi!

On 8/30/22 22:13, Jakub Wilk wrote:
> Oops, that's not how I wanted the subject to look like.
> If it not too much work, please make it s/drop/Drop/ and remove the 
> trailing full stop.
> 

Sure!  Subject line fixed, and patch applied.

Cheers,

Alex

-- 
Alejandro Colomar
<http://www.alejandro-colomar.es/>

[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 833 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2022-08-30 20:57 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 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.