Re: [PATCH (2) 03/34] eventfd.2: Use sizeof consistently

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

 



Hello Alex,

On 9/4/20 12:21 PM, Alejandro Colomar wrote:
>>From 5399e0a620c417c1003c17fb04a45ce1a7854acd Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx>
> Date: Thu, 3 Sep 2020 21:25:59 +0200
> Subject: [PATCH 03/34] eventfd.2: Use sizeof consistently
> 
> Use ``sizeof`` consistently through all the examples in the following
> way:
> 
> - Use the name of the variable instead of its type as argument for
>   ``sizeof``.
> 
> 	Rationale:
> 	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory
> 
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@xxxxxxxxx>
> ---
>  man2/eventfd.2 | 8 ++++----
>  1 file changed, 4 insertions(+), 4 deletions(-)
> 
> diff --git a/man2/eventfd.2 b/man2/eventfd.2
> index 804cf796b..35e83c957 100644
> --- a/man2/eventfd.2
> +++ b/man2/eventfd.2
> @@ -415,8 +415,8 @@ main(int argc, char *argv[])
>              printf("Child writing %s to efd\en", argv[j]);
>              u = strtoull(argv[j], NULL, 0);
>                      /* strtoull() allows various bases */
> -            s = write(efd, &u, sizeof(uint64_t));
> -            if (s != sizeof(uint64_t))
> +            s = write(efd, &u, sizeof(u));
> +            if (s != sizeof(u))
>                  handle_error("write");
>          }
>          printf("Child completed write loop\en");
> @@ -427,8 +427,8 @@ main(int argc, char *argv[])
>          sleep(2);
> 
>          printf("Parent about to read\en");
> -        s = read(efd, &u, sizeof(uint64_t));
> -        if (s != sizeof(uint64_t))
> +        s = read(efd, &u, sizeof(u));
> +        if (s != sizeof(u))
>              handle_error("read");
>          printf("Parent read %llu (0x%llx) from efd\en",
>                  (unsigned long long) u, (unsigned long long) u);
> 

This is an example where I am dubious that the change is a
good idea. For this API, the units that are being read/written
really *must* be 8-byte integers (it's baked into the API),
and I feel that explicitly mentioning the types in the example
code reinforces that point.

For the moment, I won't apply this patch.

Cheers,

Michael

-- 
Michael Kerrisk
Linux man-pages maintainer; http://www.kernel.org/doc/man-pages/
Linux/UNIX System Programming Training: http://man7.org/training/



[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