Re: [PATCH] ioctl_ns.2, stat.2: drop unneeded uintmax_t casts.

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxxxx>
---
  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: OpenPGP_signature
Description: OpenPGP digital signature


[Index of Archives]     [Kernel Documentation]     [Netdev]     [Linux Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux