All of lore.kernel.org
 help / color / mirror / Atom feed
* [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
@ 2020-08-24 13:29 Alejandro Colomar
  2020-08-25 10:29 ` Michael Kerrisk (man-pages)
  2020-09-05 14:20 ` [PATCH 35/35] qsort.3: " Alejandro Colomar
  0 siblings, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-08-24 13:29 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man

From 5df5cae0fb6973df0ab8b3629934f808487112b0 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Fri, 21 Aug 2020 16:58:12 +0200
Subject: [PATCH] memusage.1, bind.2, eventfd.2, futex.2,
open_by_handle_at.2,
 perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2,
bsearch.3,
 cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3,
 malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3,
 pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3,
 tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently

Use ``sizeof`` consistently through all the examples, in the following
way:

- Never use a space after ``sizeof``, and always use parentheses
  instead.

	Rationale:

	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces

- Use the name of the variable instead of the type as argument
  for ``sizeof``, wherever possible.

	Rationale:

	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

- When the result of ``sizeof`` is multiplied (or otherwise modified),
  write ``sizeof`` in the first place.

	Rationale:

	``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.

	``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
	results.

	As a side effect, the parentheses of ``sizeof`` are not next to
	the parentheses of the whole expression, and it is visually
	easier to read.

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man1/memusage.1               | 12 ++++++------
 man2/bind.2                   |  6 +++---
 man2/eventfd.2                |  8 ++++----
 man2/futex.2                  |  2 +-
 man2/open_by_handle_at.2      |  4 ++--
 man2/perf_event_open.2        |  6 +++---
 man2/poll.2                   |  2 +-
 man2/signalfd.2               |  4 ++--
 man2/sysctl.2                 |  2 +-
 man2/timerfd_create.2         |  4 ++--
 man3/bsearch.3                |  4 ++--
 man3/cmsg.3                   |  6 +++---
 man3/getaddrinfo.3            |  6 +++---
 man3/getaddrinfo_a.3          |  2 +-
 man3/getgrouplist.3           |  2 +-
 man3/insque.3                 |  2 +-
 man3/malloc_info.3            |  2 +-
 man3/mbsinit.3                |  2 +-
 man3/mbstowcs.3               |  2 +-
 man3/pthread_create.3         |  2 +-
 man3/pthread_setaffinity_np.3 |  4 ++--
 man3/queue.3                  | 32 ++++++++++++++++----------------
 man3/rtnetlink.3              |  4 ++--
 man3/shm_open.3               |  4 ++--
 man3/strptime.3               |  2 +-
 man3/tsearch.3                |  2 +-
 man7/aio.7                    |  4 ++--
 man7/fanotify.7               |  3 +--
 man7/inotify.7                |  6 +++---
 man7/unix.7                   |  8 ++++----
 30 files changed, 74 insertions(+), 75 deletions(-)

diff --git a/man1/memusage.1 b/man1/memusage.1
index fa1987c79..a03468442 100644
--- a/man1/memusage.1
+++ b/man1/memusage.1
@@ -247,8 +247,8 @@ main(int argc, char *argv[])
      int i, j;
      int *p;

-     printf("malloc: %zd\en", sizeof(int) * 100);
-     p = malloc(sizeof(int) * 100);
+     printf("malloc: %zd\en", sizeof(*p) * 100);
+     p = malloc(sizeof(*p) * 100);

      for (i = 0; i < CYCLES; i++) {
          if (i < CYCLES / 2)
@@ -256,11 +256,11 @@ main(int argc, char *argv[])
          else
              j--;

-         printf("realloc: %zd\en", sizeof(int) * (j * 50 + 110));
-         p = realloc(p, sizeof(int) * (j * 50 + 100));
+         printf("realloc: %zd\en", sizeof(*p) * (j * 50 + 110));
+         p = realloc(p, sizeof(*p) * (j * 50 + 100));

-         printf("realloc: %zd\en", sizeof(int) * ((j+1) * 150 + 110));
-         p = realloc(p, sizeof(int) * ((j + 1) * 150 + 110));
+         printf("realloc: %zd\en", sizeof(*p) * ((j+1) * 150 + 110));
+         p = realloc(p, sizeof(*p) * ((j + 1) * 150 + 110));
      }

      free(p);
diff --git a/man2/bind.2 b/man2/bind.2
index 72aac9555..74e34b6bd 100644
--- a/man2/bind.2
+++ b/man2/bind.2
@@ -293,14 +293,14 @@ main(int argc, char *argv[])
     if (sfd == \-1)
         handle_error("socket");

-    memset(&my_addr, 0, sizeof(struct sockaddr_un));
+    memset(&my_addr, 0, sizeof(my_addr));
                         /* Clear structure */
     my_addr.sun_family = AF_UNIX;
     strncpy(my_addr.sun_path, MY_SOCK_PATH,
             sizeof(my_addr.sun_path) \- 1);

     if (bind(sfd, (struct sockaddr *) &my_addr,
-            sizeof(struct sockaddr_un)) == \-1)
+            sizeof(my_addr)) == \-1)
         handle_error("bind");

     if (listen(sfd, LISTEN_BACKLOG) == \-1)
@@ -309,7 +309,7 @@ main(int argc, char *argv[])
     /* Now we can accept incoming connections one
        at a time using accept(2) */

-    peer_addr_size = sizeof(struct sockaddr_un);
+    peer_addr_size = sizeof(peer_addr);
     cfd = accept(sfd, (struct sockaddr *) &peer_addr,
                  &peer_addr_size);
     if (cfd == \-1)
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);
diff --git a/man2/futex.2 b/man2/futex.2
index 05696f617..6192b145a 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -1839,7 +1839,7 @@ main(int argc, char *argv[])
        subsequently use the "shared" futex operations (i.e., not the
        ones suffixed "_PRIVATE") */

-    iaddr = mmap(NULL, sizeof(int) * 2, PROT_READ | PROT_WRITE,
+    iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
                 MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
     if (iaddr == MAP_FAILED)
         errExit("mmap");
diff --git a/man2/open_by_handle_at.2 b/man2/open_by_handle_at.2
index 78c3220f8..846957acf 100644
--- a/man2/open_by_handle_at.2
+++ b/man2/open_by_handle_at.2
@@ -586,7 +586,7 @@ main(int argc, char *argv[])

     /* Reallocate file_handle structure with correct size */

-    fhsize = sizeof(struct file_handle) + fhp\->handle_bytes;
+    fhsize = sizeof(*fhp) + fhp\->handle_bytes;
     fhp = realloc(fhp, fhsize);         /* Copies fhp\->handle_bytes */
     if (fhp == NULL)
         errExit("realloc");
@@ -707,7 +707,7 @@ main(int argc, char *argv[])

     /* Given handle_bytes, we can now allocate file_handle structure */

-    fhp = malloc(sizeof(struct file_handle) + handle_bytes);
+    fhp = malloc(sizeof(*fhp) + handle_bytes);
     if (fhp == NULL)
         errExit("malloc");

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index 2492fc75a..aea825706 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -3419,9 +3419,9 @@ main(int argc, char **argv)
     long long count;
     int fd;

-    memset(&pe, 0, sizeof(struct perf_event_attr));
+    memset(&pe, 0, sizeof(pe));
     pe.type = PERF_TYPE_HARDWARE;
-    pe.size = sizeof(struct perf_event_attr);
+    pe.size = sizeof(pe);
     pe.config = PERF_COUNT_HW_INSTRUCTIONS;
     pe.disabled = 1;
     pe.exclude_kernel = 1;
@@ -3439,7 +3439,7 @@ main(int argc, char **argv)
     printf("Measuring instruction count for this printf\en");

     ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
-    read(fd, &count, sizeof(long long));
+    read(fd, &count, sizeof(count));

     printf("Used %lld instructions\en", count);

diff --git a/man2/poll.2 b/man2/poll.2
index 940c51da5..9b42822c0 100644
--- a/man2/poll.2
+++ b/man2/poll.2
@@ -596,7 +596,7 @@ main(int argc, char *argv[])
     }

     num_open_fds = nfds = argc \- 1;
-    pfds = calloc(nfds, sizeof(struct pollfd));
+    pfds = calloc(nfds, sizeof(*pfds));
     if (pfds == NULL)
         errExit("malloc");

diff --git a/man2/signalfd.2 b/man2/signalfd.2
index 96d502a50..92e9fd7ef 100644
--- a/man2/signalfd.2
+++ b/man2/signalfd.2
@@ -502,8 +502,8 @@ main(int argc, char *argv[])
         handle_error("signalfd");

     for (;;) {
-        s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
-        if (s != sizeof(struct signalfd_siginfo))
+        s = read(sfd, &fdsi, sizeof(fdsi));
+        if (s != sizeof(fdsi))
             handle_error("read");

         if (fdsi.ssi_signo == SIGINT) {
diff --git a/man2/sysctl.2 b/man2/sysctl.2
index 65f79516d..161060490 100644
--- a/man2/sysctl.2
+++ b/man2/sysctl.2
@@ -154,7 +154,7 @@ main(void)
     size_t osnamelth;
     int name[] = { CTL_KERN, KERN_OSTYPE };

-    memset(&args, 0, sizeof(struct __sysctl_args));
+    memset(&args, 0, sizeof(args));
     args.name = name;
     args.nlen = sizeof(name)/sizeof(name[0]);
     args.oldval = osname;
diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
index 67a13dba3..fd4acf3e9 100644
--- a/man2/timerfd_create.2
+++ b/man2/timerfd_create.2
@@ -700,8 +700,8 @@ main(int argc, char *argv[])
     printf("timer started\en");

     for (tot_exp = 0; tot_exp < max_exp;) {
-        s = read(fd, &exp, sizeof(uint64_t));
-        if (s != sizeof(uint64_t))
+        s = read(fd, &exp, sizeof(exp));
+        if (s != sizeof(exp))
             handle_error("read");

         tot_exp += exp;
diff --git a/man3/bsearch.3 b/man3/bsearch.3
index 88e0e6ea1..6859bdba2 100644
--- a/man3/bsearch.3
+++ b/man3/bsearch.3
@@ -124,12 +124,12 @@ main(int argc, char **argv)
 {
     int i;

-    qsort(months, nr_of_months, sizeof(struct mi), compmi);
+    qsort(months, nr_of_months, sizeof(months[0]), compmi);
     for (i = 1; i < argc; i++) {
         struct mi key, *res;
         key.name = argv[i];
         res = bsearch(&key, months, nr_of_months,
-                      sizeof(struct mi), compmi);
+                      sizeof(months[0]), compmi);
         if (res == NULL)
             printf("\(aq%s\(aq: unknown month\en", argv[i]);
         else
diff --git a/man3/cmsg.3 b/man3/cmsg.3
index 2f9910093..8d0ad6666 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -203,7 +203,7 @@ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
         cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
     if (cmsg\->cmsg_level == IPPROTO_IP
             && cmsg\->cmsg_type == IP_TTL) {
-        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(int));
+        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(received_ttl));
         break;
     }
 }
@@ -241,8 +241,8 @@ msg.msg_controllen = sizeof(u.buf);
 cmsg = CMSG_FIRSTHDR(&msg);
 cmsg\->cmsg_level = SOL_SOCKET;
 cmsg\->cmsg_type = SCM_RIGHTS;
-cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
-memcpy(CMSG_DATA(cmsg), myfds, NUM_FD * sizeof(int));
+cmsg\->cmsg_len = CMSG_LEN(sizeof(myfds));
+memcpy(CMSG_DATA(cmsg), myfds, sizeof(myfds));
 .EE
 .in
 .SH SEE ALSO
diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 8aa544789..70e6b4cc0 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -679,7 +679,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
@@ -721,7 +721,7 @@ main(int argc, char *argv[])
     /* Read datagrams and echo them back to sender */

     for (;;) {
-        peer_addr_len = sizeof(struct sockaddr_storage);
+        peer_addr_len = sizeof(peer_addr);
         nread = recvfrom(sfd, buf, BUF_SIZE, 0,
                 (struct sockaddr *) &peer_addr, &peer_addr_len);
         if (nread == \-1)
@@ -775,7 +775,7 @@ main(int argc, char *argv[])

     /* Obtain address(es) matching host/port */

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = 0;
diff --git a/man3/getaddrinfo_a.3 b/man3/getaddrinfo_a.3
index af8f88937..cd4cad0dc 100644
--- a/man3/getaddrinfo_a.3
+++ b/man3/getaddrinfo_a.3
@@ -473,7 +473,7 @@ add_requests(void)

     while ((host = strtok(NULL, " "))) {
         nreqs++;
-        reqs = realloc(reqs, nreqs * sizeof(reqs[0]));
+        reqs = realloc(reqs, sizeof(reqs[0]) * nreqs);

         reqs[nreqs \- 1] = calloc(1, sizeof(*reqs[0]));
         reqs[nreqs \- 1]\->ar_name = strdup(host);
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 61c88f75f..ff8d89e3f 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -164,7 +164,7 @@ main(int argc, char *argv[])

     ngroups = atoi(argv[2]);

-    groups = malloc(ngroups * sizeof (gid_t));
+    groups = malloc(sizeof(*groups) * ngroups);
     if (groups == NULL) {
         perror("malloc");
         exit(EXIT_FAILURE);
diff --git a/man3/insque.3 b/man3/insque.3
index a9fc28550..005ad8cc1 100644
--- a/man3/insque.3
+++ b/man3/insque.3
@@ -182,7 +182,7 @@ new_element(void)
 {
     struct element *e;

-    e = malloc(sizeof(struct element));
+    e = malloc(sizeof(*e));
     if (e == NULL) {
         fprintf(stderr, "malloc() failed\en");
         exit(EXIT_FAILURE);
diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
index 0d95cdff7..598478dcc 100644
--- a/man3/malloc_info.3
+++ b/man3/malloc_info.3
@@ -226,7 +226,7 @@ main(int argc, char *argv[])
     blockSize = atoi(argv[3]);
     sleepTime = (argc > 4) ? atoi(argv[4]) : 0;

-    thr = calloc(numThreads, sizeof(pthread_t));
+    thr = calloc(numThreads, sizeof(*thr));
     if (thr == NULL)
         errExit("calloc");

diff --git a/man3/mbsinit.3 b/man3/mbsinit.3
index 663f9d9ed..74fe48f86 100644
--- a/man3/mbsinit.3
+++ b/man3/mbsinit.3
@@ -59,7 +59,7 @@ in initial state is to set it to zero:
 .in +4n
 .EX
 mbstate_t state;
-memset(&state,0,sizeof(mbstate_t));
+memset(&state, 0, sizeof(state));
 .EE
 .in
 .PP
diff --git a/man3/mbstowcs.3 b/man3/mbstowcs.3
index cf650506e..2f9fbc17c 100644
--- a/man3/mbstowcs.3
+++ b/man3/mbstowcs.3
@@ -186,7 +186,7 @@ main(int argc, char *argv[])
     /* Allocate wide character string of the desired size.  Add 1
        to allow for terminating null wide character (L\(aq\e0\(aq). */

-    wcs = calloc(mbslen + 1, sizeof(wchar_t));
+    wcs = calloc(mbslen + 1, sizeof(*wcs));
     if (wcs == NULL) {
         perror("calloc");
         exit(EXIT_FAILURE);
diff --git a/man3/pthread_create.3 b/man3/pthread_create.3
index d86188e6b..5ffb14586 100644
--- a/man3/pthread_create.3
+++ b/man3/pthread_create.3
@@ -361,7 +361,7 @@ main(int argc, char *argv[])

     /* Allocate memory for pthread_create() arguments */

-    tinfo = calloc(num_threads, sizeof(struct thread_info));
+    tinfo = calloc(num_threads, sizeof(*tinfo));
     if (tinfo == NULL)
         handle_error("calloc");

diff --git a/man3/pthread_setaffinity_np.3 b/man3/pthread_setaffinity_np.3
index 24499f550..57aaf1251 100644
--- a/man3/pthread_setaffinity_np.3
+++ b/man3/pthread_setaffinity_np.3
@@ -194,13 +194,13 @@ main(int argc, char *argv[])
     for (j = 0; j < 8; j++)
         CPU_SET(j, &cpuset);

-    s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+    s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
     if (s != 0)
         handle_error_en(s, "pthread_setaffinity_np");

     /* Check the actual affinity mask assigned to the thread */

-    s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+    s = pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset);
     if (s != 0)
         handle_error_en(s, "pthread_getaffinity_np");

diff --git a/man3/queue.3 b/man3/queue.3
index 070ca47cb..0131fe09b 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -558,10 +558,10 @@ struct entry {

 SLIST_INIT(&head);			/* Initialize the list. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 SLIST_INSERT_HEAD(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 SLIST_INSERT_AFTER(n1, n2, entries);

 SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */
@@ -774,13 +774,13 @@ struct entry {

 STAILQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 STAILQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 STAILQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 STAILQ_INSERT_AFTER(&head, n1, n2, entries);
 					/* Deletion. */
 STAILQ_REMOVE(&head, n2, entry, entries);
@@ -974,13 +974,13 @@ struct entry {

 LIST_INIT(&head);			/* Initialize the list. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 LIST_INSERT_HEAD(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 LIST_INSERT_AFTER(n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 LIST_INSERT_BEFORE(n2, n3, entries);

 LIST_REMOVE(n2, entries);		/* Deletion. */
@@ -1232,16 +1232,16 @@ struct entry {

 TAILQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 TAILQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 TAILQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 TAILQ_INSERT_AFTER(&head, n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 TAILQ_INSERT_BEFORE(n2, n3, entries);

 TAILQ_REMOVE(&head, n2, entries);	/* Deletion. */
@@ -1425,16 +1425,16 @@ struct entry {

 CIRCLEQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 CIRCLEQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 CIRCLEQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);

 CIRCLEQ_REMOVE(&head, n2, entries);	/* Deletion. */
diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
index 07bb1fbf9..f8b6c255a 100644
--- a/man3/rtnetlink.3
+++ b/man3/rtnetlink.3
@@ -105,7 +105,7 @@ unsigned int mtu = 1000;
 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);

 memset(&req, 0, sizeof(req));
-req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
 req.nh.nlmsg_flags = NLM_F_REQUEST;
 req.nh.nlmsg_type = RTM_NEWLINK;
 req.if.ifi_family = AF_UNSPEC;
@@ -114,7 +114,7 @@ req.if.ifi_change = 0xffffffff; /* ??? */
 rta = (struct rtattr *)(((char *) &req) +
                          NLMSG_ALIGN(req.nh.nlmsg_len));
 rta\->rta_type = IFLA_MTU;
-rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
+rta\->rta_len = RTA_LENGTH(sizeof(mtu));
 req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
                               RTA_LENGTH(sizeof(mtu));
 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
diff --git a/man3/shm_open.3 b/man3/shm_open.3
index bba4eb826..24cc6a403 100644
--- a/man3/shm_open.3
+++ b/man3/shm_open.3
@@ -382,7 +382,7 @@ main(int argc, char *argv[])

     /* Map the object into the caller\(aqs address space */

-    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
+    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
                                PROT_READ | PROT_WRITE,
                                MAP_SHARED, fd, 0);
     if (shmp == MAP_FAILED)
@@ -471,7 +471,7 @@ main(int argc, char *argv[])
     if (fd == \-1)
         errExit("shm_open");

-    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
+    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
                                PROT_READ | PROT_WRITE,
                                MAP_SHARED, fd, 0);
     if (shmp == MAP_FAILED)
diff --git a/man3/strptime.3 b/man3/strptime.3
index d12f298ff..ab7d76f9a 100644
--- a/man3/strptime.3
+++ b/man3/strptime.3
@@ -429,7 +429,7 @@ main(void)
     struct tm tm;
     char buf[255];

-    memset(&tm, 0, sizeof(struct tm));
+    memset(&tm, 0, sizeof(tm));
     strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
     strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
     puts(buf);
diff --git a/man3/tsearch.3 b/man3/tsearch.3
index 452395d6b..f0ff80e8c 100644
--- a/man3/tsearch.3
+++ b/man3/tsearch.3
@@ -327,7 +327,7 @@ main(void)

     srand(time(NULL));
     for (i = 0; i < 12; i++) {
-        ptr = xmalloc(sizeof(int));
+        ptr = xmalloc(sizeof(*ptr));
         *ptr = rand() & 0xff;
         val = tsearch((void *) ptr, &root, compare);
         if (val == NULL)
diff --git a/man7/aio.7 b/man7/aio.7
index dd05dce83..d3ab3f422 100644
--- a/man7/aio.7
+++ b/man7/aio.7
@@ -311,11 +311,11 @@ main(int argc, char *argv[])

     /* Allocate our arrays */

-    ioList = calloc(numReqs, sizeof(struct ioRequest));
+    ioList = calloc(numReqs, sizeof(*ioList));
     if (ioList == NULL)
         errExit("calloc");

-    aiocbList = calloc(numReqs, sizeof(struct aiocb));
+    aiocbList = calloc(numReqs, sizeof(*aiocbList));
     if (aiocbList == NULL)
         errExit("calloc");

diff --git a/man7/fanotify.7 b/man7/fanotify.7
index a7d60b2b9..29c818027 100644
--- a/man7/fanotify.7
+++ b/man7/fanotify.7
@@ -808,8 +808,7 @@ handle_events(int fd)

                     response.fd = metadata\->fd;
                     response.response = FAN_ALLOW;
-                    write(fd, &response,
-                          sizeof(struct fanotify_response));
+                    write(fd, &response, sizeof(response));
                 }

                 /* Handle closing of writable file event */
diff --git a/man7/inotify.7 b/man7/inotify.7
index e60d9c82b..f1a1667e3 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -952,7 +952,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])

         /* Read some events. */

-        len = read(fd, buf, sizeof buf);
+        len = read(fd, buf, sizeof(buf));
         if (len == \-1 && errno != EAGAIN) {
             perror("read");
             exit(EXIT_FAILURE);
@@ -968,7 +968,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
         /* Loop over all events in the buffer */

         for (ptr = buf; ptr < buf + len;
-                ptr += sizeof(struct inotify_event) + event\->len) {
+                ptr += sizeof(*event) + event\->len) {

             event = (const struct inotify_event *) ptr;

@@ -1031,7 +1031,7 @@ main(int argc, char* argv[])

     /* Allocate memory for watch descriptors */

-    wd = calloc(argc, sizeof(int));
+    wd = calloc(argc, sizeof(*wd));
     if (wd == NULL) {
         perror("calloc");
         exit(EXIT_FAILURE);
diff --git a/man7/unix.7 b/man7/unix.7
index 5283a1e58..ac01ff712 100644
--- 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);
-- 
2.28.0

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-24 13:29 [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently Alejandro Colomar
@ 2020-08-25 10:29 ` Michael Kerrisk (man-pages)
  2020-08-25 11:19   ` Jakub Wilk
  2020-09-05 14:20 ` [PATCH 35/35] qsort.3: " Alejandro Colomar
  1 sibling, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-08-25 10:29 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man

Hello Alex,

On 8/24/20 3:29 PM, Alejandro Colomar wrote:
>>From 5df5cae0fb6973df0ab8b3629934f808487112b0 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Fri, 21 Aug 2020 16:58:12 +0200
> Subject: [PATCH] memusage.1, bind.2, eventfd.2, futex.2,
> open_by_handle_at.2,
>  perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2,
> bsearch.3,
>  cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3,
>  malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3,
>  pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3,
>  tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
> 
> Use ``sizeof`` consistently through all the examples, in the following
> way:

I would really have preferred three patches here, since:

> - Never use a space after ``sizeof``, and always use parentheses
>   instead.
> 
> 	Rationale:
> 
> 	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces

(1) This is completely unproblematic from my point of view.

> - Use the name of the variable instead of the type as argument
>   for ``sizeof``, wherever possible.
> 
> 	Rationale:
> 
> 	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory

(2) This one is up for debate. In many cases it makes sense to do
this. However, there are cases where I think that using the struct
name can actually help readability. And when I grep through the kernel
source, of around 139k lines that use "sizeof", some 37k take a 'struct type'
as an argument. SI, I think this kind of change may need to be considered on
a case by case basis, rather than as a blanket change.
 
> - When the result of ``sizeof`` is multiplied (or otherwise modified),
>   write ``sizeof`` in the first place.
> 
> 	Rationale:
> 
> 	``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
> 
> 	``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
> 	results.

(3) Is this true? "gcc -Wall" does not complain about this. And, I
thought that in both cases, all operands in the expression
would be promoted to the largest type. And, on my x86-64 system,

sizeof((sizeof(x) * INT_MAX * 2)) == 8
sizeof(INT_MAX * 2 * sizeof(x)) == 8

But, I will say tht I'm not a language lawyer, and C still
sometimes has surprises for me. At the least, I'd like to know
more about this point.

Thanks,

Michael



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

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 10:29 ` Michael Kerrisk (man-pages)
@ 2020-08-25 11:19   ` Jakub Wilk
  2020-08-25 11:34     ` Alejandro Colomar
  2020-08-25 11:35     ` [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: " Michael Kerrisk (man-pages)
  0 siblings, 2 replies; 92+ messages in thread
From: Jakub Wilk @ 2020-08-25 11:19 UTC (permalink / raw)
  To: Michael Kerrisk; +Cc: Alejandro Colomar, linux-man

[-- Attachment #1: Type: text/plain, Size: 799 bytes --]

* Michael Kerrisk <mtk.manpages@gmail.com>, 2020-08-25, 12:29:
>> 	``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
>>
>> 	``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
>> 	results.
>
>(3) Is this true? "gcc -Wall" does not complain about this.

My GCC (10.2.0) does, even without -Wall:

   $ gcc test-overflow.c
   test-overflow.c: In function 'main':
   test-overflow.c:8:52: warning: integer overflow in expression of type 'int' results in '-2' [-Woverflow]
       8 |  printf("INT_MAX * 2 * sizeof(x) = %zu\n", INT_MAX * 2 * sizeof(x));
         |                                                    ^

>sizeof((sizeof(x) * INT_MAX * 2)) == 8
>sizeof(INT_MAX * 2 * sizeof(x)) == 8

Hmm? If there was no overflow, surely you should get a number larger 
than INT_MAX...

-- 
Jakub Wilk

[-- Attachment #2: test-overflow.c --]
[-- Type: text/x-csrc, Size: 229 bytes --]

#include <stdio.h>
#include <limits.h>

int main(int arg, char **argv)
{
	typedef int x;
	printf("sizeof(x) * INT_MAX * 2 = %zu\n", sizeof(x) * INT_MAX * 2);
	printf("INT_MAX * 2 * sizeof(x) = %zu\n", INT_MAX * 2 * sizeof(x));
}

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 11:19   ` Jakub Wilk
@ 2020-08-25 11:34     ` Alejandro Colomar
  2020-08-25 11:41       ` Michael Kerrisk (man-pages)
  2020-08-25 11:35     ` [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: " Michael Kerrisk (man-pages)
  1 sibling, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-08-25 11:34 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: Michael Kerrisk (man-pages), linux-man

Hello Michael & Jakub,

On 8/25/20 12:29 PM, Michael Kerrisk (man-pages) wrote:
> I would really have preferred three patches here, since:

I can do that.

>
>> - Never use a space after ``sizeof``, and always use parentheses
>>   instead.
>>
>> 	Rationale:
>>
>> 	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces
>
> (1) This is completely unproblematic from my point of view.

Actually there was only one appearance of that (and another one that
used a space before the parentheses).  It's unproblematic, but it's so
minor that it can be fixed easily.

>> - Use the name of the variable instead of the type as argument
>>   for ``sizeof``, wherever possible.
>>
>> 	Rationale:
>>
>>
https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory
>
> (2) This one is up for debate. In many cases it makes sense to do
> this. However, there are cases where I think that using the struct
> name can actually help readability. And when I grep through the kernel
> source, of around 139k lines that use "sizeof", some 37k take a
'struct type'
> as an argument. SI, I think this kind of change may need to be
considered on
> a case by case basis, rather than as a blanket change.

Ok. I can send a set of patches with a patch for each page.

>
>> - When the result of ``sizeof`` is multiplied (or otherwise modified),
>>   write ``sizeof`` in the first place.
>>
>> 	Rationale:
>>
>> 	``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
>>
>> 	``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
>> 	results.
>
> (3) Is this true? "gcc -Wall" does not complain about this. And, I
> thought that in both cases, all operands in the expression
> would be promoted to the largest type. And, on my x86-64 system,
>
> sizeof((sizeof(x) * INT_MAX * 2)) == 8
> sizeof(INT_MAX * 2 * sizeof(x)) == 8
>
> But, I will say tht I'm not a language lawyer, and C still
> sometimes has surprises for me. At the least, I'd like to know
> more about this point.

Well, when I said the first one doesn't overflow, I meant it's much
less likely.

In C, successive multiplications are evaluated left to right (*), and
therefore here is what happens:

``(sizeof(x) * INT_MAX * 2)``:

1) sizeof(x) * INT_MAX	(the type is the largest of both, which is
			 size_t (unsigned long; uint64_t)).
2) ANS * 2		(the type is again the largest: size_t)

``(INT_MAX * 2 * sizeof(x))``:

1) INT_MAX * 2		(the type is the largest of both, which is
			 int as both are int (int; int32_t), so the
			 result is already truncated as it doesn't fit
			 an int; at this point, the intermediate result
			 will be 2^32 - 2 (``INT_MAX - 1``) (if I did
			 the math right)).
2) ANS * 2		(the type is again the largest of both: size_t;
			 however, ANS was already incorrect, so the
			 result will be an incorrect size_t value)

> sizeof((sizeof(x) * INT_MAX * 2)) == 8

Here you were overflowing a uint64_t (if x were a char, it would not
overflow, and the result would be close to UINT64_MAX).

> sizeof(INT_MAX * 2 * sizeof(x)) == 8

Here you were overflowing int32_t, and it would overflow regardless of
sizeof(x).


I wrote an extreme case, but we can agree that 32 bit is much easier to
overflow than 64.


(*): https://en.cppreference.com/w/c/language/operator_precedence


On 8/25/20 1:19 PM, Jakub Wilk wrote:
> * Michael Kerrisk <mtk.manpages@gmail.com>, 2020-08-25, 12:29:
>>>     ``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
>>>
>>>     ``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
>>>     results.
>>
>> (3) Is this true? "gcc -Wall" does not complain about this.
>
> My GCC (10.2.0) does, even without -Wall:
>
>   $ gcc test-overflow.c
>   test-overflow.c: In function 'main':
>   test-overflow.c:8:52: warning: integer overflow in expression of type
> 'int' results in '-2' [-Woverflow]
>       8 |  printf("INT_MAX * 2 * sizeof(x) = %zu\n", INT_MAX * 2 *
> sizeof(x));
>         |                                                    ^
I guess it will only complain for the first one, doesn't it?

>
>> sizeof((sizeof(x) * INT_MAX * 2)) == 8
>> sizeof(INT_MAX * 2 * sizeof(x)) == 8
>
> Hmm? If there was no overflow, surely you should get a number larger
> than INT_MAX...
>

INT_MAX is INT32_MAX, and given that size_t is 64 bit, sure we can, but
only in the first case.

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 11:19   ` Jakub Wilk
  2020-08-25 11:34     ` Alejandro Colomar
@ 2020-08-25 11:35     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-08-25 11:35 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: Alejandro Colomar, linux-man

Hi Jakub,

Once again, thanks for jumping in...

On Tue, 25 Aug 2020 at 13:19, Jakub Wilk <jwilk@jwilk.net> wrote:
>
> * Michael Kerrisk <mtk.manpages@gmail.com>, 2020-08-25, 12:29:
> >>      ``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
> >>
> >>      ``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
> >>      results.
> >
> >(3) Is this true? "gcc -Wall" does not complain about this.
>
> My GCC (10.2.0) does, even without -Wall:
>
>    $ gcc test-overflow.c
>    test-overflow.c: In function 'main':
>    test-overflow.c:8:52: warning: integer overflow in expression of type 'int' results in '-2' [-Woverflow]
>        8 |  printf("INT_MAX * 2 * sizeof(x) = %zu\n", INT_MAX * 2 * sizeof(x));
>          |                                                    ^
>
> >sizeof((sizeof(x) * INT_MAX * 2)) == 8
> >sizeof(INT_MAX * 2 * sizeof(x)) == 8
>
> Hmm? If there was no overflow, surely you should get a number larger
> than INT_MAX...

Yes, I goofed :-(. There is no compiler warning for "sizeof(INT_MAX *
2 * sizeof(x))", which is what I tested, but as you point out, there
is a warning for "INT_MAX * 2 * sizeof(x)".

Thanks,

Michael

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

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 11:34     ` Alejandro Colomar
@ 2020-08-25 11:41       ` Michael Kerrisk (man-pages)
  2020-08-25 11:48         ` Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-08-25 11:41 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: Jakub Wilk, linux-man

Hello Alex,

On Tue, 25 Aug 2020 at 13:34, Alejandro Colomar <colomar.6.4.3@gmail.com> wrote:
>
> Hello Michael & Jakub,
>
> On 8/25/20 12:29 PM, Michael Kerrisk (man-pages) wrote:
> > I would really have preferred three patches here, since:
>
> I can do that.
>
> >
> >> - Never use a space after ``sizeof``, and always use parentheses
> >>   instead.
> >>
> >>      Rationale:
> >>
> >>      https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces
> >
> > (1) This is completely unproblematic from my point of view.
>
> Actually there was only one appearance of that (and another one that
> used a space before the parentheses).  It's unproblematic, but it's so
> minor that it can be fixed easily.
>
> >> - Use the name of the variable instead of the type as argument
> >>   for ``sizeof``, wherever possible.
> >>
> >>      Rationale:
> >>
> >>
> https://www.kernel.org/doc/html/v5.8/process/coding-style.html#allocating-memory
> >
> > (2) This one is up for debate. In many cases it makes sense to do
> > this. However, there are cases where I think that using the struct
> > name can actually help readability. And when I grep through the kernel
> > source, of around 139k lines that use "sizeof", some 37k take a
> 'struct type'
> > as an argument. SI, I think this kind of change may need to be
> considered on
> > a case by case basis, rather than as a blanket change.
>
> Ok. I can send a set of patches with a patch for each page.

Okay. Don't do them all at once, since we may change strategy while
discussing the first few patches.

> >> - When the result of ``sizeof`` is multiplied (or otherwise modified),
> >>   write ``sizeof`` in the first place.
> >>
> >>      Rationale:
> >>
> >>      ``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
> >>
> >>      ``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
> >>      results.
> >
> > (3) Is this true? "gcc -Wall" does not complain about this. And, I
> > thought that in both cases, all operands in the expression
> > would be promoted to the largest type. And, on my x86-64 system,
> >
> > sizeof((sizeof(x) * INT_MAX * 2)) == 8
> > sizeof(INT_MAX * 2 * sizeof(x)) == 8
> >
> > But, I will say tht I'm not a language lawyer, and C still
> > sometimes has surprises for me. At the least, I'd like to know
> > more about this point.
>
> Well, when I said the first one doesn't overflow, I meant it's much
> less likely.
>
> In C, successive multiplications are evaluated left to right (*), and
> therefore here is what happens:
>
> ``(sizeof(x) * INT_MAX * 2)``:
>
> 1) sizeof(x) * INT_MAX  (the type is the largest of both, which is
>                          size_t (unsigned long; uint64_t)).
> 2) ANS * 2              (the type is again the largest: size_t)
>
> ``(INT_MAX * 2 * sizeof(x))``:
>
> 1) INT_MAX * 2          (the type is the largest of both, which is
>                          int as both are int (int; int32_t), so the
>                          result is already truncated as it doesn't fit
>                          an int; at this point, the intermediate result
>                          will be 2^32 - 2 (``INT_MAX - 1``) (if I did
>                          the math right)).
> 2) ANS * 2              (the type is again the largest of both: size_t;
>                          however, ANS was already incorrect, so the
>                          result will be an incorrect size_t value)
>
> > sizeof((sizeof(x) * INT_MAX * 2)) == 8
>
> Here you were overflowing a uint64_t (if x were a char, it would not
> overflow, and the result would be close to UINT64_MAX).
>
> > sizeof(INT_MAX * 2 * sizeof(x)) == 8
>
> Here you were overflowing int32_t, and it would overflow regardless of
> sizeof(x).

Thanks for the lesson in C basics. I clearly did need a refresher :-}.

You and Jakub are of course correct.

If you send the patches in the order (as I numbered in my previous reply):

(1)
(3)
(2) as multiple pieces

that would be best, since the first two patches should obviously be
applied, and then we can discuss the last patch(es) case by case.

Thanks,

Michael

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 11:41       ` Michael Kerrisk (man-pages)
@ 2020-08-25 11:48         ` Alejandro Colomar
  2020-08-25 12:21           ` Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-08-25 11:48 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Jakub Wilk, linux-man

Hi Michael,

On 8/25/20 1:41 PM, Michael Kerrisk (man-pages) wrote:

>> In C, successive multiplications are evaluated left to right (*), and
>> therefore here is what happens:
>>
>> ``(sizeof(x) * INT_MAX * 2)``:
>>
>> 1) sizeof(x) * INT_MAX  (the type is the largest of both, which is
>>                          size_t (unsigned long; uint64_t)).
>> 2) ANS * 2              (the type is again the largest: size_t)
>>
>> ``(INT_MAX * 2 * sizeof(x))``:
>>
>> 1) INT_MAX * 2          (the type is the largest of both, which is
>>                          int as both are int (int; int32_t), so the
>>                          result is already truncated as it doesn't fit
>>                          an int; at this point, the intermediate result
>>                          will be 2^32 - 2 (``INT_MAX - 1``) (if I did
>>                          the math right)).
>> 2) ANS * 2              (the type is again the largest of both: size_t;
>>                          however, ANS was already incorrect, so the
>>                          result will be an incorrect size_t value)
>>
>>> sizeof((sizeof(x) * INT_MAX * 2)) == 8
>>
>> Here you were overflowing a uint64_t (if x were a char, it would not
>> overflow, and the result would be close to UINT64_MAX).

I also goofed :)  I didn't see the sizeof applying to everything.
And I was wrong:  you aren't overflowing 64 bits, which would need x to
be enormous.  But the idea is there; the explanation above was right.

>>
>>> sizeof(INT_MAX * 2 * sizeof(x)) == 8
>>
>> Here you were overflowing int32_t, and it would overflow regardless of
>> sizeof(x).
>
> Thanks for the lesson in C basics. I clearly did need a refresher :-}.

You're welcome!  It happens me from time to time too. :)

>
> You and Jakub are of course correct.
>
> If you send the patches in the order (as I numbered in my previous reply):
>
> (1)
> (3)
> (2) as multiple pieces
>
> that would be best, since the first two patches should obviously be
> applied, and then we can discuss the last patch(es) case by case.

Ok.

>
> Thanks,
>
> Michael
>

Cheers,
Alex.

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 11:48         ` Alejandro Colomar
@ 2020-08-25 12:21           ` Alejandro Colomar
  2020-08-25 12:35             ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-08-25 12:21 UTC (permalink / raw)
  To: mtk.manpages; +Cc: Jakub Wilk, linux-man

This is the patch for (1) as numbered in the previous replies:

-----------------------------------------------------------------------
From b0880bd0485d9abc93bcb3055342ec328240b7cf Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Tue, 25 Aug 2020 14:14:21 +0200
Subject: [PATCH] getgrouplist.3, inotify.7: Use sizeof consistently

Use ``sizeof`` consistently through all the examples in the following
way:

- Never use a space after ``sizeof``, and always use parentheses around
  the argument.

	Rationale:

	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/getgrouplist.3 | 2 +-
 man7/inotify.7      | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 61c88f75f..aea52d999 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -164,7 +164,7 @@ main(int argc, char *argv[])

     ngroups = atoi(argv[2]);

-    groups = malloc(ngroups * sizeof (gid_t));
+    groups = malloc(ngroups * sizeof(gid_t));
     if (groups == NULL) {
         perror("malloc");
         exit(EXIT_FAILURE);
diff --git a/man7/inotify.7 b/man7/inotify.7
index e60d9c82b..9b2d7a4e5 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -952,7 +952,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])

         /* Read some events. */

-        len = read(fd, buf, sizeof buf);
+        len = read(fd, buf, sizeof(buf));
         if (len == \-1 && errno != EAGAIN) {
             perror("read");
             exit(EXIT_FAILURE);
-- 
2.28.0

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

* Re: [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently
  2020-08-25 12:21           ` Alejandro Colomar
@ 2020-08-25 12:35             ` Michael Kerrisk (man-pages)
  2020-08-25 13:05               ` [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof, consistently Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-08-25 12:35 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, Jakub Wilk, linux-man

Hi Alex,

On 8/25/20 2:21 PM, Alejandro Colomar wrote:
> This is the patch for (1) as numbered in the previous replies:
> 
> -----------------------------------------------------------------------
>>From b0880bd0485d9abc93bcb3055342ec328240b7cf Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Tue, 25 Aug 2020 14:14:21 +0200
> Subject: [PATCH] getgrouplist.3, inotify.7: Use sizeof consistently
> 
> Use ``sizeof`` consistently through all the examples in the following
> way:
> 
> - Never use a space after ``sizeof``, and always use parentheses around
>   the argument.
> 
> 	Rationale:
> 
> 	https://www.kernel.org/doc/html/v5.8/process/coding-style.html#spaces


Patch applied, but I had to fix up the title line, which got taken
from the mail subject line. Probably best to send subsequent patches
as new mails, rather than as replies to this thread.

Thanks,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/getgrouplist.3 | 2 +-
>  man7/inotify.7      | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
> index 61c88f75f..aea52d999 100644
> --- a/man3/getgrouplist.3
> +++ b/man3/getgrouplist.3
> @@ -164,7 +164,7 @@ main(int argc, char *argv[])
> 
>      ngroups = atoi(argv[2]);
> 
> -    groups = malloc(ngroups * sizeof (gid_t));
> +    groups = malloc(ngroups * sizeof(gid_t));
>      if (groups == NULL) {
>          perror("malloc");
>          exit(EXIT_FAILURE);
> diff --git a/man7/inotify.7 b/man7/inotify.7
> index e60d9c82b..9b2d7a4e5 100644
> --- a/man7/inotify.7
> +++ b/man7/inotify.7
> @@ -952,7 +952,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
> 
>          /* Read some events. */
> 
> -        len = read(fd, buf, sizeof buf);
> +        len = read(fd, buf, sizeof(buf));
>          if (len == \-1 && errno != EAGAIN) {
>              perror("read");
>              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/

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

* [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof, consistently
  2020-08-25 12:35             ` Michael Kerrisk (man-pages)
@ 2020-08-25 13:05               ` Alejandro Colomar
  2020-08-26  6:21                 ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-08-25 13:05 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

Hi Michael,

On 8/25/20 2:35 PM, Michael Kerrisk (man-pages) wrote:
> Patch applied, but I had to fix up the title line, which got taken
> from the mail subject line. Probably best to send subsequent patches
> as new mails, rather than as replies to this thread.

This time I replied to the thread (so that the conversation can be
followed in the archive), but changed the subject.  I hope that works.

(I sent this email only to you by accident; I'm sending it again with
the CCs).

Patch (3) as numbered in the previous replies:

--------------------------------------------------------------------
From 1cb973629d94a048c5dcbe13fef76173f99dc3de Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Tue, 25 Aug 2020 14:52:03 +0200
Subject: [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof
 consistently

Use ``sizeof`` consistently through all the examples in the following
way:

- When the result of ``sizeof`` is multiplied (or otherwise modified),
  write ``sizeof`` in the first place.

Rationale:

``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.

``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
results.

As a side effect, the parentheses of ``sizeof`` are not next to
the parentheses of the whole expression, and it is visually
easier to read.

Detailed rationale:

In C, successive multiplications are evaluated left to right (*), and
therefore here is what happens (assuming x86_64):

``(sizeof(x) * INT_MAX * 2)``:

1) sizeof(x) * INT_MAX	(the type is the largest of both, which is
			 size_t (unsigned long; uint64_t)).
2) ANS * 2		(the type is again the largest: size_t)

``(INT_MAX * 2 * sizeof(x))``:

1) INT_MAX * 2		(the type is the largest of both, which is
			 int as both are int (int; int32_t), so the
			 result is already truncated as it doesn't fit
			 an int; at this point, the intermediate result
			 will be 2^32 - 2 (``INT_MAX - 1``) (if I did
			 the math right)).
2) ANS * 2		(the type is again the largest of both: size_t;
			 however, ANS was already incorrect, so the
			 result will be an incorrect size_t value)

(*):	https://en.cppreference.com/w/c/language/operator_precedence

Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
---
 man3/cmsg.3          | 2 +-
 man3/getaddrinfo_a.3 | 2 +-
 man3/getgrouplist.3  | 2 +-
 3 files changed, 3 insertions(+), 3 deletions(-)

diff --git a/man3/cmsg.3 b/man3/cmsg.3
index 2f9910093..99ee950f9 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -242,7 +242,7 @@ cmsg = CMSG_FIRSTHDR(&msg);
 cmsg\->cmsg_level = SOL_SOCKET;
 cmsg\->cmsg_type = SCM_RIGHTS;
 cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
-memcpy(CMSG_DATA(cmsg), myfds, NUM_FD * sizeof(int));
+memcpy(CMSG_DATA(cmsg), myfds, sizeof(int) * NUM_FD);
 .EE
 .in
 .SH SEE ALSO
diff --git a/man3/getaddrinfo_a.3 b/man3/getaddrinfo_a.3
index af8f88937..cd4cad0dc 100644
--- a/man3/getaddrinfo_a.3
+++ b/man3/getaddrinfo_a.3
@@ -473,7 +473,7 @@ add_requests(void)

     while ((host = strtok(NULL, " "))) {
         nreqs++;
-        reqs = realloc(reqs, nreqs * sizeof(reqs[0]));
+        reqs = realloc(reqs, sizeof(reqs[0]) * nreqs);

         reqs[nreqs \- 1] = calloc(1, sizeof(*reqs[0]));
         reqs[nreqs \- 1]\->ar_name = strdup(host);
diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index aea52d999..372f2613f 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -164,7 +164,7 @@ main(int argc, char *argv[])

     ngroups = atoi(argv[2]);

-    groups = malloc(ngroups * sizeof(gid_t));
+    groups = malloc(sizeof(gid_t) * ngroups);
     if (groups == NULL) {
         perror("malloc");
         exit(EXIT_FAILURE);
-- 
2.28.0

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

* Re: [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof, consistently
  2020-08-25 13:05               ` [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof, consistently Alejandro Colomar
@ 2020-08-26  6:21                 ` Michael Kerrisk (man-pages)
  2020-09-03 10:23                   ` [PATCH] memusage.1: Use sizeof consistently Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-08-26  6:21 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 8/25/20 3:05 PM, Alejandro Colomar wrote:
> Hi Michael,
> 
> On 8/25/20 2:35 PM, Michael Kerrisk (man-pages) wrote:
>> Patch applied, but I had to fix up the title line, which got taken
>> from the mail subject line. Probably best to send subsequent patches
>> as new mails, rather than as replies to this thread.
> 
> This time I replied to the thread (so that the conversation can be
> followed in the archive), but changed the subject.  I hope that works.
> 
> (I sent this email only to you by accident; I'm sending it again with
> the CCs).
> 
> Patch (3) as numbered in the previous replies:
> 
> --------------------------------------------------------------------
>>From 1cb973629d94a048c5dcbe13fef76173f99dc3de Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Tue, 25 Aug 2020 14:52:03 +0200
> Subject: [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof
>  consistently
> 
> Use ``sizeof`` consistently through all the examples in the following
> way:
> 
> - When the result of ``sizeof`` is multiplied (or otherwise modified),
>   write ``sizeof`` in the first place.
> 
> Rationale:
> 
> ``(sizeof(x) * INT_MAX * 2)`` doesn't overflow.
> 
> ``(INT_MAX * 2 * sizeof(x))`` overflows, giving incorrect
> results.
> 
> As a side effect, the parentheses of ``sizeof`` are not next to
> the parentheses of the whole expression, and it is visually
> easier to read.
> 
> Detailed rationale:
> 
> In C, successive multiplications are evaluated left to right (*), and
> therefore here is what happens (assuming x86_64):
> 
> ``(sizeof(x) * INT_MAX * 2)``:
> 
> 1) sizeof(x) * INT_MAX	(the type is the largest of both, which is
> 			 size_t (unsigned long; uint64_t)).
> 2) ANS * 2		(the type is again the largest: size_t)
> 
> ``(INT_MAX * 2 * sizeof(x))``:
> 
> 1) INT_MAX * 2		(the type is the largest of both, which is
> 			 int as both are int (int; int32_t), so the
> 			 result is already truncated as it doesn't fit
> 			 an int; at this point, the intermediate result
> 			 will be 2^32 - 2 (``INT_MAX - 1``) (if I did
> 			 the math right)).
> 2) ANS * 2		(the type is again the largest of both: size_t;
> 			 however, ANS was already incorrect, so the
> 			 result will be an incorrect size_t value)
> 
> (*):	https://en.cppreference.com/w/c/language/operator_precedence
> 
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>

Thanks! Patch applied.

Cheers,

Michael

> ---
>  man3/cmsg.3          | 2 +-
>  man3/getaddrinfo_a.3 | 2 +-
>  man3/getgrouplist.3  | 2 +-
>  3 files changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/man3/cmsg.3 b/man3/cmsg.3
> index 2f9910093..99ee950f9 100644
> --- a/man3/cmsg.3
> +++ b/man3/cmsg.3
> @@ -242,7 +242,7 @@ cmsg = CMSG_FIRSTHDR(&msg);
>  cmsg\->cmsg_level = SOL_SOCKET;
>  cmsg\->cmsg_type = SCM_RIGHTS;
>  cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
> -memcpy(CMSG_DATA(cmsg), myfds, NUM_FD * sizeof(int));
> +memcpy(CMSG_DATA(cmsg), myfds, sizeof(int) * NUM_FD);
>  .EE
>  .in
>  .SH SEE ALSO
> diff --git a/man3/getaddrinfo_a.3 b/man3/getaddrinfo_a.3
> index af8f88937..cd4cad0dc 100644
> --- a/man3/getaddrinfo_a.3
> +++ b/man3/getaddrinfo_a.3
> @@ -473,7 +473,7 @@ add_requests(void)
> 
>      while ((host = strtok(NULL, " "))) {
>          nreqs++;
> -        reqs = realloc(reqs, nreqs * sizeof(reqs[0]));
> +        reqs = realloc(reqs, sizeof(reqs[0]) * nreqs);
> 
>          reqs[nreqs \- 1] = calloc(1, sizeof(*reqs[0]));
>          reqs[nreqs \- 1]\->ar_name = strdup(host);
> diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
> index aea52d999..372f2613f 100644
> --- a/man3/getgrouplist.3
> +++ b/man3/getgrouplist.3
> @@ -164,7 +164,7 @@ main(int argc, char *argv[])
> 
>      ngroups = atoi(argv[2]);
> 
> -    groups = malloc(ngroups * sizeof(gid_t));
> +    groups = malloc(sizeof(gid_t) * ngroups);
>      if (groups == NULL) {
>          perror("malloc");
>          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/

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

* [PATCH] memusage.1: Use sizeof consistently
  2020-08-26  6:21                 ` Michael Kerrisk (man-pages)
@ 2020-09-03 10:23                   ` Alejandro Colomar
  2020-09-04  8:20                     ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-03 10:23 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

Hi Michael,

Continuing with the series, this is the first of the last set of
patches: (2).1 as numbered in previous emails.

Regards,
Alex.

------------------------------------------------------------------------
From ad5f958ed68079791d6e35f9d70ca5ec2a72c43b Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 12:11:18 +0200
Subject: [PATCH] memusage.1: 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>
---
 man1/memusage.1 | 12 ++++++------
 1 file changed, 6 insertions(+), 6 deletions(-)

diff --git a/man1/memusage.1 b/man1/memusage.1
index fa1987c79..a03468442 100644
--- a/man1/memusage.1
+++ b/man1/memusage.1
@@ -247,8 +247,8 @@ main(int argc, char *argv[])
      int i, j;
      int *p;

-     printf("malloc: %zd\en", sizeof(int) * 100);
-     p = malloc(sizeof(int) * 100);
+     printf("malloc: %zd\en", sizeof(*p) * 100);
+     p = malloc(sizeof(*p) * 100);

      for (i = 0; i < CYCLES; i++) {
          if (i < CYCLES / 2)
@@ -256,11 +256,11 @@ main(int argc, char *argv[])
          else
              j--;

-         printf("realloc: %zd\en", sizeof(int) * (j * 50 + 110));
-         p = realloc(p, sizeof(int) * (j * 50 + 100));
+         printf("realloc: %zd\en", sizeof(*p) * (j * 50 + 110));
+         p = realloc(p, sizeof(*p) * (j * 50 + 100));

-         printf("realloc: %zd\en", sizeof(int) * ((j+1) * 150 + 110));
-         p = realloc(p, sizeof(int) * ((j + 1) * 150 + 110));
+         printf("realloc: %zd\en", sizeof(*p) * ((j+1) * 150 + 110));
+         p = realloc(p, sizeof(*p) * ((j + 1) * 150 + 110));
      }

      free(p);
-- 
2.28.0

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

* Re: [PATCH] memusage.1: Use sizeof consistently
  2020-09-03 10:23                   ` [PATCH] memusage.1: Use sizeof consistently Alejandro Colomar
@ 2020-09-04  8:20                     ` Michael Kerrisk (man-pages)
  2020-09-04 10:19                       ` [PATCH (2) 02/34] bind.2: " Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04  8:20 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/3/20 12:23 PM, Alejandro Colomar wrote:
> Hi Michael,
> 
> Continuing with the series, this is the first of the last set of
> patches: (2).1 as numbered in previous emails.


I must admit that I don't care too much either way on this.
That is to say, I'm not sure one way is any clearer than
the other. However, I have applied the patch.

In passing, I note that there is a clarity issue that I do
find more significant though: the repeated calculations in
the malloc() and printf() calls. So I changed that:
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=15fc4aab1f22c2d4f62ab7f74bbb844942708633

Thanks,

Michael

> ------------------------------------------------------------------------
>>From ad5f958ed68079791d6e35f9d70ca5ec2a72c43b Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 12:11:18 +0200
> Subject: [PATCH] memusage.1: 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>
> ---
>  man1/memusage.1 | 12 ++++++------
>  1 file changed, 6 insertions(+), 6 deletions(-)
> 
> diff --git a/man1/memusage.1 b/man1/memusage.1
> index fa1987c79..a03468442 100644
> --- a/man1/memusage.1
> +++ b/man1/memusage.1
> @@ -247,8 +247,8 @@ main(int argc, char *argv[])
>       int i, j;
>       int *p;
> 
> -     printf("malloc: %zd\en", sizeof(int) * 100);
> -     p = malloc(sizeof(int) * 100);
> +     printf("malloc: %zd\en", sizeof(*p) * 100);
> +     p = malloc(sizeof(*p) * 100);
> 
>       for (i = 0; i < CYCLES; i++) {
>           if (i < CYCLES / 2)
> @@ -256,11 +256,11 @@ main(int argc, char *argv[])
>           else
>               j--;
> 
> -         printf("realloc: %zd\en", sizeof(int) * (j * 50 + 110));
> -         p = realloc(p, sizeof(int) * (j * 50 + 100));
> +         printf("realloc: %zd\en", sizeof(*p) * (j * 50 + 110));
> +         p = realloc(p, sizeof(*p) * (j * 50 + 100));
> 
> -         printf("realloc: %zd\en", sizeof(int) * ((j+1) * 150 + 110));
> -         p = realloc(p, sizeof(int) * ((j + 1) * 150 + 110));
> +         printf("realloc: %zd\en", sizeof(*p) * ((j+1) * 150 + 110));
> +         p = realloc(p, sizeof(*p) * ((j + 1) * 150 + 110));
>       }
> 
>       free(p);
> 


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

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

* [PATCH (2) 02/34] bind.2: Use sizeof consistently
  2020-09-04  8:20                     ` Michael Kerrisk (man-pages)
@ 2020-09-04 10:19                       ` Alejandro Colomar
  2020-09-04 10:21                         ` [PATCH (2) 03/34] eventfd.2: " Alejandro Colomar
  2020-09-04 10:44                         ` [PATCH (2) 02/34] bind.2: " Michael Kerrisk (man-pages)
  0 siblings, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:19 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

Hello Michael,

On 9/4/20 10:20 AM, Michael Kerrisk (man-pages) wrote:
> I must admit that I don't care too much either way on this.
> That is to say, I'm not sure one way is any clearer than
> the other. However, I have applied the patch.

There are places where I wouldn't say there are any readability
benefits.  However, there are functions such as malloc() or memset(),
where using the type could lead to future bugs, so IMHO it's better to
just be consistent and use always the name, unless there are clear
readability problems (or other problems).

In the end, someone thought it to be important enough to write it in the
kernel coding style.

I don't expect all of these patches to be applied, as I had doubts when
writing some of them, but we can discuss those where it is better to
keep the type.

>
> In passing, I note that there is a clarity issue that I do
> find more significant though: the repeated calculations in
> the malloc() and printf() calls. So I changed that:
>
https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=15fc4aab1f22c2d4f62ab7f74bbb844942708633

:)

Cheers,
Alex

------------------------------------------------------------------------
From 54016160b603454fbe4f38d6a81886a03fe2ffdf Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:24:43 +0200
Subject: [PATCH 02/34] bind.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@gmail.com>
---
 man2/bind.2 | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/man2/bind.2 b/man2/bind.2
index 72aac9555..74e34b6bd 100644
--- a/man2/bind.2
+++ b/man2/bind.2
@@ -293,14 +293,14 @@ main(int argc, char *argv[])
     if (sfd == \-1)
         handle_error("socket");

-    memset(&my_addr, 0, sizeof(struct sockaddr_un));
+    memset(&my_addr, 0, sizeof(my_addr));
                         /* Clear structure */
     my_addr.sun_family = AF_UNIX;
     strncpy(my_addr.sun_path, MY_SOCK_PATH,
             sizeof(my_addr.sun_path) \- 1);

     if (bind(sfd, (struct sockaddr *) &my_addr,
-            sizeof(struct sockaddr_un)) == \-1)
+            sizeof(my_addr)) == \-1)
         handle_error("bind");

     if (listen(sfd, LISTEN_BACKLOG) == \-1)
@@ -309,7 +309,7 @@ main(int argc, char *argv[])
     /* Now we can accept incoming connections one
        at a time using accept(2) */

-    peer_addr_size = sizeof(struct sockaddr_un);
+    peer_addr_size = sizeof(peer_addr);
     cfd = accept(sfd, (struct sockaddr *) &peer_addr,
                  &peer_addr_size);
     if (cfd == \-1)
-- 
2.28.0

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

* [PATCH (2) 03/34] eventfd.2: Use sizeof consistently
  2020-09-04 10:19                       ` [PATCH (2) 02/34] bind.2: " Alejandro Colomar
@ 2020-09-04 10:21                         ` Alejandro Colomar
  2020-09-04 10:46                           ` Michael Kerrisk (man-pages)
  2020-09-04 10:54                           ` [PATCH (2) 04/34] futex.2: " Alejandro Colomar
  2020-09-04 10:44                         ` [PATCH (2) 02/34] bind.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:21 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 5399e0a620c417c1003c17fb04a45ce1a7854acd Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
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@gmail.com>
---
 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);
-- 
2.28.0

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

* Re: [PATCH (2) 02/34] bind.2: Use sizeof consistently
  2020-09-04 10:19                       ` [PATCH (2) 02/34] bind.2: " Alejandro Colomar
  2020-09-04 10:21                         ` [PATCH (2) 03/34] eventfd.2: " Alejandro Colomar
@ 2020-09-04 10:44                         ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 10:44 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 12:19 PM, Alejandro Colomar wrote:
> Hello Michael,
> 
> On 9/4/20 10:20 AM, Michael Kerrisk (man-pages) wrote:
>> I must admit that I don't care too much either way on this.
>> That is to say, I'm not sure one way is any clearer than
>> the other. However, I have applied the patch.
> 
> There are places where I wouldn't say there are any readability
> benefits.  However, there are functions such as malloc() or memset(),
> where using the type could lead to future bugs, so IMHO it's better to
> just be consistent and use always the name, unless there are clear
> readability problems (or other problems).
> 
> In the end, someone thought it to be important enough to write it in the
> kernel coding style.
> 
> I don't expect all of these patches to be applied, as I had doubts when
> writing some of them, but we can discuss those where it is better to
> keep the type.
> 
>>
>> In passing, I note that there is a clarity issue that I do
>> find more significant though: the repeated calculations in
>> the malloc() and printf() calls. So I changed that:
>>
> https://git.kernel.org/pub/scm/docs/man-pages/man-pages.git/commit/?id=15fc4aab1f22c2d4f62ab7f74bbb844942708633

Patch applied.

Cheers,

Michael


> ------------------------------------------------------------------------
>>From 54016160b603454fbe4f38d6a81886a03fe2ffdf Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:24:43 +0200
> Subject: [PATCH 02/34] bind.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@gmail.com>
> ---
>  man2/bind.2 | 6 +++---
>  1 file changed, 3 insertions(+), 3 deletions(-)
> 
> diff --git a/man2/bind.2 b/man2/bind.2
> index 72aac9555..74e34b6bd 100644
> --- a/man2/bind.2
> +++ b/man2/bind.2
> @@ -293,14 +293,14 @@ main(int argc, char *argv[])
>      if (sfd == \-1)
>          handle_error("socket");
> 
> -    memset(&my_addr, 0, sizeof(struct sockaddr_un));
> +    memset(&my_addr, 0, sizeof(my_addr));
>                          /* Clear structure */
>      my_addr.sun_family = AF_UNIX;
>      strncpy(my_addr.sun_path, MY_SOCK_PATH,
>              sizeof(my_addr.sun_path) \- 1);
> 
>      if (bind(sfd, (struct sockaddr *) &my_addr,
> -            sizeof(struct sockaddr_un)) == \-1)
> +            sizeof(my_addr)) == \-1)
>          handle_error("bind");
> 
>      if (listen(sfd, LISTEN_BACKLOG) == \-1)
> @@ -309,7 +309,7 @@ main(int argc, char *argv[])
>      /* Now we can accept incoming connections one
>         at a time using accept(2) */
> 
> -    peer_addr_size = sizeof(struct sockaddr_un);
> +    peer_addr_size = sizeof(peer_addr);
>      cfd = accept(sfd, (struct sockaddr *) &peer_addr,
>                   &peer_addr_size);
>      if (cfd == \-1)
> 


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

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

* Re: [PATCH (2) 03/34] eventfd.2: Use sizeof consistently
  2020-09-04 10:21                         ` [PATCH (2) 03/34] eventfd.2: " Alejandro Colomar
@ 2020-09-04 10:46                           ` Michael Kerrisk (man-pages)
  2020-09-04 10:54                           ` [PATCH (2) 04/34] futex.2: " Alejandro Colomar
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 10:46 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

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@gmail.com>
> 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@gmail.com>
> ---
>  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/

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

* [PATCH (2) 04/34] futex.2: Use sizeof consistently
  2020-09-04 10:21                         ` [PATCH (2) 03/34] eventfd.2: " Alejandro Colomar
  2020-09-04 10:46                           ` Michael Kerrisk (man-pages)
@ 2020-09-04 10:54                           ` Alejandro Colomar
  2020-09-04 10:55                             ` [PATCH (2) 05/34] open_by_handle_at.2: " Alejandro Colomar
  2020-09-04 12:19                             ` [PATCH (2) 04/34] futex.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:54 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 21cd85c6f11390c71ed4475f1f9d55910891cf23 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:27:01 +0200
Subject: [PATCH 04/34] futex.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@gmail.com>
---
 man2/futex.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man2/futex.2 b/man2/futex.2
index 05696f617..6192b145a 100644
--- a/man2/futex.2
+++ b/man2/futex.2
@@ -1839,7 +1839,7 @@ main(int argc, char *argv[])
        subsequently use the "shared" futex operations (i.e., not the
        ones suffixed "_PRIVATE") */

-    iaddr = mmap(NULL, sizeof(int) * 2, PROT_READ | PROT_WRITE,
+    iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
                 MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
     if (iaddr == MAP_FAILED)
         errExit("mmap");
-- 
2.28.0

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

* [PATCH (2) 05/34] open_by_handle_at.2: Use sizeof consistently
  2020-09-04 10:54                           ` [PATCH (2) 04/34] futex.2: " Alejandro Colomar
@ 2020-09-04 10:55                             ` Alejandro Colomar
  2020-09-04 10:56                               ` [PATCH (2) 06/34] perf_event_open.2: " Alejandro Colomar
  2020-09-04 12:20                               ` [PATCH (2) 05/34] open_by_handle_at.2: " Michael Kerrisk (man-pages)
  2020-09-04 12:19                             ` [PATCH (2) 04/34] futex.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:55 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 0176a7981aead1a202d5d0295b074e165b0d39dd Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:27:55 +0200
Subject: [PATCH 05/34] open_by_handle_at.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@gmail.com>
---
 man2/open_by_handle_at.2 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man2/open_by_handle_at.2 b/man2/open_by_handle_at.2
index 78c3220f8..846957acf 100644
--- a/man2/open_by_handle_at.2
+++ b/man2/open_by_handle_at.2
@@ -586,7 +586,7 @@ main(int argc, char *argv[])

     /* Reallocate file_handle structure with correct size */

-    fhsize = sizeof(struct file_handle) + fhp\->handle_bytes;
+    fhsize = sizeof(*fhp) + fhp\->handle_bytes;
     fhp = realloc(fhp, fhsize);         /* Copies fhp\->handle_bytes */
     if (fhp == NULL)
         errExit("realloc");
@@ -707,7 +707,7 @@ main(int argc, char *argv[])

     /* Given handle_bytes, we can now allocate file_handle structure */

-    fhp = malloc(sizeof(struct file_handle) + handle_bytes);
+    fhp = malloc(sizeof(*fhp) + handle_bytes);
     if (fhp == NULL)
         errExit("malloc");

-- 
2.28.0

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

* [PATCH (2) 06/34] perf_event_open.2: Use sizeof consistently
  2020-09-04 10:55                             ` [PATCH (2) 05/34] open_by_handle_at.2: " Alejandro Colomar
@ 2020-09-04 10:56                               ` Alejandro Colomar
  2020-09-04 10:57                                 ` [PATCH (2) 07/34] " Alejandro Colomar
  2020-09-04 12:24                                 ` [PATCH (2) 06/34] perf_event_open.2: " Michael Kerrisk (man-pages)
  2020-09-04 12:20                               ` [PATCH (2) 05/34] open_by_handle_at.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:56 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From dbb7b520bd4314488122835c87f45b685ce45b28 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:29:02 +0200
Subject: [PATCH 06/34] perf_event_open.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@gmail.com>
---
 man2/perf_event_open.2 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index 2492fc75a..ea5ee725f 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -3419,9 +3419,9 @@ main(int argc, char **argv)
     long long count;
     int fd;

-    memset(&pe, 0, sizeof(struct perf_event_attr));
+    memset(&pe, 0, sizeof(pe));
     pe.type = PERF_TYPE_HARDWARE;
-    pe.size = sizeof(struct perf_event_attr);
+    pe.size = sizeof(pe);
     pe.config = PERF_COUNT_HW_INSTRUCTIONS;
     pe.disabled = 1;
     pe.exclude_kernel = 1;
-- 
2.28.0

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

* [PATCH (2) 07/34] perf_event_open.2: Use sizeof consistently
  2020-09-04 10:56                               ` [PATCH (2) 06/34] perf_event_open.2: " Alejandro Colomar
@ 2020-09-04 10:57                                 ` Alejandro Colomar
  2020-09-04 12:25                                   ` Michael Kerrisk (man-pages)
  2020-09-04 13:42                                   ` [PATCH (2) 08/34] poll.2: " Alejandro Colomar
  2020-09-04 12:24                                 ` [PATCH (2) 06/34] perf_event_open.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 10:57 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From ec1f70a162b0f4ea7a191baf8c098d7872dedce6 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:29:33 +0200
Subject: [PATCH 07/34] perf_event_open.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@gmail.com>
---
 man2/perf_event_open.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
index ea5ee725f..aea825706 100644
--- a/man2/perf_event_open.2
+++ b/man2/perf_event_open.2
@@ -3439,7 +3439,7 @@ main(int argc, char **argv)
     printf("Measuring instruction count for this printf\en");

     ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
-    read(fd, &count, sizeof(long long));
+    read(fd, &count, sizeof(count));

     printf("Used %lld instructions\en", count);

-- 
2.28.0

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

* Re: [PATCH (2) 04/34] futex.2: Use sizeof consistently
  2020-09-04 10:54                           ` [PATCH (2) 04/34] futex.2: " Alejandro Colomar
  2020-09-04 10:55                             ` [PATCH (2) 05/34] open_by_handle_at.2: " Alejandro Colomar
@ 2020-09-04 12:19                             ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 12:19 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 12:54 PM, Alejandro Colomar wrote:
>>From 21cd85c6f11390c71ed4475f1f9d55910891cf23 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:27:01 +0200
> Subject: [PATCH 04/34] futex.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@gmail.com>

Patch applied.

Cheers,

Michael

> ---
>  man2/futex.2 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/futex.2 b/man2/futex.2
> index 05696f617..6192b145a 100644
> --- a/man2/futex.2
> +++ b/man2/futex.2
> @@ -1839,7 +1839,7 @@ main(int argc, char *argv[])
>         subsequently use the "shared" futex operations (i.e., not the
>         ones suffixed "_PRIVATE") */
> 
> -    iaddr = mmap(NULL, sizeof(int) * 2, PROT_READ | PROT_WRITE,
> +    iaddr = mmap(NULL, sizeof(*iaddr) * 2, PROT_READ | PROT_WRITE,
>                  MAP_ANONYMOUS | MAP_SHARED, \-1, 0);
>      if (iaddr == MAP_FAILED)
>          errExit("mmap");
> 


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

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

* Re: [PATCH (2) 05/34] open_by_handle_at.2: Use sizeof consistently
  2020-09-04 10:55                             ` [PATCH (2) 05/34] open_by_handle_at.2: " Alejandro Colomar
  2020-09-04 10:56                               ` [PATCH (2) 06/34] perf_event_open.2: " Alejandro Colomar
@ 2020-09-04 12:20                               ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 12:20 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 12:55 PM, Alejandro Colomar wrote:
>>From 0176a7981aead1a202d5d0295b074e165b0d39dd Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:27:55 +0200
> Subject: [PATCH 05/34] open_by_handle_at.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
>

Well the page was already quite inconsistent, wasn't it, since
"sizeof(*fhp)" was already used elsewhere in the example!

Patch applied.

Thanks,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man2/open_by_handle_at.2 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man2/open_by_handle_at.2 b/man2/open_by_handle_at.2
> index 78c3220f8..846957acf 100644
> --- a/man2/open_by_handle_at.2
> +++ b/man2/open_by_handle_at.2
> @@ -586,7 +586,7 @@ main(int argc, char *argv[])
> 
>      /* Reallocate file_handle structure with correct size */
> 
> -    fhsize = sizeof(struct file_handle) + fhp\->handle_bytes;
> +    fhsize = sizeof(*fhp) + fhp\->handle_bytes;
>      fhp = realloc(fhp, fhsize);         /* Copies fhp\->handle_bytes */
>      if (fhp == NULL)
>          errExit("realloc");
> @@ -707,7 +707,7 @@ main(int argc, char *argv[])
> 
>      /* Given handle_bytes, we can now allocate file_handle structure */
> 
> -    fhp = malloc(sizeof(struct file_handle) + handle_bytes);
> +    fhp = malloc(sizeof(*fhp) + handle_bytes);
>      if (fhp == NULL)
>          errExit("malloc");
> 


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

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

* Re: [PATCH (2) 06/34] perf_event_open.2: Use sizeof consistently
  2020-09-04 10:56                               ` [PATCH (2) 06/34] perf_event_open.2: " Alejandro Colomar
  2020-09-04 10:57                                 ` [PATCH (2) 07/34] " Alejandro Colomar
@ 2020-09-04 12:24                                 ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 12:24 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 12:56 PM, Alejandro Colomar wrote:
>>From dbb7b520bd4314488122835c87f45b685ce45b28 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:29:02 +0200
> Subject: [PATCH 06/34] perf_event_open.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


Patch applied.

Cheers,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man2/perf_event_open.2 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
> index 2492fc75a..ea5ee725f 100644
> --- a/man2/perf_event_open.2
> +++ b/man2/perf_event_open.2
> @@ -3419,9 +3419,9 @@ main(int argc, char **argv)
>      long long count;
>      int fd;
> 
> -    memset(&pe, 0, sizeof(struct perf_event_attr));
> +    memset(&pe, 0, sizeof(pe));
>      pe.type = PERF_TYPE_HARDWARE;
> -    pe.size = sizeof(struct perf_event_attr);
> +    pe.size = sizeof(pe);
>      pe.config = PERF_COUNT_HW_INSTRUCTIONS;
>      pe.disabled = 1;
>      pe.exclude_kernel = 1;
> 


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

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

* Re: [PATCH (2) 07/34] perf_event_open.2: Use sizeof consistently
  2020-09-04 10:57                                 ` [PATCH (2) 07/34] " Alejandro Colomar
@ 2020-09-04 12:25                                   ` Michael Kerrisk (man-pages)
  2020-09-04 13:42                                   ` [PATCH (2) 08/34] poll.2: " Alejandro Colomar
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 12:25 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello ALex,

On 9/4/20 12:57 PM, Alejandro Colomar wrote:
>>From ec1f70a162b0f4ea7a191baf8c098d7872dedce6 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:29:33 +0200
> Subject: [PATCH 07/34] perf_event_open.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

Thanks. Patch applied.

Cheers,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man2/perf_event_open.2 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/perf_event_open.2 b/man2/perf_event_open.2
> index ea5ee725f..aea825706 100644
> --- a/man2/perf_event_open.2
> +++ b/man2/perf_event_open.2
> @@ -3439,7 +3439,7 @@ main(int argc, char **argv)
>      printf("Measuring instruction count for this printf\en");
> 
>      ioctl(fd, PERF_EVENT_IOC_DISABLE, 0);
> -    read(fd, &count, sizeof(long long));
> +    read(fd, &count, sizeof(count));
> 
>      printf("Used %lld instructions\en", count);
> 
Hello 

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

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

* [PATCH (2) 08/34] poll.2: Use sizeof consistently
  2020-09-04 10:57                                 ` [PATCH (2) 07/34] " Alejandro Colomar
  2020-09-04 12:25                                   ` Michael Kerrisk (man-pages)
@ 2020-09-04 13:42                                   ` Alejandro Colomar
  2020-09-04 13:43                                     ` [PATCH (2) 09/34] sysctl.2: " Alejandro Colomar
  2020-09-04 15:11                                     ` [PATCH (2) 08/34] poll.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:42 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 791b2082c91de4fb49a1a46e9c11d294aac09050 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:34:52 +0200
Subject: [PATCH 08/34] poll.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@gmail.com>
---
 man2/poll.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man2/poll.2 b/man2/poll.2
index 940c51da5..9b42822c0 100644
--- a/man2/poll.2
+++ b/man2/poll.2
@@ -596,7 +596,7 @@ main(int argc, char *argv[])
     }

     num_open_fds = nfds = argc \- 1;
-    pfds = calloc(nfds, sizeof(struct pollfd));
+    pfds = calloc(nfds, sizeof(*pfds));
     if (pfds == NULL)
         errExit("malloc");

-- 
2.28.0

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

* [PATCH (2) 09/34] sysctl.2: Use sizeof consistently
  2020-09-04 13:42                                   ` [PATCH (2) 08/34] poll.2: " Alejandro Colomar
@ 2020-09-04 13:43                                     ` Alejandro Colomar
  2020-09-04 13:44                                       ` [PATCH (2) 10/34] signalfd.2: " Alejandro Colomar
  2020-09-04 15:11                                       ` [PATCH (2) 09/34] sysctl.2: " Michael Kerrisk (man-pages)
  2020-09-04 15:11                                     ` [PATCH (2) 08/34] poll.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:43 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 90572d59a4f3b1986e57c0b32e14e4e68ecab716 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:39:56 +0200
Subject: [PATCH 09/34] sysctl.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@gmail.com>
---
 man2/sysctl.2 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man2/sysctl.2 b/man2/sysctl.2
index 65f79516d..161060490 100644
--- a/man2/sysctl.2
+++ b/man2/sysctl.2
@@ -154,7 +154,7 @@ main(void)
     size_t osnamelth;
     int name[] = { CTL_KERN, KERN_OSTYPE };

-    memset(&args, 0, sizeof(struct __sysctl_args));
+    memset(&args, 0, sizeof(args));
     args.name = name;
     args.nlen = sizeof(name)/sizeof(name[0]);
     args.oldval = osname;
-- 
2.28.0

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

* [PATCH (2) 10/34] signalfd.2: Use sizeof consistently
  2020-09-04 13:43                                     ` [PATCH (2) 09/34] sysctl.2: " Alejandro Colomar
@ 2020-09-04 13:44                                       ` Alejandro Colomar
  2020-09-04 13:45                                         ` [PATCH (2) 11/34] timerfd_create.2: " Alejandro Colomar
  2020-09-04 15:13                                         ` [PATCH (2) 10/34] signalfd.2: " Michael Kerrisk (man-pages)
  2020-09-04 15:11                                       ` [PATCH (2) 09/34] sysctl.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:44 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 9a10e681849a57f75d89cf6943901a3df8097399 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:41:31 +0200
Subject: [PATCH 10/34] signalfd.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@gmail.com>
---
 man2/signalfd.2 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man2/signalfd.2 b/man2/signalfd.2
index 96d502a50..92e9fd7ef 100644
--- a/man2/signalfd.2
+++ b/man2/signalfd.2
@@ -502,8 +502,8 @@ main(int argc, char *argv[])
         handle_error("signalfd");

     for (;;) {
-        s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
-        if (s != sizeof(struct signalfd_siginfo))
+        s = read(sfd, &fdsi, sizeof(fdsi));
+        if (s != sizeof(fdsi))
             handle_error("read");

         if (fdsi.ssi_signo == SIGINT) {
-- 
2.28.0

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

* [PATCH (2) 11/34] timerfd_create.2: Use sizeof consistently
  2020-09-04 13:44                                       ` [PATCH (2) 10/34] signalfd.2: " Alejandro Colomar
@ 2020-09-04 13:45                                         ` Alejandro Colomar
  2020-09-04 13:46                                           ` [PATCH (2) 12/34] bsearch.3: " Alejandro Colomar
  2020-09-04 15:14                                           ` [PATCH (2) 11/34] timerfd_create.2: " Michael Kerrisk (man-pages)
  2020-09-04 15:13                                         ` [PATCH (2) 10/34] signalfd.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:45 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From d347c933a8c253028f8f76c4170b65b85ce7d605 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:42:28 +0200
Subject: [PATCH 11/34] timerfd_create.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@gmail.com>
---
 man2/timerfd_create.2 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
index 67a13dba3..fd4acf3e9 100644
--- a/man2/timerfd_create.2
+++ b/man2/timerfd_create.2
@@ -700,8 +700,8 @@ main(int argc, char *argv[])
     printf("timer started\en");

     for (tot_exp = 0; tot_exp < max_exp;) {
-        s = read(fd, &exp, sizeof(uint64_t));
-        if (s != sizeof(uint64_t))
+        s = read(fd, &exp, sizeof(exp));
+        if (s != sizeof(exp))
             handle_error("read");

         tot_exp += exp;
-- 
2.28.0

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

* [PATCH (2) 12/34] bsearch.3: Use sizeof consistently
  2020-09-04 13:45                                         ` [PATCH (2) 11/34] timerfd_create.2: " Alejandro Colomar
@ 2020-09-04 13:46                                           ` Alejandro Colomar
  2020-09-04 13:50                                             ` [PATCH (2) 13/34] cmsg.3: " Alejandro Colomar
  2020-09-04 15:17                                             ` [PATCH (2) 12/34] bsearch.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:14                                           ` [PATCH (2) 11/34] timerfd_create.2: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:46 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 886db3bad74f35fc40a1238a0d2f35ace3dc7620 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:43:23 +0200
Subject: [PATCH 12/34] bsearch.3: 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>
---
 man3/bsearch.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/bsearch.3 b/man3/bsearch.3
index 88e0e6ea1..6859bdba2 100644
--- a/man3/bsearch.3
+++ b/man3/bsearch.3
@@ -124,12 +124,12 @@ main(int argc, char **argv)
 {
     int i;

-    qsort(months, nr_of_months, sizeof(struct mi), compmi);
+    qsort(months, nr_of_months, sizeof(months[0]), compmi);
     for (i = 1; i < argc; i++) {
         struct mi key, *res;
         key.name = argv[i];
         res = bsearch(&key, months, nr_of_months,
-                      sizeof(struct mi), compmi);
+                      sizeof(months[0]), compmi);
         if (res == NULL)
             printf("\(aq%s\(aq: unknown month\en", argv[i]);
         else
-- 
2.28.0

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

* [PATCH (2) 13/34] cmsg.3: Use sizeof consistently
  2020-09-04 13:46                                           ` [PATCH (2) 12/34] bsearch.3: " Alejandro Colomar
@ 2020-09-04 13:50                                             ` Alejandro Colomar
  2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
  2020-09-04 15:18                                               ` [PATCH (2) 13/34] " Michael Kerrisk (man-pages)
  2020-09-04 15:17                                             ` [PATCH (2) 12/34] bsearch.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:50 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From ba70b1e8addad4ef9f2a490d2069b112d09ba9f1 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:44:41 +0200
Subject: [PATCH 13/34] cmsg.3: 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>
---
 man3/cmsg.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/cmsg.3 b/man3/cmsg.3
index 99ee950f9..3d6288901 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -203,7 +203,7 @@ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
         cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
     if (cmsg\->cmsg_level == IPPROTO_IP
             && cmsg\->cmsg_type == IP_TTL) {
-        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(int));
+        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(received_ttl));
         break;
     }
 }
-- 
2.28.0

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

* [PATCH (2) 14/34] cmsg.3: Use sizeof consistently
  2020-09-04 13:50                                             ` [PATCH (2) 13/34] cmsg.3: " Alejandro Colomar
@ 2020-09-04 13:52                                               ` Alejandro Colomar
  2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
                                                                   ` (2 more replies)
  2020-09-04 15:18                                               ` [PATCH (2) 13/34] " Michael Kerrisk (man-pages)
  1 sibling, 3 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:52 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 374b31bee6762314ab48988e2e78a3a6a2f96834 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:44:54 +0200
Subject: [PATCH 14/34] cmsg.3: 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>
---
 man3/cmsg.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/cmsg.3 b/man3/cmsg.3
index 3d6288901..8d0ad6666 100644
--- a/man3/cmsg.3
+++ b/man3/cmsg.3
@@ -241,8 +241,8 @@ msg.msg_controllen = sizeof(u.buf);
 cmsg = CMSG_FIRSTHDR(&msg);
 cmsg\->cmsg_level = SOL_SOCKET;
 cmsg\->cmsg_type = SCM_RIGHTS;
-cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
-memcpy(CMSG_DATA(cmsg), myfds, sizeof(int) * NUM_FD);
+cmsg\->cmsg_len = CMSG_LEN(sizeof(myfds));
+memcpy(CMSG_DATA(cmsg), myfds, sizeof(myfds));
 .EE
 .in
 .SH SEE ALSO
-- 
2.28.0

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

* [PATCH (2) 15/34] getaddrinfo.3: Use sizeof consistently
  2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
@ 2020-09-04 13:53                                                 ` Alejandro Colomar
  2020-09-04 14:32                                                   ` [PATCH (2) 16/34] " Alejandro Colomar
  2020-09-04 15:20                                                   ` [PATCH (2) 15/34] " Michael Kerrisk (man-pages)
  2020-09-04 13:54                                                 ` Alejandro Colomar
  2020-09-04 15:20                                                 ` [PATCH (2) 14/34] cmsg.3: " Michael Kerrisk (man-pages)
  2 siblings, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:53 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From eef612c1f5f039421bd0fa167e1972e98d934bce Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:46:06 +0200
Subject: [PATCH 15/34] getaddrinfo.3: 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>
---
 man3/getaddrinfo.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 8aa544789..158fd2e31 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -679,7 +679,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
@@ -775,7 +775,7 @@ main(int argc, char *argv[])

     /* Obtain address(es) matching host/port */

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = 0;
-- 
2.28.0

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

* [PATCH (2) 15/34] getaddrinfo.3: Use sizeof consistently
  2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
  2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
@ 2020-09-04 13:54                                                 ` Alejandro Colomar
  2020-09-04 15:20                                                 ` [PATCH (2) 14/34] cmsg.3: " Michael Kerrisk (man-pages)
  2 siblings, 0 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 13:54 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From eef612c1f5f039421bd0fa167e1972e98d934bce Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:46:06 +0200
Subject: [PATCH 15/34] getaddrinfo.3: 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>
---
 man3/getaddrinfo.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 8aa544789..158fd2e31 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -679,7 +679,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
@@ -775,7 +775,7 @@ main(int argc, char *argv[])

     /* Obtain address(es) matching host/port */

-    memset(&hints, 0, sizeof(struct addrinfo));
+    memset(&hints, 0, sizeof(hints));
     hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
     hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
     hints.ai_flags = 0;
-- 
2.28.0

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

* [PATCH (2) 16/34] getaddrinfo.3: Use sizeof consistently
  2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
@ 2020-09-04 14:32                                                   ` Alejandro Colomar
  2020-09-04 14:34                                                     ` [PATCH (2) 17/34] getgrouplist.3: " Alejandro Colomar
  2020-09-04 15:21                                                     ` [PATCH (2) 16/34] getaddrinfo.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:20                                                   ` [PATCH (2) 15/34] " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:32 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From f926f02eede41183aed7ae279eb333273bd0c8dc Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:46:35 +0200
Subject: [PATCH 16/34] getaddrinfo.3: 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>
---
 man3/getaddrinfo.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
index 158fd2e31..70e6b4cc0 100644
--- a/man3/getaddrinfo.3
+++ b/man3/getaddrinfo.3
@@ -721,7 +721,7 @@ main(int argc, char *argv[])
     /* Read datagrams and echo them back to sender */

     for (;;) {
-        peer_addr_len = sizeof(struct sockaddr_storage);
+        peer_addr_len = sizeof(peer_addr);
         nread = recvfrom(sfd, buf, BUF_SIZE, 0,
                 (struct sockaddr *) &peer_addr, &peer_addr_len);
         if (nread == \-1)
-- 
2.28.0

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

* [PATCH (2) 17/34] getgrouplist.3: Use sizeof consistently
  2020-09-04 14:32                                                   ` [PATCH (2) 16/34] " Alejandro Colomar
@ 2020-09-04 14:34                                                     ` Alejandro Colomar
  2020-09-04 14:37                                                       ` [PATCH (2) 18/34] insque.3: " Alejandro Colomar
  2020-09-04 15:25                                                       ` [PATCH (2) 17/34] getgrouplist.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:21                                                     ` [PATCH (2) 16/34] getaddrinfo.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:34 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 7ca60fc88b831818c1f1722919af220a646761ab Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:47:15 +0200
Subject: [PATCH 17/34] getgrouplist.3: 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>
---
 man3/getgrouplist.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
index 372f2613f..ff8d89e3f 100644
--- a/man3/getgrouplist.3
+++ b/man3/getgrouplist.3
@@ -164,7 +164,7 @@ main(int argc, char *argv[])

     ngroups = atoi(argv[2]);

-    groups = malloc(sizeof(gid_t) * ngroups);
+    groups = malloc(sizeof(*groups) * ngroups);
     if (groups == NULL) {
         perror("malloc");
         exit(EXIT_FAILURE);
-- 
2.28.0

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

* [PATCH (2) 18/34] insque.3: Use sizeof consistently
  2020-09-04 14:34                                                     ` [PATCH (2) 17/34] getgrouplist.3: " Alejandro Colomar
@ 2020-09-04 14:37                                                       ` Alejandro Colomar
  2020-09-04 14:41                                                         ` [PATCH (2) 19/34] malloc_info.3: " Alejandro Colomar
  2020-09-04 15:25                                                         ` [PATCH (2) 18/34] insque.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:25                                                       ` [PATCH (2) 17/34] getgrouplist.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:37 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From b43c812d1e129a8d2b34df7624a78baa3bf1273e Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:47:45 +0200
Subject: [PATCH 18/34] insque.3: 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>
---
 man3/insque.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/insque.3 b/man3/insque.3
index a9fc28550..005ad8cc1 100644
--- a/man3/insque.3
+++ b/man3/insque.3
@@ -182,7 +182,7 @@ new_element(void)
 {
     struct element *e;

-    e = malloc(sizeof(struct element));
+    e = malloc(sizeof(*e));
     if (e == NULL) {
         fprintf(stderr, "malloc() failed\en");
         exit(EXIT_FAILURE);
-- 
2.28.0

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

* [PATCH (2) 19/34] malloc_info.3: Use sizeof consistently
  2020-09-04 14:37                                                       ` [PATCH (2) 18/34] insque.3: " Alejandro Colomar
@ 2020-09-04 14:41                                                         ` Alejandro Colomar
  2020-09-04 14:44                                                           ` [PATCH (2) 20/34] mbsinit.3: " Alejandro Colomar
  2020-09-04 15:27                                                           ` [PATCH (2) 19/34] malloc_info.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:25                                                         ` [PATCH (2) 18/34] insque.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:41 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From bf1a7799161fe1f08570c4f25d87a0f4e0b51ef1 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:49:17 +0200
Subject: [PATCH 19/34] malloc_info.3: 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>
---
 man3/malloc_info.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
index 0d95cdff7..598478dcc 100644
--- a/man3/malloc_info.3
+++ b/man3/malloc_info.3
@@ -226,7 +226,7 @@ main(int argc, char *argv[])
     blockSize = atoi(argv[3]);
     sleepTime = (argc > 4) ? atoi(argv[4]) : 0;

-    thr = calloc(numThreads, sizeof(pthread_t));
+    thr = calloc(numThreads, sizeof(*thr));
     if (thr == NULL)
         errExit("calloc");

-- 
2.28.0

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

* Re: [PATCH (2) 20/34] mbsinit.3: Use sizeof consistently
  2020-09-04 14:41                                                         ` [PATCH (2) 19/34] malloc_info.3: " Alejandro Colomar
@ 2020-09-04 14:44                                                           ` Alejandro Colomar
  2020-09-04 14:45                                                             ` [PATCH (2) 21/34] mbstowcs.3: " Alejandro Colomar
  2020-09-04 15:27                                                             ` [PATCH (2) 20/34] mbsinit.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:27                                                           ` [PATCH (2) 19/34] malloc_info.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:44 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 77587b9c0b58cde232ea3bfaeef5f50607d83b5e Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:50:10 +0200
Subject: [PATCH 20/34] mbsinit.3: 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>
---
 man3/mbsinit.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/mbsinit.3 b/man3/mbsinit.3
index aeaa6ce88..74fe48f86 100644
--- a/man3/mbsinit.3
+++ b/man3/mbsinit.3
@@ -59,7 +59,7 @@ in initial state is to set it to zero:
 .in +4n
 .EX
 mbstate_t state;
-memset(&state, 0, sizeof(mbstate_t));
+memset(&state, 0, sizeof(state));
 .EE
 .in
 .PP
-- 
2.28.0

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

* [PATCH (2) 21/34] mbstowcs.3: Use sizeof consistently
  2020-09-04 14:44                                                           ` [PATCH (2) 20/34] mbsinit.3: " Alejandro Colomar
@ 2020-09-04 14:45                                                             ` Alejandro Colomar
  2020-09-04 14:48                                                               ` [PATCH (2) 22/34] pthread_create.3: " Alejandro Colomar
  2020-09-05 14:21                                                               ` [PATCH (2) 21/34] mbstowcs.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:27                                                             ` [PATCH (2) 20/34] mbsinit.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:45 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 1b70e7a1da093e4a8e3be79aaed623b21c10e763 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:51:07 +0200
Subject: [PATCH 21/34] mbstowcs.3: 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>
---
 man3/mbstowcs.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/mbstowcs.3 b/man3/mbstowcs.3
index cf650506e..2f9fbc17c 100644
--- a/man3/mbstowcs.3
+++ b/man3/mbstowcs.3
@@ -186,7 +186,7 @@ main(int argc, char *argv[])
     /* Allocate wide character string of the desired size.  Add 1
        to allow for terminating null wide character (L\(aq\e0\(aq). */

-    wcs = calloc(mbslen + 1, sizeof(wchar_t));
+    wcs = calloc(mbslen + 1, sizeof(*wcs));
     if (wcs == NULL) {
         perror("calloc");
         exit(EXIT_FAILURE);
-- 
2.28.0

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

* [PATCH (2) 22/34] pthread_create.3: Use sizeof consistently
  2020-09-04 14:45                                                             ` [PATCH (2) 21/34] mbstowcs.3: " Alejandro Colomar
@ 2020-09-04 14:48                                                               ` Alejandro Colomar
  2020-09-04 14:50                                                                 ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Alejandro Colomar
  2020-09-05 14:21                                                                 ` [PATCH (2) 22/34] pthread_create.3: " Michael Kerrisk (man-pages)
  2020-09-05 14:21                                                               ` [PATCH (2) 21/34] mbstowcs.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:48 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 03783d811fad4783b394c01a4ac68ca6d92b6c58 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:52:22 +0200
Subject: [PATCH 22/34] pthread_create.3: 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>
---
 man3/pthread_create.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/pthread_create.3 b/man3/pthread_create.3
index d86188e6b..5ffb14586 100644
--- a/man3/pthread_create.3
+++ b/man3/pthread_create.3
@@ -361,7 +361,7 @@ main(int argc, char *argv[])

     /* Allocate memory for pthread_create() arguments */

-    tinfo = calloc(num_threads, sizeof(struct thread_info));
+    tinfo = calloc(num_threads, sizeof(*tinfo));
     if (tinfo == NULL)
         handle_error("calloc");

-- 
2.28.0

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

* [PATCH (2) 23/34] pthread_setaffinity_np.3: Use sizeof consistently
  2020-09-04 14:48                                                               ` [PATCH (2) 22/34] pthread_create.3: " Alejandro Colomar
@ 2020-09-04 14:50                                                                 ` Alejandro Colomar
  2020-09-04 14:50                                                                   ` [PATCH (2) 24/34] queue.3: " Alejandro Colomar
  2020-09-04 15:42                                                                   ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Michael Kerrisk (man-pages)
  2020-09-05 14:21                                                                 ` [PATCH (2) 22/34] pthread_create.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:50 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From ba0d73749a85e835aa43a4134a1b6906062943f3 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:53:12 +0200
Subject: [PATCH 23/34] pthread_setaffinity_np.3: 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>
---
 man3/pthread_setaffinity_np.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/pthread_setaffinity_np.3 b/man3/pthread_setaffinity_np.3
index 24499f550..57aaf1251 100644
--- a/man3/pthread_setaffinity_np.3
+++ b/man3/pthread_setaffinity_np.3
@@ -194,13 +194,13 @@ main(int argc, char *argv[])
     for (j = 0; j < 8; j++)
         CPU_SET(j, &cpuset);

-    s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+    s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
     if (s != 0)
         handle_error_en(s, "pthread_setaffinity_np");

     /* Check the actual affinity mask assigned to the thread */

-    s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
+    s = pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset);
     if (s != 0)
         handle_error_en(s, "pthread_getaffinity_np");

-- 
2.28.0

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

* [PATCH (2) 24/34] queue.3: Use sizeof consistently
  2020-09-04 14:50                                                                 ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Alejandro Colomar
@ 2020-09-04 14:50                                                                   ` Alejandro Colomar
  2020-09-04 14:52                                                                     ` [PATCH (2) 25/34] rtnetlink.3: " Alejandro Colomar
  2020-09-04 16:58                                                                     ` [PATCH (2) 24/34] queue.3: " Michael Kerrisk (man-pages)
  2020-09-04 15:42                                                                   ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:50 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 6f3e17cf38bc3718332c7151899e253dbc91affb Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:53:51 +0200
Subject: [PATCH 24/34] queue.3: 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>
---
 man3/queue.3 | 32 ++++++++++++++++----------------
 1 file changed, 16 insertions(+), 16 deletions(-)

diff --git a/man3/queue.3 b/man3/queue.3
index 55cd5847e..2ea5ff4f5 100644
--- a/man3/queue.3
+++ b/man3/queue.3
@@ -559,10 +559,10 @@ struct entry {

 SLIST_INIT(&head);			/* Initialize the list. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 SLIST_INSERT_HEAD(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 SLIST_INSERT_AFTER(n1, n2, entries);

 SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */
@@ -775,13 +775,13 @@ struct entry {

 STAILQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 STAILQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 STAILQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 STAILQ_INSERT_AFTER(&head, n1, n2, entries);
 					/* Deletion. */
 STAILQ_REMOVE(&head, n2, entry, entries);
@@ -975,13 +975,13 @@ struct entry {

 LIST_INIT(&head);			/* Initialize the list. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 LIST_INSERT_HEAD(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 LIST_INSERT_AFTER(n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 LIST_INSERT_BEFORE(n2, n3, entries);

 LIST_REMOVE(n2, entries);		/* Deletion. */
@@ -1233,16 +1233,16 @@ struct entry {

 TAILQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 TAILQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 TAILQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 TAILQ_INSERT_AFTER(&head, n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 TAILQ_INSERT_BEFORE(n2, n3, entries);

 TAILQ_REMOVE(&head, n2, entries);	/* Deletion. */
@@ -1426,16 +1426,16 @@ struct entry {

 CIRCLEQ_INIT(&head);			/* Initialize the queue. */

-n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
+n1 = malloc(sizeof(*n1));		/* Insert at the head. */
 CIRCLEQ_INSERT_HEAD(&head, n1, entries);

-n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
+n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
 CIRCLEQ_INSERT_TAIL(&head, n1, entries);

-n2 = malloc(sizeof(struct entry));	/* Insert after. */
+n2 = malloc(sizeof(*n2));		/* Insert after. */
 CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);

-n3 = malloc(sizeof(struct entry));	/* Insert before. */
+n3 = malloc(sizeof(*n3));		/* Insert before. */
 CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);

 CIRCLEQ_REMOVE(&head, n2, entries);	/* Deletion. */
-- 
2.28.0

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

* [PATCH (2) 25/34] rtnetlink.3: Use sizeof consistently
  2020-09-04 14:50                                                                   ` [PATCH (2) 24/34] queue.3: " Alejandro Colomar
@ 2020-09-04 14:52                                                                     ` Alejandro Colomar
  2020-09-04 14:54                                                                       ` [PATCH (2) 26/34] " Alejandro Colomar
  2020-09-04 16:59                                                                       ` [PATCH (2) 25/34] " Michael Kerrisk (man-pages)
  2020-09-04 16:58                                                                     ` [PATCH (2) 24/34] queue.3: " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:52 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From eca0c1500aa4db77c8c8d079798fe080e83e9935 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:55:00 +0200
Subject: [PATCH 25/34] rtnetlink.3: 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>
---
 man3/rtnetlink.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
index 07bb1fbf9..2d9fa05a2 100644
--- a/man3/rtnetlink.3
+++ b/man3/rtnetlink.3
@@ -105,7 +105,7 @@ unsigned int mtu = 1000;
 int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);

 memset(&req, 0, sizeof(req));
-req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
+req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
 req.nh.nlmsg_flags = NLM_F_REQUEST;
 req.nh.nlmsg_type = RTM_NEWLINK;
 req.if.ifi_family = AF_UNSPEC;
-- 
2.28.0

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

* [PATCH (2) 26/34] rtnetlink.3: Use sizeof consistently
  2020-09-04 14:52                                                                     ` [PATCH (2) 25/34] rtnetlink.3: " Alejandro Colomar
@ 2020-09-04 14:54                                                                       ` Alejandro Colomar
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
  2020-09-04 17:04                                                                         ` [PATCH (2) 26/34] rtnetlink.3: " Michael Kerrisk (man-pages)
  2020-09-04 16:59                                                                       ` [PATCH (2) 25/34] " Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:54 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 2b7a02916c24af8cbb0cbb071a7223fe48a52571 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:55:11 +0200
Subject: [PATCH 26/34] rtnetlink.3: 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>
---
 man3/rtnetlink.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
index 2d9fa05a2..f8b6c255a 100644
--- a/man3/rtnetlink.3
+++ b/man3/rtnetlink.3
@@ -114,7 +114,7 @@ req.if.ifi_change = 0xffffffff; /* ??? */
 rta = (struct rtattr *)(((char *) &req) +
                          NLMSG_ALIGN(req.nh.nlmsg_len));
 rta\->rta_type = IFLA_MTU;
-rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
+rta\->rta_len = RTA_LENGTH(sizeof(mtu));
 req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
                               RTA_LENGTH(sizeof(mtu));
 memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
-- 
2.28.0

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

* [PATCH (2) 27/34] shm_open.3: Use sizeof consistently
  2020-09-04 14:54                                                                       ` [PATCH (2) 26/34] " Alejandro Colomar
@ 2020-09-04 14:55                                                                         ` Alejandro Colomar
  2020-09-04 14:57                                                                           ` [PATCH (2) 28/34] strptime.3: " Alejandro Colomar
                                                                                             ` (7 more replies)
  2020-09-04 17:04                                                                         ` [PATCH (2) 26/34] rtnetlink.3: " Michael Kerrisk (man-pages)
  1 sibling, 8 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:55 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From d3f439e697c9a384cad55e84a584493088eb4291 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:55:48 +0200
Subject: [PATCH 27/34] shm_open.3: 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>
---
 man3/shm_open.3 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man3/shm_open.3 b/man3/shm_open.3
index bba4eb826..24cc6a403 100644
--- a/man3/shm_open.3
+++ b/man3/shm_open.3
@@ -382,7 +382,7 @@ main(int argc, char *argv[])

     /* Map the object into the caller\(aqs address space */

-    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
+    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
                                PROT_READ | PROT_WRITE,
                                MAP_SHARED, fd, 0);
     if (shmp == MAP_FAILED)
@@ -471,7 +471,7 @@ main(int argc, char *argv[])
     if (fd == \-1)
         errExit("shm_open");

-    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
+    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
                                PROT_READ | PROT_WRITE,
                                MAP_SHARED, fd, 0);
     if (shmp == MAP_FAILED)
-- 
2.28.0

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

* [PATCH (2) 28/34] strptime.3: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
@ 2020-09-04 14:57                                                                           ` Alejandro Colomar
  2020-09-04 15:37                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:03                                                                           ` [PATCH (2) 29/34] tsearch.3: " Alejandro Colomar
                                                                                             ` (6 subsequent siblings)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 14:57 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From f000e36d106a22d68f26e9cebe84758854739a42 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:56:21 +0200
Subject: [PATCH 28/34] strptime.3: 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>
---
 man3/strptime.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/strptime.3 b/man3/strptime.3
index d12f298ff..ab7d76f9a 100644
--- a/man3/strptime.3
+++ b/man3/strptime.3
@@ -429,7 +429,7 @@ main(void)
     struct tm tm;
     char buf[255];

-    memset(&tm, 0, sizeof(struct tm));
+    memset(&tm, 0, sizeof(tm));
     strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
     strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
     puts(buf);
-- 
2.28.0

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

* [PATCH (2) 29/34] tsearch.3: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
  2020-09-04 14:57                                                                           ` [PATCH (2) 28/34] strptime.3: " Alejandro Colomar
@ 2020-09-04 15:03                                                                           ` Alejandro Colomar
  2020-09-05 14:22                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:04                                                                           ` [PATCH (2) 30/34] aio.7: " Alejandro Colomar
                                                                                             ` (5 subsequent siblings)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:03 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From ff3fe9cdfd280fce97e9289e9a91fb6cc2c1c368 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:56:52 +0200
Subject: [PATCH 29/34] tsearch.3: 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>
---
 man3/tsearch.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/tsearch.3 b/man3/tsearch.3
index 452395d6b..f0ff80e8c 100644
--- a/man3/tsearch.3
+++ b/man3/tsearch.3
@@ -327,7 +327,7 @@ main(void)

     srand(time(NULL));
     for (i = 0; i < 12; i++) {
-        ptr = xmalloc(sizeof(int));
+        ptr = xmalloc(sizeof(*ptr));
         *ptr = rand() & 0xff;
         val = tsearch((void *) ptr, &root, compare);
         if (val == NULL)
-- 
2.28.0

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

* [PATCH (2) 30/34] aio.7: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
  2020-09-04 14:57                                                                           ` [PATCH (2) 28/34] strptime.3: " Alejandro Colomar
  2020-09-04 15:03                                                                           ` [PATCH (2) 29/34] tsearch.3: " Alejandro Colomar
@ 2020-09-04 15:04                                                                           ` Alejandro Colomar
  2020-09-04 17:15                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:05                                                                           ` [PATCH (2) 31/34] fanotify.7: " Alejandro Colomar
                                                                                             ` (4 subsequent siblings)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:04 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 33a09662331be9666c2f69dc60a792d9deee761e Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:57:28 +0200
Subject: [PATCH 30/34] aio.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/aio.7 | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/man7/aio.7 b/man7/aio.7
index dd05dce83..d3ab3f422 100644
--- a/man7/aio.7
+++ b/man7/aio.7
@@ -311,11 +311,11 @@ main(int argc, char *argv[])

     /* Allocate our arrays */

-    ioList = calloc(numReqs, sizeof(struct ioRequest));
+    ioList = calloc(numReqs, sizeof(*ioList));
     if (ioList == NULL)
         errExit("calloc");

-    aiocbList = calloc(numReqs, sizeof(struct aiocb));
+    aiocbList = calloc(numReqs, sizeof(*aiocbList));
     if (aiocbList == NULL)
         errExit("calloc");

-- 
2.28.0

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

* [PATCH (2) 31/34] fanotify.7: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
                                                                                             ` (2 preceding siblings ...)
  2020-09-04 15:04                                                                           ` [PATCH (2) 30/34] aio.7: " Alejandro Colomar
@ 2020-09-04 15:05                                                                           ` Alejandro Colomar
  2020-09-04 15:38                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:06                                                                           ` [PATCH (2) 32/34] inotify.7: " Alejandro Colomar
                                                                                             ` (3 subsequent siblings)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:05 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 75af70465a8e60aa1d96b32d843b074966b7a878 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:58:14 +0200
Subject: [PATCH 31/33] fanotify.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/fanotify.7 | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/man7/fanotify.7 b/man7/fanotify.7
index a7d60b2b9..29c818027 100644
--- a/man7/fanotify.7
+++ b/man7/fanotify.7
@@ -808,8 +808,7 @@ handle_events(int fd)

                     response.fd = metadata\->fd;
                     response.response = FAN_ALLOW;
-                    write(fd, &response,
-                          sizeof(struct fanotify_response));
+                    write(fd, &response, sizeof(response));
                 }

                 /* Handle closing of writable file event */
-- 
2.28.0

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

* [PATCH (2) 32/34] inotify.7: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
                                                                                             ` (3 preceding siblings ...)
  2020-09-04 15:05                                                                           ` [PATCH (2) 31/34] fanotify.7: " Alejandro Colomar
@ 2020-09-04 15:06                                                                           ` Alejandro Colomar
  2020-09-04 17:08                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:07                                                                           ` [PATCH (2) 33/34] " Alejandro Colomar
                                                                                             ` (2 subsequent siblings)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:06 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 464c2941b936df850f03d7d9df382dc2c46f37f1 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:58:59 +0200
Subject: [PATCH 32/34] inotify.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/inotify.7 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man7/inotify.7 b/man7/inotify.7
index 9b2d7a4e5..4093bba5a 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -968,7 +968,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
         /* Loop over all events in the buffer */

         for (ptr = buf; ptr < buf + len;
-                ptr += sizeof(struct inotify_event) + event\->len) {
+                ptr += sizeof(*event) + event\->len) {

             event = (const struct inotify_event *) ptr;

-- 
2.28.0

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

* [PATCH (2) 33/34] inotify.7: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
                                                                                             ` (4 preceding siblings ...)
  2020-09-04 15:06                                                                           ` [PATCH (2) 32/34] inotify.7: " Alejandro Colomar
@ 2020-09-04 15:07                                                                           ` Alejandro Colomar
  2020-09-04 17:14                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 15:08                                                                           ` [PATCH (2) 34/34] unix.7: " Alejandro Colomar
  2020-09-04 17:26                                                                           ` [PATCH (2) 27/34] shm_open.3: " Michael Kerrisk (man-pages)
  7 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:07 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

From 0d4adf855466fe5c36e378eb704abafd45fc6417 Mon Sep 17 00:00:00 2001
From: Alejandro Colomar <colomar.6.4.3@gmail.com>
Date: Thu, 3 Sep 2020 21:59:11 +0200
Subject: [PATCH 33/34] inotify.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/inotify.7 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man7/inotify.7 b/man7/inotify.7
index 4093bba5a..f1a1667e3 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -1031,7 +1031,7 @@ main(int argc, char* argv[])

     /* Allocate memory for watch descriptors */

-    wd = calloc(argc, sizeof(int));
+    wd = calloc(argc, sizeof(*wd));
     if (wd == NULL) {
         perror("calloc");
         exit(EXIT_FAILURE);
-- 
2.28.0

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

* [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
                                                                                             ` (5 preceding siblings ...)
  2020-09-04 15:07                                                                           ` [PATCH (2) 33/34] " Alejandro Colomar
@ 2020-09-04 15:08                                                                           ` Alejandro Colomar
  2020-09-04 15:12                                                                             ` Alejandro Colomar
  2020-09-04 15:40                                                                             ` Michael Kerrisk (man-pages)
  2020-09-04 17:26                                                                           ` [PATCH (2) 27/34] shm_open.3: " Michael Kerrisk (man-pages)
  7 siblings, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:08 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

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
--- 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);
-- 
2.28.0

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

* Re: [PATCH (2) 08/34] poll.2: Use sizeof consistently
  2020-09-04 13:42                                   ` [PATCH (2) 08/34] poll.2: " Alejandro Colomar
  2020-09-04 13:43                                     ` [PATCH (2) 09/34] sysctl.2: " Alejandro Colomar
@ 2020-09-04 15:11                                     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:11 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 3:42 PM, Alejandro Colomar wrote:
>>From 791b2082c91de4fb49a1a46e9c11d294aac09050 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:34:52 +0200
> Subject: [PATCH 08/34] poll.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

This is another of those cases where I am inclined not to
apply the patch. It feels to me like this reduces readability
somewhat, since the very point is to allocate an array of
pollfd structs. So, I think I won't apply this one.

Thanks,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man2/poll.2 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/poll.2 b/man2/poll.2
> index 940c51da5..9b42822c0 100644
> --- a/man2/poll.2
> +++ b/man2/poll.2
> @@ -596,7 +596,7 @@ main(int argc, char *argv[])
>      }
> 
>      num_open_fds = nfds = argc \- 1;
> -    pfds = calloc(nfds, sizeof(struct pollfd));
> +    pfds = calloc(nfds, sizeof(*pfds));
>      if (pfds == NULL)
>          errExit("malloc");
> 


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

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

* Re: [PATCH (2) 09/34] sysctl.2: Use sizeof consistently
  2020-09-04 13:43                                     ` [PATCH (2) 09/34] sysctl.2: " Alejandro Colomar
  2020-09-04 13:44                                       ` [PATCH (2) 10/34] signalfd.2: " Alejandro Colomar
@ 2020-09-04 15:11                                       ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:11 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 3:43 PM, Alejandro Colomar wrote:
>>From 90572d59a4f3b1986e57c0b32e14e4e68ecab716 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:39:56 +0200
> Subject: [PATCH 09/34] sysctl.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@gmail.com>

Patch applied. Thanks!

Cheers,

Michael

> ---
>  man2/sysctl.2 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man2/sysctl.2 b/man2/sysctl.2
> index 65f79516d..161060490 100644
> --- a/man2/sysctl.2
> +++ b/man2/sysctl.2
> @@ -154,7 +154,7 @@ main(void)
>      size_t osnamelth;
>      int name[] = { CTL_KERN, KERN_OSTYPE };
> 
> -    memset(&args, 0, sizeof(struct __sysctl_args));
> +    memset(&args, 0, sizeof(args));
>      args.name = name;
>      args.nlen = sizeof(name)/sizeof(name[0]);
>      args.oldval = osname;
> 


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

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-04 15:08                                                                           ` [PATCH (2) 34/34] unix.7: " Alejandro Colomar
@ 2020-09-04 15:12                                                                             ` Alejandro Colomar
  2020-09-05  8:27                                                                               ` Michael Kerrisk (man-pages)
  2020-09-04 15:40                                                                             ` Michael Kerrisk (man-pages)
  1 sibling, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-04 15:12 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

Hi Michael,

Sorry for the deep threading, I noticed it late and I tried to fix it in
the last messages.  Also there's some email where I forgot to remove
"Re:" from the subject.

Well, that's all!  I can see 2 or 3 patches where I have doubts, but I
think most of them are straightforward.

Cheers,
Alex.

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

* Re: [PATCH (2) 10/34] signalfd.2: Use sizeof consistently
  2020-09-04 13:44                                       ` [PATCH (2) 10/34] signalfd.2: " Alejandro Colomar
  2020-09-04 13:45                                         ` [PATCH (2) 11/34] timerfd_create.2: " Alejandro Colomar
@ 2020-09-04 15:13                                         ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:13 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 3:44 PM, Alejandro Colomar wrote:
>>From 9a10e681849a57f75d89cf6943901a3df8097399 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:41:31 +0200
> Subject: [PATCH 10/34] signalfd.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@gmail.com>

Patch applied. Thanks.

Michael

> ---
>  man2/signalfd.2 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man2/signalfd.2 b/man2/signalfd.2
> index 96d502a50..92e9fd7ef 100644
> --- a/man2/signalfd.2
> +++ b/man2/signalfd.2
> @@ -502,8 +502,8 @@ main(int argc, char *argv[])
>          handle_error("signalfd");
> 
>      for (;;) {
> -        s = read(sfd, &fdsi, sizeof(struct signalfd_siginfo));
> -        if (s != sizeof(struct signalfd_siginfo))
> +        s = read(sfd, &fdsi, sizeof(fdsi));
> +        if (s != sizeof(fdsi))
>              handle_error("read");
> 
>          if (fdsi.ssi_signo == SIGINT) {
> 


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

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

* Re: [PATCH (2) 11/34] timerfd_create.2: Use sizeof consistently
  2020-09-04 13:45                                         ` [PATCH (2) 11/34] timerfd_create.2: " Alejandro Colomar
  2020-09-04 13:46                                           ` [PATCH (2) 12/34] bsearch.3: " Alejandro Colomar
@ 2020-09-04 15:14                                           ` Michael Kerrisk (man-pages)
  2020-09-05  8:07                                             ` Michael Kerrisk (man-pages)
  1 sibling, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:14 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 3:45 PM, Alejandro Colomar wrote:
>>From d347c933a8c253028f8f76c4170b65b85ce7d605 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:42:28 +0200
> Subject: [PATCH 11/34] timerfd_create.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@gmail.com>

Applied. Thanks!

Michael

> ---
>  man2/timerfd_create.2 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
> index 67a13dba3..fd4acf3e9 100644
> --- a/man2/timerfd_create.2
> +++ b/man2/timerfd_create.2
> @@ -700,8 +700,8 @@ main(int argc, char *argv[])
>      printf("timer started\en");
> 
>      for (tot_exp = 0; tot_exp < max_exp;) {
> -        s = read(fd, &exp, sizeof(uint64_t));
> -        if (s != sizeof(uint64_t))
> +        s = read(fd, &exp, sizeof(exp));
> +        if (s != sizeof(exp))
>              handle_error("read");
> 
>          tot_exp += exp;
> 


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

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

* Re: [PATCH (2) 12/34] bsearch.3: Use sizeof consistently
  2020-09-04 13:46                                           ` [PATCH (2) 12/34] bsearch.3: " Alejandro Colomar
  2020-09-04 13:50                                             ` [PATCH (2) 13/34] cmsg.3: " Alejandro Colomar
@ 2020-09-04 15:17                                             ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:17 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 3:46 PM, Alejandro Colomar wrote:
>>From 886db3bad74f35fc40a1238a0d2f35ace3dc7620 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:43:23 +0200
> Subject: [PATCH 12/34] bsearch.3: 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>

Patch applied. Thanks!

Cheers,

Michael

> ---
>  man3/bsearch.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/bsearch.3 b/man3/bsearch.3
> index 88e0e6ea1..6859bdba2 100644
> --- a/man3/bsearch.3
> +++ b/man3/bsearch.3
> @@ -124,12 +124,12 @@ main(int argc, char **argv)
>  {
>      int i;
> 
> -    qsort(months, nr_of_months, sizeof(struct mi), compmi);
> +    qsort(months, nr_of_months, sizeof(months[0]), compmi);
>      for (i = 1; i < argc; i++) {
>          struct mi key, *res;
>          key.name = argv[i];
>          res = bsearch(&key, months, nr_of_months,
> -                      sizeof(struct mi), compmi);
> +                      sizeof(months[0]), compmi);
>          if (res == NULL)
>              printf("\(aq%s\(aq: unknown month\en", argv[i]);
>          else
> 


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

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

* Re: [PATCH (2) 13/34] cmsg.3: Use sizeof consistently
  2020-09-04 13:50                                             ` [PATCH (2) 13/34] cmsg.3: " Alejandro Colomar
  2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
@ 2020-09-04 15:18                                               ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:18 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,On 9/4/20 3:50 PM, Alejandro Colomar wrote:
>>From ba70b1e8addad4ef9f2a490d2069b112d09ba9f1 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:44:41 +0200
> Subject: [PATCH 13/34] cmsg.3: 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


Patch applied. Thanks.

Cheers,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/cmsg.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/cmsg.3 b/man3/cmsg.3
> index 99ee950f9..3d6288901 100644
> --- a/man3/cmsg.3
> +++ b/man3/cmsg.3
> @@ -203,7 +203,7 @@ for (cmsg = CMSG_FIRSTHDR(&msgh); cmsg != NULL;
>          cmsg = CMSG_NXTHDR(&msgh, cmsg)) {
>      if (cmsg\->cmsg_level == IPPROTO_IP
>              && cmsg\->cmsg_type == IP_TTL) {
> -        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(int));
> +        memcpy(&receive_ttl, CMSG_DATA(cmsg), sizeof(received_ttl));
>          break;
>      }
>  }
> 


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

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

* Re: [PATCH (2) 14/34] cmsg.3: Use sizeof consistently
  2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
  2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
  2020-09-04 13:54                                                 ` Alejandro Colomar
@ 2020-09-04 15:20                                                 ` Michael Kerrisk (man-pages)
  2 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:20 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 3:52 PM, Alejandro Colomar wrote:
>>From 374b31bee6762314ab48988e2e78a3a6a2f96834 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:44:54 +0200
> Subject: [PATCH 14/34] cmsg.3: 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>
> ---
>  man3/cmsg.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/cmsg.3 b/man3/cmsg.3
> index 3d6288901..8d0ad6666 100644
> --- a/man3/cmsg.3
> +++ b/man3/cmsg.3
> @@ -241,8 +241,8 @@ msg.msg_controllen = sizeof(u.buf);
>  cmsg = CMSG_FIRSTHDR(&msg);
>  cmsg\->cmsg_level = SOL_SOCKET;
>  cmsg\->cmsg_type = SCM_RIGHTS;
> -cmsg\->cmsg_len = CMSG_LEN(sizeof(int) * NUM_FD);
> -memcpy(CMSG_DATA(cmsg), myfds, sizeof(int) * NUM_FD);
> +cmsg\->cmsg_len = CMSG_LEN(sizeof(myfds));
> +memcpy(CMSG_DATA(cmsg), myfds, sizeof(myfds));
>  .EE
>  .in
>  .SH SEE ALSO

Thanks. Patch applied.

Cheers,

Michael



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

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

* Re: [PATCH (2) 15/34] getaddrinfo.3: Use sizeof consistently
  2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
  2020-09-04 14:32                                                   ` [PATCH (2) 16/34] " Alejandro Colomar
@ 2020-09-04 15:20                                                   ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:20 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 3:53 PM, Alejandro Colomar wrote:
>>From eef612c1f5f039421bd0fa167e1972e98d934bce Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:46:06 +0200
> Subject: [PATCH 15/34] getaddrinfo.3: 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>

Patch applied.

Cheers,

Michael

> ---
>  man3/getaddrinfo.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
> index 8aa544789..158fd2e31 100644
> --- a/man3/getaddrinfo.3
> +++ b/man3/getaddrinfo.3
> @@ -679,7 +679,7 @@ main(int argc, char *argv[])
>          exit(EXIT_FAILURE);
>      }
> 
> -    memset(&hints, 0, sizeof(struct addrinfo));
> +    memset(&hints, 0, sizeof(hints));
>      hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
>      hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
>      hints.ai_flags = AI_PASSIVE;    /* For wildcard IP address */
> @@ -775,7 +775,7 @@ main(int argc, char *argv[])
> 
>      /* Obtain address(es) matching host/port */
> 
> -    memset(&hints, 0, sizeof(struct addrinfo));
> +    memset(&hints, 0, sizeof(hints));
>      hints.ai_family = AF_UNSPEC;    /* Allow IPv4 or IPv6 */
>      hints.ai_socktype = SOCK_DGRAM; /* Datagram socket */
>      hints.ai_flags = 0;
> 


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

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

* Re: [PATCH (2) 16/34] getaddrinfo.3: Use sizeof consistently
  2020-09-04 14:32                                                   ` [PATCH (2) 16/34] " Alejandro Colomar
  2020-09-04 14:34                                                     ` [PATCH (2) 17/34] getgrouplist.3: " Alejandro Colomar
@ 2020-09-04 15:21                                                     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:21 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:32 PM, Alejandro Colomar wrote:
>>From f926f02eede41183aed7ae279eb333273bd0c8dc Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:46:35 +0200
> Subject: [PATCH 16/34] getaddrinfo.3: 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>

Patch applied. Thanks!

Cheers,

Michael


> ---
>  man3/getaddrinfo.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/getaddrinfo.3 b/man3/getaddrinfo.3
> index 158fd2e31..70e6b4cc0 100644
> --- a/man3/getaddrinfo.3
> +++ b/man3/getaddrinfo.3
> @@ -721,7 +721,7 @@ main(int argc, char *argv[])
>      /* Read datagrams and echo them back to sender */
> 
>      for (;;) {
> -        peer_addr_len = sizeof(struct sockaddr_storage);
> +        peer_addr_len = sizeof(peer_addr);
>          nread = recvfrom(sfd, buf, BUF_SIZE, 0,
>                  (struct sockaddr *) &peer_addr, &peer_addr_len);
>          if (nread == \-1)
> 


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

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

* Re: [PATCH (2) 17/34] getgrouplist.3: Use sizeof consistently
  2020-09-04 14:34                                                     ` [PATCH (2) 17/34] getgrouplist.3: " Alejandro Colomar
  2020-09-04 14:37                                                       ` [PATCH (2) 18/34] insque.3: " Alejandro Colomar
@ 2020-09-04 15:25                                                       ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:25 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:34 PM, Alejandro Colomar wrote:
>>From 7ca60fc88b831818c1f1722919af220a646761ab Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:47:15 +0200
> Subject: [PATCH 17/34] getgrouplist.3: 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>

Thanks. Applied.

Cheers,

Michael

> ---
>  man3/getgrouplist.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/getgrouplist.3 b/man3/getgrouplist.3
> index 372f2613f..ff8d89e3f 100644
> --- a/man3/getgrouplist.3
> +++ b/man3/getgrouplist.3
> @@ -164,7 +164,7 @@ main(int argc, char *argv[])
> 
>      ngroups = atoi(argv[2]);
> 
> -    groups = malloc(sizeof(gid_t) * ngroups);
> +    groups = malloc(sizeof(*groups) * ngroups);
>      if (groups == NULL) {
>          perror("malloc");
>          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/

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

* Re: [PATCH (2) 18/34] insque.3: Use sizeof consistently
  2020-09-04 14:37                                                       ` [PATCH (2) 18/34] insque.3: " Alejandro Colomar
  2020-09-04 14:41                                                         ` [PATCH (2) 19/34] malloc_info.3: " Alejandro Colomar
@ 2020-09-04 15:25                                                         ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:25 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:37 PM, Alejandro Colomar wrote:
>>From b43c812d1e129a8d2b34df7624a78baa3bf1273e Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:47:45 +0200
> Subject: [PATCH 18/34] insque.3: 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>

Thanks. Patch applied.

Cheers,

Michael


> ---
>  man3/insque.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/insque.3 b/man3/insque.3
> index a9fc28550..005ad8cc1 100644
> --- a/man3/insque.3
> +++ b/man3/insque.3
> @@ -182,7 +182,7 @@ new_element(void)
>  {
>      struct element *e;
> 
> -    e = malloc(sizeof(struct element));
> +    e = malloc(sizeof(*e));
>      if (e == NULL) {
>          fprintf(stderr, "malloc() failed\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/

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

* Re: [PATCH (2) 19/34] malloc_info.3: Use sizeof consistently
  2020-09-04 14:41                                                         ` [PATCH (2) 19/34] malloc_info.3: " Alejandro Colomar
  2020-09-04 14:44                                                           ` [PATCH (2) 20/34] mbsinit.3: " Alejandro Colomar
@ 2020-09-04 15:27                                                           ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:27 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:41 PM, Alejandro Colomar wrote:
>>From bf1a7799161fe1f08570c4f25d87a0f4e0b51ef1 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:49:17 +0200
> Subject: [PATCH 19/34] malloc_info.3: 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>

Thanks. Patch applied.

Cheers,

Michael

> ---
>  man3/malloc_info.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/malloc_info.3 b/man3/malloc_info.3
> index 0d95cdff7..598478dcc 100644
> --- a/man3/malloc_info.3
> +++ b/man3/malloc_info.3
> @@ -226,7 +226,7 @@ main(int argc, char *argv[])
>      blockSize = atoi(argv[3]);
>      sleepTime = (argc > 4) ? atoi(argv[4]) : 0;
> 
> -    thr = calloc(numThreads, sizeof(pthread_t));
> +    thr = calloc(numThreads, sizeof(*thr));
>      if (thr == NULL)
>          errExit("calloc");
> 


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

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

* Re: [PATCH (2) 20/34] mbsinit.3: Use sizeof consistently
  2020-09-04 14:44                                                           ` [PATCH (2) 20/34] mbsinit.3: " Alejandro Colomar
  2020-09-04 14:45                                                             ` [PATCH (2) 21/34] mbstowcs.3: " Alejandro Colomar
@ 2020-09-04 15:27                                                             ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:27 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:44 PM, Alejandro Colomar wrote:
>>From 77587b9c0b58cde232ea3bfaeef5f50607d83b5e Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:50:10 +0200
> Subject: [PATCH 20/34] mbsinit.3: 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

Thanks. Patch applied.

Cheers,

Michael

> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/mbsinit.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/mbsinit.3 b/man3/mbsinit.3
> index aeaa6ce88..74fe48f86 100644
> --- a/man3/mbsinit.3
> +++ b/man3/mbsinit.3
> @@ -59,7 +59,7 @@ in initial state is to set it to zero:
>  .in +4n
>  .EX
>  mbstate_t state;
> -memset(&state, 0, sizeof(mbstate_t));
> +memset(&state, 0, sizeof(state));
>  .EE
>  .in
>  .PP
> 


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

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

* Re: [PATCH (2) 28/34] strptime.3: Use sizeof consistently
  2020-09-04 14:57                                                                           ` [PATCH (2) 28/34] strptime.3: " Alejandro Colomar
@ 2020-09-04 15:37                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:37 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 4:57 PM, Alejandro Colomar wrote:
>>From f000e36d106a22d68f26e9cebe84758854739a42 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:56:21 +0200
> Subject: [PATCH 28/34] strptime.3: 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>

Patch applied.

Thanks,

Michael


> ---
>  man3/strptime.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/strptime.3 b/man3/strptime.3
> index d12f298ff..ab7d76f9a 100644
> --- a/man3/strptime.3
> +++ b/man3/strptime.3
> @@ -429,7 +429,7 @@ main(void)
>      struct tm tm;
>      char buf[255];
> 
> -    memset(&tm, 0, sizeof(struct tm));
> +    memset(&tm, 0, sizeof(tm));
>      strptime("2001\-11\-12 18:31:01", "%Y\-%m\-%d %H:%M:%S", &tm);
>      strftime(buf, sizeof(buf), "%d %b %Y %H:%M", &tm);
>      puts(buf);
> 


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

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

* Re: [PATCH (2) 31/34] fanotify.7: Use sizeof consistently
  2020-09-04 15:05                                                                           ` [PATCH (2) 31/34] fanotify.7: " Alejandro Colomar
@ 2020-09-04 15:38                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:38 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 5:05 PM, Alejandro Colomar wrote:
>>From 75af70465a8e60aa1d96b32d843b074966b7a878 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:58:14 +0200
> Subject: [PATCH 31/33] fanotify.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>

Thanks. Patch applied.

Cheers,

Michael



> ---
>  man7/fanotify.7 | 3 +--
>  1 file changed, 1 insertion(+), 2 deletions(-)
> 
> diff --git a/man7/fanotify.7 b/man7/fanotify.7
> index a7d60b2b9..29c818027 100644
> --- a/man7/fanotify.7
> +++ b/man7/fanotify.7
> @@ -808,8 +808,7 @@ handle_events(int fd)
> 
>                      response.fd = metadata\->fd;
>                      response.response = FAN_ALLOW;
> -                    write(fd, &response,
> -                          sizeof(struct fanotify_response));
> +                    write(fd, &response, sizeof(response));
>                  }
> 
>                  /* Handle closing of writable file event */
> 


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

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-04 15:08                                                                           ` [PATCH (2) 34/34] unix.7: " Alejandro Colomar
  2020-09-04 15:12                                                                             ` Alejandro Colomar
@ 2020-09-04 15:40                                                                             ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:40 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

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/

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

* Re: [PATCH (2) 23/34] pthread_setaffinity_np.3: Use sizeof consistently
  2020-09-04 14:50                                                                 ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Alejandro Colomar
  2020-09-04 14:50                                                                   ` [PATCH (2) 24/34] queue.3: " Alejandro Colomar
@ 2020-09-04 15:42                                                                   ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 15:42 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:50 PM, Alejandro Colomar wrote:
>>From ba0d73749a85e835aa43a4134a1b6906062943f3 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:53:12 +0200
> Subject: [PATCH 23/34] pthread_setaffinity_np.3: 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
> 

Thanks. Patch applied.

Cheers,

Michael



> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/pthread_setaffinity_np.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/pthread_setaffinity_np.3 b/man3/pthread_setaffinity_np.3
> index 24499f550..57aaf1251 100644
> --- a/man3/pthread_setaffinity_np.3
> +++ b/man3/pthread_setaffinity_np.3
> @@ -194,13 +194,13 @@ main(int argc, char *argv[])
>      for (j = 0; j < 8; j++)
>          CPU_SET(j, &cpuset);
> 
> -    s = pthread_setaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
> +    s = pthread_setaffinity_np(thread, sizeof(cpuset), &cpuset);
>      if (s != 0)
>          handle_error_en(s, "pthread_setaffinity_np");
> 
>      /* Check the actual affinity mask assigned to the thread */
> 
> -    s = pthread_getaffinity_np(thread, sizeof(cpu_set_t), &cpuset);
> +    s = pthread_getaffinity_np(thread, sizeof(cpuset), &cpuset);
>      if (s != 0)
>          handle_error_en(s, "pthread_getaffinity_np");
> 


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

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

* Re: [PATCH (2) 24/34] queue.3: Use sizeof consistently
  2020-09-04 14:50                                                                   ` [PATCH (2) 24/34] queue.3: " Alejandro Colomar
  2020-09-04 14:52                                                                     ` [PATCH (2) 25/34] rtnetlink.3: " Alejandro Colomar
@ 2020-09-04 16:58                                                                     ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 16:58 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:50 PM, Alejandro Colomar wrote:
>>From 6f3e17cf38bc3718332c7151899e253dbc91affb Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:53:51 +0200
> Subject: [PATCH 24/34] queue.3: 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>

I don't think this change improves readability. Looking at the code as
it is, one can immediately see that it is the same structure being 
allocated everywhere. After the change, that's not so obvious. I think
I won't apply this.

Cheers,

Michael

> ---
>  man3/queue.3 | 32 ++++++++++++++++----------------
>  1 file changed, 16 insertions(+), 16 deletions(-)
> 
> diff --git a/man3/queue.3 b/man3/queue.3
> index 55cd5847e..2ea5ff4f5 100644
> --- a/man3/queue.3
> +++ b/man3/queue.3
> @@ -559,10 +559,10 @@ struct entry {
> 
>  SLIST_INIT(&head);			/* Initialize the list. */
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the head. */
>  SLIST_INSERT_HEAD(&head, n1, entries);
> 
> -n2 = malloc(sizeof(struct entry));	/* Insert after. */
> +n2 = malloc(sizeof(*n2));		/* Insert after. */
>  SLIST_INSERT_AFTER(n1, n2, entries);
> 
>  SLIST_REMOVE(&head, n2, entry, entries);/* Deletion. */
> @@ -775,13 +775,13 @@ struct entry {
> 
>  STAILQ_INIT(&head);			/* Initialize the queue. */
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the head. */
>  STAILQ_INSERT_HEAD(&head, n1, entries);
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
>  STAILQ_INSERT_TAIL(&head, n1, entries);
> 
> -n2 = malloc(sizeof(struct entry));	/* Insert after. */
> +n2 = malloc(sizeof(*n2));		/* Insert after. */
>  STAILQ_INSERT_AFTER(&head, n1, n2, entries);
>  					/* Deletion. */
>  STAILQ_REMOVE(&head, n2, entry, entries);
> @@ -975,13 +975,13 @@ struct entry {
> 
>  LIST_INIT(&head);			/* Initialize the list. */
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the head. */
>  LIST_INSERT_HEAD(&head, n1, entries);
> 
> -n2 = malloc(sizeof(struct entry));	/* Insert after. */
> +n2 = malloc(sizeof(*n2));		/* Insert after. */
>  LIST_INSERT_AFTER(n1, n2, entries);
> 
> -n3 = malloc(sizeof(struct entry));	/* Insert before. */
> +n3 = malloc(sizeof(*n3));		/* Insert before. */
>  LIST_INSERT_BEFORE(n2, n3, entries);
> 
>  LIST_REMOVE(n2, entries);		/* Deletion. */
> @@ -1233,16 +1233,16 @@ struct entry {
> 
>  TAILQ_INIT(&head);			/* Initialize the queue. */
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the head. */
>  TAILQ_INSERT_HEAD(&head, n1, entries);
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
>  TAILQ_INSERT_TAIL(&head, n1, entries);
> 
> -n2 = malloc(sizeof(struct entry));	/* Insert after. */
> +n2 = malloc(sizeof(*n2));		/* Insert after. */
>  TAILQ_INSERT_AFTER(&head, n1, n2, entries);
> 
> -n3 = malloc(sizeof(struct entry));	/* Insert before. */
> +n3 = malloc(sizeof(*n3));		/* Insert before. */
>  TAILQ_INSERT_BEFORE(n2, n3, entries);
> 
>  TAILQ_REMOVE(&head, n2, entries);	/* Deletion. */
> @@ -1426,16 +1426,16 @@ struct entry {
> 
>  CIRCLEQ_INIT(&head);			/* Initialize the queue. */
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the head. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the head. */
>  CIRCLEQ_INSERT_HEAD(&head, n1, entries);
> 
> -n1 = malloc(sizeof(struct entry));	/* Insert at the tail. */
> +n1 = malloc(sizeof(*n1));		/* Insert at the tail. */
>  CIRCLEQ_INSERT_TAIL(&head, n1, entries);
> 
> -n2 = malloc(sizeof(struct entry));	/* Insert after. */
> +n2 = malloc(sizeof(*n2));		/* Insert after. */
>  CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
> 
> -n3 = malloc(sizeof(struct entry));	/* Insert before. */
> +n3 = malloc(sizeof(*n3));		/* Insert before. */
>  CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);
> 
>  CIRCLEQ_REMOVE(&head, n2, entries);	/* Deletion. */
> 


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

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

* Re: [PATCH (2) 25/34] rtnetlink.3: Use sizeof consistently
  2020-09-04 14:52                                                                     ` [PATCH (2) 25/34] rtnetlink.3: " Alejandro Colomar
  2020-09-04 14:54                                                                       ` [PATCH (2) 26/34] " Alejandro Colomar
@ 2020-09-04 16:59                                                                       ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 16:59 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:52 PM, Alejandro Colomar wrote:
>>From eca0c1500aa4db77c8c8d079798fe080e83e9935 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:55:00 +0200
> Subject: [PATCH 25/34] rtnetlink.3: 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>
> ---
>  man3/rtnetlink.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
> index 07bb1fbf9..2d9fa05a2 100644

Patch applied.

Thanks,

Michael


> --- a/man3/rtnetlink.3
> +++ b/man3/rtnetlink.3
> @@ -105,7 +105,7 @@ unsigned int mtu = 1000;
>  int rtnetlink_sk = socket(AF_NETLINK, SOCK_DGRAM, NETLINK_ROUTE);
> 
>  memset(&req, 0, sizeof(req));
> -req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(struct ifinfomsg));
> +req.nh.nlmsg_len = NLMSG_LENGTH(sizeof(req.if));
>  req.nh.nlmsg_flags = NLM_F_REQUEST;
>  req.nh.nlmsg_type = RTM_NEWLINK;
>  req.if.ifi_family = AF_UNSPEC;
> 


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

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

* Re: [PATCH (2) 26/34] rtnetlink.3: Use sizeof consistently
  2020-09-04 14:54                                                                       ` [PATCH (2) 26/34] " Alejandro Colomar
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
@ 2020-09-04 17:04                                                                         ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 17:04 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:54 PM, Alejandro Colomar wrote:
>>From 2b7a02916c24af8cbb0cbb071a7223fe48a52571 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:55:11 +0200
> Subject: [PATCH 26/34] rtnetlink.3: 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>

Thanks. Patch applied.

Cheers,

Michael

> ---
>  man3/rtnetlink.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/rtnetlink.3 b/man3/rtnetlink.3
> index 2d9fa05a2..f8b6c255a 100644
> --- a/man3/rtnetlink.3
> +++ b/man3/rtnetlink.3
> @@ -114,7 +114,7 @@ req.if.ifi_change = 0xffffffff; /* ??? */
>  rta = (struct rtattr *)(((char *) &req) +
>                           NLMSG_ALIGN(req.nh.nlmsg_len));
>  rta\->rta_type = IFLA_MTU;
> -rta\->rta_len = RTA_LENGTH(sizeof(unsigned int));
> +rta\->rta_len = RTA_LENGTH(sizeof(mtu));
>  req.nh.nlmsg_len = NLMSG_ALIGN(req.nh.nlmsg_len) +
>                                RTA_LENGTH(sizeof(mtu));
>  memcpy(RTA_DATA(rta), &mtu, sizeof(mtu));
> 


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

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

* Re: [PATCH (2) 32/34] inotify.7: Use sizeof consistently
  2020-09-04 15:06                                                                           ` [PATCH (2) 32/34] inotify.7: " Alejandro Colomar
@ 2020-09-04 17:08                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 17:08 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 5:06 PM, Alejandro Colomar wrote:
>>From 464c2941b936df850f03d7d9df382dc2c46f37f1 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:58:59 +0200
> Subject: [PATCH 32/34] inotify.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>

I think this change would weaken the example. The point is that when
traversing through these variable-length structures, the length of each
structure is the size of the fixed-size component (struct inotify_event)
plus the variable-length piece. The code as it stands emphasizes that.
The patch would leave that point less clear. I won't apply this one.

Thanks,

Michael

> ---
>  man7/inotify.7 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man7/inotify.7 b/man7/inotify.7
> index 9b2d7a4e5..4093bba5a 100644
> --- a/man7/inotify.7
> +++ b/man7/inotify.7
> @@ -968,7 +968,7 @@ handle_events(int fd, int *wd, int argc, char* argv[])
>          /* Loop over all events in the buffer */
> 
>          for (ptr = buf; ptr < buf + len;
> -                ptr += sizeof(struct inotify_event) + event\->len) {
> +                ptr += sizeof(*event) + event\->len) {
> 
>              event = (const struct inotify_event *) ptr;
> 


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

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

* Re: [PATCH (2) 33/34] inotify.7: Use sizeof consistently
  2020-09-04 15:07                                                                           ` [PATCH (2) 33/34] " Alejandro Colomar
@ 2020-09-04 17:14                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 17:14 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

I noticed that you sometimes split out several patches to the same
page. Thanks for doing that. As you realize sometimes, there might
be differnt decisions for different patches to the same page.

On 9/4/20 5:07 PM, Alejandro Colomar wrote:
>>From 0d4adf855466fe5c36e378eb704abafd45fc6417 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:59:11 +0200
> Subject: [PATCH 33/34] inotify.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>

The above said, I'm also not inclined to apply this patch. Watch 
descriptors are by definition 'int', so I don't think this change
improves readability. I think I won't apply this.

Cheers,

Michael

> ---
>  man7/inotify.7 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man7/inotify.7 b/man7/inotify.7
> index 4093bba5a..f1a1667e3 100644
> --- a/man7/inotify.7
> +++ b/man7/inotify.7
> @@ -1031,7 +1031,7 @@ main(int argc, char* argv[])
> 
>      /* Allocate memory for watch descriptors */
> 
> -    wd = calloc(argc, sizeof(int));
> +    wd = calloc(argc, sizeof(*wd));
>      if (wd == NULL) {
>          perror("calloc");
>          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/

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

* Re: [PATCH (2) 30/34] aio.7: Use sizeof consistently
  2020-09-04 15:04                                                                           ` [PATCH (2) 30/34] aio.7: " Alejandro Colomar
@ 2020-09-04 17:15                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 17:15 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 5:04 PM, Alejandro Colomar wrote:
>>From 33a09662331be9666c2f69dc60a792d9deee761e Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:57:28 +0200
> Subject: [PATCH 30/34] aio.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>

Thanks. Patch applied.

Cheers,

Michael

> ---
>  man7/aio.7 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man7/aio.7 b/man7/aio.7
> index dd05dce83..d3ab3f422 100644
> --- a/man7/aio.7
> +++ b/man7/aio.7
> @@ -311,11 +311,11 @@ main(int argc, char *argv[])
> 
>      /* Allocate our arrays */
> 
> -    ioList = calloc(numReqs, sizeof(struct ioRequest));
> +    ioList = calloc(numReqs, sizeof(*ioList));
>      if (ioList == NULL)
>          errExit("calloc");
> 
> -    aiocbList = calloc(numReqs, sizeof(struct aiocb));
> +    aiocbList = calloc(numReqs, sizeof(*aiocbList));
>      if (aiocbList == NULL)
>          errExit("calloc");
> 


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

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

* Re: [PATCH (2) 27/34] shm_open.3: Use sizeof consistently
  2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
                                                                                             ` (6 preceding siblings ...)
  2020-09-04 15:08                                                                           ` [PATCH (2) 34/34] unix.7: " Alejandro Colomar
@ 2020-09-04 17:26                                                                           ` Michael Kerrisk (man-pages)
  7 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-04 17:26 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:55 PM, Alejandro Colomar wrote:
>>From d3f439e697c9a384cad55e84a584493088eb4291 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:55:48 +0200
> Subject: [PATCH 27/34] shm_open.3: 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>

Thanks. Patch applied.

Cheers,

Michael

> ---
>  man3/shm_open.3 | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/man3/shm_open.3 b/man3/shm_open.3
> index bba4eb826..24cc6a403 100644
> --- a/man3/shm_open.3
> +++ b/man3/shm_open.3
> @@ -382,7 +382,7 @@ main(int argc, char *argv[])
> 
>      /* Map the object into the caller\(aqs address space */
> 
> -    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
> +    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
>                                 PROT_READ | PROT_WRITE,
>                                 MAP_SHARED, fd, 0);
>      if (shmp == MAP_FAILED)
> @@ -471,7 +471,7 @@ main(int argc, char *argv[])
>      if (fd == \-1)
>          errExit("shm_open");
> 
> -    struct shmbuf *shmp = mmap(NULL, sizeof(struct shmbuf),
> +    struct shmbuf *shmp = mmap(NULL, sizeof(*shmp),
>                                 PROT_READ | PROT_WRITE,
>                                 MAP_SHARED, fd, 0);
>      if (shmp == MAP_FAILED)
> 


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

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

* Re: [PATCH (2) 11/34] timerfd_create.2: Use sizeof consistently
  2020-09-04 15:14                                           ` [PATCH (2) 11/34] timerfd_create.2: " Michael Kerrisk (man-pages)
@ 2020-09-05  8:07                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05  8:07 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

On 9/4/20 5:14 PM, Michael Kerrisk (man-pages) wrote:
> Hello Alex,
> 
> On 9/4/20 3:45 PM, Alejandro Colomar wrote:
>> >From d347c933a8c253028f8f76c4170b65b85ce7d605 Mon Sep 17 00:00:00 2001
>> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
>> Date: Thu, 3 Sep 2020 21:42:28 +0200
>> Subject: [PATCH 11/34] timerfd_create.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@gmail.com>
> 
> Applied. Thanks!
> 
> Michael

I've changed my mind on this one (for similar reasons to patch 03/34).
The buffer here must be an 8-byte integer; it's baked into the API,
and I think it's helpful to show the type, to emphasize this point.
I've decided not to apply this patch.

Thanks,

Michael

>> ---
>>  man2/timerfd_create.2 | 4 ++--
>>  1 file changed, 2 insertions(+), 2 deletions(-)
>>
>> diff --git a/man2/timerfd_create.2 b/man2/timerfd_create.2
>> index 67a13dba3..fd4acf3e9 100644
>> --- a/man2/timerfd_create.2
>> +++ b/man2/timerfd_create.2
>> @@ -700,8 +700,8 @@ main(int argc, char *argv[])
>>      printf("timer started\en");
>>
>>      for (tot_exp = 0; tot_exp < max_exp;) {
>> -        s = read(fd, &exp, sizeof(uint64_t));
>> -        if (s != sizeof(uint64_t))
>> +        s = read(fd, &exp, sizeof(exp));
>> +        if (s != sizeof(exp))
>>              handle_error("read");
>>
>>          tot_exp += exp;
>>
> 
> 


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

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-04 15:12                                                                             ` Alejandro Colomar
@ 2020-09-05  8:27                                                                               ` Michael Kerrisk (man-pages)
  2020-09-05  9:37                                                                                 ` Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05  8:27 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hi Alex,

On 9/4/20 5:12 PM, Alejandro Colomar wrote:
> Hi Michael,
> 
> Sorry for the deep threading, I noticed it late and I tried to fix it in
> the last messages.  Also there's some email where I forgot to remove
> "Re:" from the subject.

Yes, the threading made things a little tricky, especially when it
came to trying to review what I'd done. Did you not send with 
"git send-email"? Usually that threads things nicely (all patches 
after the first as replies to the first patch).

> Well, that's all!  I can see 2 or 3 patches where I have doubts, but I
> think most of them are straightforward.

So, I've still not processed patches 21, 22, and 29. And in review,
I see that I am wondering about whether I should maintain 1, 5, 17,
18, and 19. These all involve the use of malloc() or similar.

The existing pattern was something like:

    struct mytype *x;   // Or some simple type such as 'int'
    ...
    x = malloc(n * sizeof(struct mytpe));

and your patches change it to:

    struct mytype *x;
    ...
    x = malloc(n * sizeof(*x));

I'm not sure that always helps readability.

Part of the problem is the use of C90 in the code.

Do you both agree with me that both of the following c99
forms are better than the original:

    struct mytype *x = malloc(n * sizeof(struct mytpe));
    struct mytype *x = malloc(n * sizeof(*x));

?

I *think* I mildly prefer the first form, but I'm open to
arguments that the latter form is preferable. Of course, the
fact that there might be more than one point where an 'alloc'
is done and assigned to 'x' may influence the argument. Thus


    struct mytype *x = malloc(n * sizeof(struct mytpe));
    ...
    x = malloc(p * sizeof(struct mytype));

vs

    struct mytype *x = malloc(n * sizeof(*x));
    ...
    x = malloc(p * sizeof(*x));

Thanks,

Michael

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

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-05  8:27                                                                               ` Michael Kerrisk (man-pages)
@ 2020-09-05  9:37                                                                                 ` Alejandro Colomar
  2020-09-05 14:38                                                                                   ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-05  9:37 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man, Jakub Wilk

Hi Michael,

On 9/5/20 10:27 AM, Michael Kerrisk (man-pages) wrote:
> Yes, the threading made things a little tricky, especially when it
> came to trying to review what I'd done. Did you not send with 
> "git send-email"? Usually that threads things nicely (all patches 
> after the first as replies to the first patch).

In this case, I didn't, because the conversation was already started,
even the set of patches was already started, and I had to edit all of
the subjects, and sometimes add introductory messages, and I felt more
comfortable with the GUI.

> So, I've still not processed patches 21, 22, and 29. And in review,
> I see that I am wondering about whether I should maintain 1, 5, 17,
> 18, and 19. These all involve the use of malloc() or similar.
> 
> The existing pattern was something like:
> 
>     struct mytype *x;   // Or some simple type such as 'int'
>     ...
>     x = malloc(n * sizeof(struct mytpe));

Not to forget `malloc(sizeof(struct mytpe) * n);`

> 
> and your patches change it to:
> 
>     struct mytype *x;
>     ...
>     x = malloc(n * sizeof(*x));>
> I'm not sure that always helps readability.
> 
> Part of the problem is the use of C90 in the code.
> 
> Do you both agree with me that both of the following c99
> forms are better than the original:
> 
>     struct mytype *x = malloc(n * sizeof(struct mytpe));
>     struct mytype *x = malloc(n * sizeof(*x));
> 
> ?

Yes, I would say both of these are an improvement.
> 
> I *think* I mildly prefer the first form, but I'm open to
> arguments that the latter form is preferable. Of course, the
> fact that there might be more than one point where an 'alloc'
> is done and assigned to 'x' may influence the argument. Thus
> 
> 
>     struct mytype *x = malloc(n * sizeof(struct mytpe));
>     ...
>     x = malloc(p * sizeof(struct mytype));
> 
> vs
> 
>     struct mytype *x = malloc(n * sizeof(*x));
>     ...
>     x = malloc(p * sizeof(*x));

In case there are 2 or more allocs, in general, I prefer the name of the
variable.

In case there is only 1 alloc in the same line as the declaration, I
still prefer the name of the variable: for consistency, and because some
day you may add another alloc, and then separate the original
declaration+alloc in two lines, and forget to fix sizeof to use the name
of the variable.

The cases where I see the type much better are cases where it is
impossible for the type to change (and if it ever changed it would be an
accident and cause a deserved bug) such as in those cases where you
really need an (u)int64_t because of the API.

There's also cases where in real code I would prefer the name of the
variable (to avoid future bugs because of type change), but in the man
pages it is clearer if you write the type to be more explicit and
consistent.  Example: queue.3 (PATCH 24/34): It's clearer if you
consistently use the type across all the code (and it may be therefore
better to use it in the man-pages), because the name of the variable
looks like it's different from one alloc to the next, but I can imagine
some real code implementing a TAILQ and later deciding to use a CIRCLEQ,
and if any of the types in the allocation are not updated accordingly,
there will appear bugs, while if the name of the node is used for
allocating the memory, the transition will be really simple.

Regards,
Alex.

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

* [PATCH 35/35] qsort.3: Use sizeof consistently
  2020-08-24 13:29 [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently Alejandro Colomar
  2020-08-25 10:29 ` Michael Kerrisk (man-pages)
@ 2020-09-05 14:20 ` Alejandro Colomar
  2020-09-05 14:23   ` Alejandro Colomar
  2020-09-05 15:27   ` Michael Kerrisk (man-pages)
  1 sibling, 2 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-05 14:20 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, Alejandro Colomar

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>
---
 man3/qsort.3 | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/man3/qsort.3 b/man3/qsort.3
index b49c2a9d3..e1af43cf0 100644
--- a/man3/qsort.3
+++ b/man3/qsort.3
@@ -150,7 +150,7 @@ main(int argc, char *argv[])
         exit(EXIT_FAILURE);
     }
 
-    qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
+    qsort(&argv[1], argc \- 1, sizeof(argv[0]), cmpstringp);
 
     for (j = 1; j < argc; j++)
         puts(argv[j]);
-- 
2.28.0


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

* Re: [PATCH (2) 21/34] mbstowcs.3: Use sizeof consistently
  2020-09-04 14:45                                                             ` [PATCH (2) 21/34] mbstowcs.3: " Alejandro Colomar
  2020-09-04 14:48                                                               ` [PATCH (2) 22/34] pthread_create.3: " Alejandro Colomar
@ 2020-09-05 14:21                                                               ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 14:21 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:45 PM, Alejandro Colomar wrote:
>>From 1b70e7a1da093e4a8e3be79aaed623b21c10e763 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:51:07 +0200
> Subject: [PATCH 21/34] mbstowcs.3: 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

Patch applied.

Cheers,

Michael

> 
> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/mbstowcs.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/mbstowcs.3 b/man3/mbstowcs.3
> index cf650506e..2f9fbc17c 100644
> --- a/man3/mbstowcs.3
> +++ b/man3/mbstowcs.3
> @@ -186,7 +186,7 @@ main(int argc, char *argv[])
>      /* Allocate wide character string of the desired size.  Add 1
>         to allow for terminating null wide character (L\(aq\e0\(aq). */
> 
> -    wcs = calloc(mbslen + 1, sizeof(wchar_t));
> +    wcs = calloc(mbslen + 1, sizeof(*wcs));
>      if (wcs == NULL) {
>          perror("calloc");
>          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/

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

* Re: [PATCH (2) 22/34] pthread_create.3: Use sizeof consistently
  2020-09-04 14:48                                                               ` [PATCH (2) 22/34] pthread_create.3: " Alejandro Colomar
  2020-09-04 14:50                                                                 ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Alejandro Colomar
@ 2020-09-05 14:21                                                                 ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 14:21 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 4:48 PM, Alejandro Colomar wrote:
>>From 03783d811fad4783b394c01a4ac68ca6d92b6c58 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:52:22 +0200
> Subject: [PATCH 22/34] pthread_create.3: 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


Patch applied.

Cheers,

Michael


> Signed-off-by: Alejandro Colomar <colomar.6.4.3@gmail.com>
> ---
>  man3/pthread_create.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/pthread_create.3 b/man3/pthread_create.3
> index d86188e6b..5ffb14586 100644
> --- a/man3/pthread_create.3
> +++ b/man3/pthread_create.3
> @@ -361,7 +361,7 @@ main(int argc, char *argv[])
> 
>      /* Allocate memory for pthread_create() arguments */
> 
> -    tinfo = calloc(num_threads, sizeof(struct thread_info));
> +    tinfo = calloc(num_threads, sizeof(*tinfo));
>      if (tinfo == NULL)
>          handle_error("calloc");
> 


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

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

* Re: [PATCH (2) 29/34] tsearch.3: Use sizeof consistently
  2020-09-04 15:03                                                                           ` [PATCH (2) 29/34] tsearch.3: " Alejandro Colomar
@ 2020-09-05 14:22                                                                             ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 14:22 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/4/20 5:03 PM, Alejandro Colomar wrote:
>>From ff3fe9cdfd280fce97e9289e9a91fb6cc2c1c368 Mon Sep 17 00:00:00 2001
> From: Alejandro Colomar <colomar.6.4.3@gmail.com>
> Date: Thu, 3 Sep 2020 21:56:52 +0200
> Subject: [PATCH 29/34] tsearch.3: 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>


Patch applied.

Cheers,

Michael


> ---
>  man3/tsearch.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/tsearch.3 b/man3/tsearch.3
> index 452395d6b..f0ff80e8c 100644
> --- a/man3/tsearch.3
> +++ b/man3/tsearch.3
> @@ -327,7 +327,7 @@ main(void)
> 
>      srand(time(NULL));
>      for (i = 0; i < 12; i++) {
> -        ptr = xmalloc(sizeof(int));
> +        ptr = xmalloc(sizeof(*ptr));
>          *ptr = rand() & 0xff;
>          val = tsearch((void *) ptr, &root, compare);
>          if (val == NULL)
> 


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

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

* Re: [PATCH 35/35] qsort.3: Use sizeof consistently
  2020-09-05 14:20 ` [PATCH 35/35] qsort.3: " Alejandro Colomar
@ 2020-09-05 14:23   ` Alejandro Colomar
  2020-09-05 15:27   ` Michael Kerrisk (man-pages)
  1 sibling, 0 replies; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-05 14:23 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, Jakub Wilk

Hi Michael,

This one I sent it with git.  It is *really* *really* simple :)

Cheers,
Alex

On 9/5/20 4:20 PM, Alejandro Colomar wrote:
> 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>
> ---
>  man3/qsort.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/qsort.3 b/man3/qsort.3
> index b49c2a9d3..e1af43cf0 100644
> --- a/man3/qsort.3
> +++ b/man3/qsort.3
> @@ -150,7 +150,7 @@ main(int argc, char *argv[])
>          exit(EXIT_FAILURE);
>      }
>  
> -    qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
> +    qsort(&argv[1], argc \- 1, sizeof(argv[0]), cmpstringp);
>  
>      for (j = 1; j < argc; j++)
>          puts(argv[j]);
> 

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-05  9:37                                                                                 ` Alejandro Colomar
@ 2020-09-05 14:38                                                                                   ` Michael Kerrisk (man-pages)
  2020-09-05 14:52                                                                                     ` Alejandro Colomar
  0 siblings, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 14:38 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: linux-man, Jakub Wilk

Hello Alex,

On Sat, 5 Sep 2020 at 11:37, Alejandro Colomar <colomar.6.4.3@gmail.com> wrote:
>
> Hi Michael,
>
> On 9/5/20 10:27 AM, Michael Kerrisk (man-pages) wrote:
[...]
> So, I've still not processed patches 21, 22, and 29. And in review,
> > I see that I am wondering about whether I should maintain 1, 5, 17,
> > 18, and 19. These all involve the use of malloc() or similar.
> >
> > The existing pattern was something like:
> >
> >     struct mytype *x;   // Or some simple type such as 'int'
> >     ...
> >     x = malloc(n * sizeof(struct mytpe));
>
> Not to forget `malloc(sizeof(struct mytpe) * n);`

<Cough> yes <cough>...

> > and your patches change it to:
> >
> >     struct mytype *x;
> >     ...
> >     x = malloc(n * sizeof(*x));>
> > I'm not sure that always helps readability.
> >
> > Part of the problem is the use of C90 in the code.
> >
> > Do you both agree with me that both of the following c99
> > forms are better than the original:
> >
> >     struct mytype *x = malloc(n * sizeof(struct mytpe));
> >     struct mytype *x = malloc(n * sizeof(*x));
> >
> > ?
>
> Yes, I would say both of these are an improvement.
> >
> > I *think* I mildly prefer the first form, but I'm open to
> > arguments that the latter form is preferable. Of course, the
> > fact that there might be more than one point where an 'alloc'
> > is done and assigned to 'x' may influence the argument. Thus
> >
> >
> >     struct mytype *x = malloc(n * sizeof(struct mytpe));
> >     ...
> >     x = malloc(p * sizeof(struct mytype));
> >
> > vs
> >
> >     struct mytype *x = malloc(n * sizeof(*x));
> >     ...
> >     x = malloc(p * sizeof(*x));
>
> In case there are 2 or more allocs, in general, I prefer the name of the
> variable.

Yes, by the time I'd written the two allocs examples, I'd started to
lean that way too, but didn't say so because I wanted to hear your
independent perspective .

> In case there is only 1 alloc in the same line as the declaration, I
> still prefer the name of the variable: for consistency, and because some
> day you may add another alloc, and then separate the original
> declaration+alloc in two lines, and forget to fix sizeof to use the name
> of the variable.

Yes.

> The cases where I see the type much better are cases where it is
> impossible for the type to change (and if it ever changed it would be an
> accident and cause a deserved bug) such as in those cases where you
> really need an (u)int64_t because of the API.

Yes.

> There's also cases where in real code I would prefer the name of the
> variable (to avoid future bugs because of type change), but in the man
> pages it is clearer if you write the type to be more explicit and
> consistent.  Example: queue.3 (PATCH 24/34): It's clearer if you
> consistently use the type across all the code (and it may be therefore
> better to use it in the man-pages), because the name of the variable
> looks like it's different from one alloc to the next, but I can imagine
> some real code implementing a TAILQ and later deciding to use a CIRCLEQ,
> and if any of the types in the allocation are not updated accordingly,
> there will appear bugs, while if the name of the node is used for
> allocating the memory, the transition will be really simple.

Agreed.

I've applied patches 21, 22, and 29. And then in line with our
discussion above, I moved some pages to the style discussed above:

struct mytype *x = malloc(sizeof(*x));

See commit 48d05103071830b6708a3ecabeddcdef5f3daa44.

Thanks for your input Alex, it's been really helpful!

Cheers,

Michael

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

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-05 14:38                                                                                   ` Michael Kerrisk (man-pages)
@ 2020-09-05 14:52                                                                                     ` Alejandro Colomar
  2020-09-05 15:24                                                                                       ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-05 14:52 UTC (permalink / raw)
  To: mtk.manpages; +Cc: linux-man, Jakub Wilk

Hello Michael,

On 9/5/20 4:38 PM, Michael Kerrisk (man-pages) wrote:
> See commit 48d05103071830b6708a3ecabeddcdef5f3daa44.

It looks good.  Maybe I'd keep the cosmetic blank line after the
declaration+alloc in insque.3...

> Thanks for your input Alex, it's been really helpful!

Thank you very much!  I'm really happy to read that!
I learnt a lot these days.

Cheers,
Alex.

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

* Re: [PATCH (2) 34/34] unix.7: Use sizeof consistently
  2020-09-05 14:52                                                                                     ` Alejandro Colomar
@ 2020-09-05 15:24                                                                                       ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 15:24 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man, Jakub Wilk

Hello Alex,

On 9/5/20 4:52 PM, Alejandro Colomar wrote:
> Hello Michael,
> 
> On 9/5/20 4:38 PM, Michael Kerrisk (man-pages) wrote:
>> See commit 48d05103071830b6708a3ecabeddcdef5f3daa44.
> 
> It looks good.  Maybe I'd keep the cosmetic blank line after the
> declaration+alloc in insque.3...

I kinda prefer not to have it.

>> Thanks for your input Alex, it's been really helpful!
> 
> Thank you very much!  I'm really happy to read that!
> I learnt a lot these days.

I learned a few things too :-).

Cheers,

Michael

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

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

* Re: [PATCH 35/35] qsort.3: Use sizeof consistently
  2020-09-05 14:20 ` [PATCH 35/35] qsort.3: " Alejandro Colomar
  2020-09-05 14:23   ` Alejandro Colomar
@ 2020-09-05 15:27   ` Michael Kerrisk (man-pages)
  2020-09-05 15:32     ` Alejandro Colomar
  1 sibling, 1 reply; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 15:27 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man

On 9/5/20 4:20 PM, Alejandro Colomar wrote:
> 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>

I'm not convinced about this one. Do you really think it
improves readability? I kinda feel that it does not.

Thanks,

Michael

> ---
>  man3/qsort.3 | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/man3/qsort.3 b/man3/qsort.3
> index b49c2a9d3..e1af43cf0 100644
> --- a/man3/qsort.3
> +++ b/man3/qsort.3
> @@ -150,7 +150,7 @@ main(int argc, char *argv[])
>          exit(EXIT_FAILURE);
>      }
>  
> -    qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
> +    qsort(&argv[1], argc \- 1, sizeof(argv[0]), cmpstringp);
>  
>      for (j = 1; j < argc; j++)
>          puts(argv[j]);
> 


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

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

* Re: [PATCH 35/35] qsort.3: Use sizeof consistently
  2020-09-05 15:27   ` Michael Kerrisk (man-pages)
@ 2020-09-05 15:32     ` Alejandro Colomar
  2020-09-05 15:36       ` Michael Kerrisk (man-pages)
  0 siblings, 1 reply; 92+ messages in thread
From: Alejandro Colomar @ 2020-09-05 15:32 UTC (permalink / raw)
  To: Michael Kerrisk (man-pages); +Cc: linux-man

On 9/5/20 5:27 PM, Michael Kerrisk (man-pages) wrote:> On 9/5/20 4:20
PM, Alejandro Colomar wrote:
>> 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>
>
> I'm not convinced about this one. Do you really think it
> improves readability? I kinda feel that it does not.

Well, I have two different ideas for this one.
In terms of readability, `char *` might seem clearer.
In terms of preventing bugs, `argv[0]` seems safer.
For real code I would use the latter.  For the man, I have doubts.

Follow your intuition :)

>
> Thanks,
>
> Michael
>
>> ---
>>  man3/qsort.3 | 2 +-
>>  1 file changed, 1 insertion(+), 1 deletion(-)
>>
>> diff --git a/man3/qsort.3 b/man3/qsort.3
>> index b49c2a9d3..e1af43cf0 100644
>> --- a/man3/qsort.3
>> +++ b/man3/qsort.3
>> @@ -150,7 +150,7 @@ main(int argc, char *argv[])
>>          exit(EXIT_FAILURE);
>>      }
>>
>> -    qsort(&argv[1], argc \- 1, sizeof(char *), cmpstringp);
>> +    qsort(&argv[1], argc \- 1, sizeof(argv[0]), cmpstringp);
>>
>>      for (j = 1; j < argc; j++)
>>          puts(argv[j]);
>>
>
>

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

* Re: [PATCH 35/35] qsort.3: Use sizeof consistently
  2020-09-05 15:32     ` Alejandro Colomar
@ 2020-09-05 15:36       ` Michael Kerrisk (man-pages)
  0 siblings, 0 replies; 92+ messages in thread
From: Michael Kerrisk (man-pages) @ 2020-09-05 15:36 UTC (permalink / raw)
  To: Alejandro Colomar; +Cc: mtk.manpages, linux-man

On 9/5/20 5:32 PM, Alejandro Colomar wrote:
> On 9/5/20 5:27 PM, Michael Kerrisk (man-pages) wrote:> On 9/5/20 4:20
> PM, Alejandro Colomar wrote:
>>> 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>
>>
>> I'm not convinced about this one. Do you really think it
>> improves readability? I kinda feel that it does not.
> 
> Well, I have two different ideas for this one.
> In terms of readability, `char *` might seem clearer.
> In terms of preventing bugs, `argv[0]` seems safer.
> For real code I would use the latter.  For the man, I have doubts.
> 
> Follow your intuition :)

Nothing personal, but I'm rejecting this one :-).


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

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

end of thread, other threads:[~2020-09-05 15:36 UTC | newest]

Thread overview: 92+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-24 13:29 [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: Use sizeof consistently Alejandro Colomar
2020-08-25 10:29 ` Michael Kerrisk (man-pages)
2020-08-25 11:19   ` Jakub Wilk
2020-08-25 11:34     ` Alejandro Colomar
2020-08-25 11:41       ` Michael Kerrisk (man-pages)
2020-08-25 11:48         ` Alejandro Colomar
2020-08-25 12:21           ` Alejandro Colomar
2020-08-25 12:35             ` Michael Kerrisk (man-pages)
2020-08-25 13:05               ` [PATCH] cmsg.3, getaddrinfo_a.3 getgrouplist.3: Use sizeof, consistently Alejandro Colomar
2020-08-26  6:21                 ` Michael Kerrisk (man-pages)
2020-09-03 10:23                   ` [PATCH] memusage.1: Use sizeof consistently Alejandro Colomar
2020-09-04  8:20                     ` Michael Kerrisk (man-pages)
2020-09-04 10:19                       ` [PATCH (2) 02/34] bind.2: " Alejandro Colomar
2020-09-04 10:21                         ` [PATCH (2) 03/34] eventfd.2: " Alejandro Colomar
2020-09-04 10:46                           ` Michael Kerrisk (man-pages)
2020-09-04 10:54                           ` [PATCH (2) 04/34] futex.2: " Alejandro Colomar
2020-09-04 10:55                             ` [PATCH (2) 05/34] open_by_handle_at.2: " Alejandro Colomar
2020-09-04 10:56                               ` [PATCH (2) 06/34] perf_event_open.2: " Alejandro Colomar
2020-09-04 10:57                                 ` [PATCH (2) 07/34] " Alejandro Colomar
2020-09-04 12:25                                   ` Michael Kerrisk (man-pages)
2020-09-04 13:42                                   ` [PATCH (2) 08/34] poll.2: " Alejandro Colomar
2020-09-04 13:43                                     ` [PATCH (2) 09/34] sysctl.2: " Alejandro Colomar
2020-09-04 13:44                                       ` [PATCH (2) 10/34] signalfd.2: " Alejandro Colomar
2020-09-04 13:45                                         ` [PATCH (2) 11/34] timerfd_create.2: " Alejandro Colomar
2020-09-04 13:46                                           ` [PATCH (2) 12/34] bsearch.3: " Alejandro Colomar
2020-09-04 13:50                                             ` [PATCH (2) 13/34] cmsg.3: " Alejandro Colomar
2020-09-04 13:52                                               ` [PATCH (2) 14/34] " Alejandro Colomar
2020-09-04 13:53                                                 ` [PATCH (2) 15/34] getaddrinfo.3: " Alejandro Colomar
2020-09-04 14:32                                                   ` [PATCH (2) 16/34] " Alejandro Colomar
2020-09-04 14:34                                                     ` [PATCH (2) 17/34] getgrouplist.3: " Alejandro Colomar
2020-09-04 14:37                                                       ` [PATCH (2) 18/34] insque.3: " Alejandro Colomar
2020-09-04 14:41                                                         ` [PATCH (2) 19/34] malloc_info.3: " Alejandro Colomar
2020-09-04 14:44                                                           ` [PATCH (2) 20/34] mbsinit.3: " Alejandro Colomar
2020-09-04 14:45                                                             ` [PATCH (2) 21/34] mbstowcs.3: " Alejandro Colomar
2020-09-04 14:48                                                               ` [PATCH (2) 22/34] pthread_create.3: " Alejandro Colomar
2020-09-04 14:50                                                                 ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Alejandro Colomar
2020-09-04 14:50                                                                   ` [PATCH (2) 24/34] queue.3: " Alejandro Colomar
2020-09-04 14:52                                                                     ` [PATCH (2) 25/34] rtnetlink.3: " Alejandro Colomar
2020-09-04 14:54                                                                       ` [PATCH (2) 26/34] " Alejandro Colomar
2020-09-04 14:55                                                                         ` [PATCH (2) 27/34] shm_open.3: " Alejandro Colomar
2020-09-04 14:57                                                                           ` [PATCH (2) 28/34] strptime.3: " Alejandro Colomar
2020-09-04 15:37                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:03                                                                           ` [PATCH (2) 29/34] tsearch.3: " Alejandro Colomar
2020-09-05 14:22                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:04                                                                           ` [PATCH (2) 30/34] aio.7: " Alejandro Colomar
2020-09-04 17:15                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:05                                                                           ` [PATCH (2) 31/34] fanotify.7: " Alejandro Colomar
2020-09-04 15:38                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:06                                                                           ` [PATCH (2) 32/34] inotify.7: " Alejandro Colomar
2020-09-04 17:08                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:07                                                                           ` [PATCH (2) 33/34] " Alejandro Colomar
2020-09-04 17:14                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:08                                                                           ` [PATCH (2) 34/34] unix.7: " Alejandro Colomar
2020-09-04 15:12                                                                             ` Alejandro Colomar
2020-09-05  8:27                                                                               ` Michael Kerrisk (man-pages)
2020-09-05  9:37                                                                                 ` Alejandro Colomar
2020-09-05 14:38                                                                                   ` Michael Kerrisk (man-pages)
2020-09-05 14:52                                                                                     ` Alejandro Colomar
2020-09-05 15:24                                                                                       ` Michael Kerrisk (man-pages)
2020-09-04 15:40                                                                             ` Michael Kerrisk (man-pages)
2020-09-04 17:26                                                                           ` [PATCH (2) 27/34] shm_open.3: " Michael Kerrisk (man-pages)
2020-09-04 17:04                                                                         ` [PATCH (2) 26/34] rtnetlink.3: " Michael Kerrisk (man-pages)
2020-09-04 16:59                                                                       ` [PATCH (2) 25/34] " Michael Kerrisk (man-pages)
2020-09-04 16:58                                                                     ` [PATCH (2) 24/34] queue.3: " Michael Kerrisk (man-pages)
2020-09-04 15:42                                                                   ` [PATCH (2) 23/34] pthread_setaffinity_np.3: " Michael Kerrisk (man-pages)
2020-09-05 14:21                                                                 ` [PATCH (2) 22/34] pthread_create.3: " Michael Kerrisk (man-pages)
2020-09-05 14:21                                                               ` [PATCH (2) 21/34] mbstowcs.3: " Michael Kerrisk (man-pages)
2020-09-04 15:27                                                             ` [PATCH (2) 20/34] mbsinit.3: " Michael Kerrisk (man-pages)
2020-09-04 15:27                                                           ` [PATCH (2) 19/34] malloc_info.3: " Michael Kerrisk (man-pages)
2020-09-04 15:25                                                         ` [PATCH (2) 18/34] insque.3: " Michael Kerrisk (man-pages)
2020-09-04 15:25                                                       ` [PATCH (2) 17/34] getgrouplist.3: " Michael Kerrisk (man-pages)
2020-09-04 15:21                                                     ` [PATCH (2) 16/34] getaddrinfo.3: " Michael Kerrisk (man-pages)
2020-09-04 15:20                                                   ` [PATCH (2) 15/34] " Michael Kerrisk (man-pages)
2020-09-04 13:54                                                 ` Alejandro Colomar
2020-09-04 15:20                                                 ` [PATCH (2) 14/34] cmsg.3: " Michael Kerrisk (man-pages)
2020-09-04 15:18                                               ` [PATCH (2) 13/34] " Michael Kerrisk (man-pages)
2020-09-04 15:17                                             ` [PATCH (2) 12/34] bsearch.3: " Michael Kerrisk (man-pages)
2020-09-04 15:14                                           ` [PATCH (2) 11/34] timerfd_create.2: " Michael Kerrisk (man-pages)
2020-09-05  8:07                                             ` Michael Kerrisk (man-pages)
2020-09-04 15:13                                         ` [PATCH (2) 10/34] signalfd.2: " Michael Kerrisk (man-pages)
2020-09-04 15:11                                       ` [PATCH (2) 09/34] sysctl.2: " Michael Kerrisk (man-pages)
2020-09-04 15:11                                     ` [PATCH (2) 08/34] poll.2: " Michael Kerrisk (man-pages)
2020-09-04 12:24                                 ` [PATCH (2) 06/34] perf_event_open.2: " Michael Kerrisk (man-pages)
2020-09-04 12:20                               ` [PATCH (2) 05/34] open_by_handle_at.2: " Michael Kerrisk (man-pages)
2020-09-04 12:19                             ` [PATCH (2) 04/34] futex.2: " Michael Kerrisk (man-pages)
2020-09-04 10:44                         ` [PATCH (2) 02/34] bind.2: " Michael Kerrisk (man-pages)
2020-08-25 11:35     ` [patch] memusage.1, bind.2, eventfd.2, futex.2, open_by_handle_at.2, perf_event_open.2, poll.2, signalfd.2, sysctl.2, timerfd_create.2, bsearch.3, cmsg.3, getaddrinfo.3, getaddrinfo_a.3 getgrouplist.3, insque.3, malloc_info.3, mbsinit.3, mbstowcs.3, pthread_create.3, pthread_setaffinity_np.3, queue.3, rtnetlink.3, shm_open.3, strptime.3, tsearch.3, aio.7, fanotify.7, inotify.7, unix.7: " Michael Kerrisk (man-pages)
2020-09-05 14:20 ` [PATCH 35/35] qsort.3: " Alejandro Colomar
2020-09-05 14:23   ` Alejandro Colomar
2020-09-05 15:27   ` Michael Kerrisk (man-pages)
2020-09-05 15:32     ` Alejandro Colomar
2020-09-05 15:36       ` Michael Kerrisk (man-pages)

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.