Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently

Michael Kerrisk (man-pages)
2020-09-04T15:40:43Z

Hello Alex,

On 9/4/20 5:08 PM, Alejandro Colomar wrote:
>>From 63fa45f7c45c49df2eeab0735342de9304507e46 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 22:24:12 +0200
> Subject: [PATCH 34/34] unix.7: 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@gmail.com>
> ---
> man7/unix.7 | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/man7/unix.7 b/man7/unix.7
> index 86a35be7b..30b0e754d 100644

Thanks. Patch applied.

Cheers,

Michael

> --- a/man7/unix.7
> +++ b/man7/unix.7
> @@ -948,7 +948,7 @@ main(int argc, char *argv[])
> * the structure.
> */
>
> - memset(&name, 0, sizeof(struct sockaddr_un));
> + memset(&name, 0, sizeof(name));
>
> /* Bind socket to socket name. */
>
> @@ -956,7 +956,7 @@ main(int argc, char *argv[])
> strncpy(name.sun_path, SOCKET_NAME, sizeof(name.sun_path) \- 1);
>
> ret = bind(connection_socket, (const struct sockaddr *) &name,
> - sizeof(struct sockaddr_un));
> + sizeof(name));
> if (ret == \-1) {
> perror("bind");
> exit(EXIT_FAILURE);
> @@ -1082,7 +1082,7 @@ main(int argc, char *argv[])
> * the structure.
> */
>
> - memset(&addr, 0, sizeof(struct sockaddr_un));
> + memset(&addr, 0, sizeof(addr));
>
> /* Connect socket to socket address */
>
> @@ -1090,7 +1090,7 @@ main(int argc, char *argv[])
> strncpy(addr.sun_path, SOCKET_NAME, sizeof(addr.sun_path) \- 1);
>
> ret = connect(data_socket, (const struct sockaddr *) &addr,
> - sizeof(struct sockaddr_un));
> + sizeof(addr));
> if (ret == \-1) {
> fprintf(stderr, "The server is down.\en");
> exit(EXIT_FAILURE);
>

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