summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <colomar.6.4.3@gmail.com>2020-09-03 21:25:59 +0200
committerAlejandro Colomar <alx.manpages@gmail.com>2021-09-05 15:06:17 +0200
commit3c621767d197c0831e05314fcd8dc8e7d4adae68 (patch)
treedf32f4d173cc3d7d19424ff6bb40fc79c170d80a
parentd948af19963476c7cd1f1fc3f19c3f0b1afb247f (diff)
eventfd.2, poll.2, timerfd_create.2,
circleq.3, list.3, qsort.3, slist.3, stailq.3, tailq.3, 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>
-rw-r--r--man2/eventfd.28
-rw-r--r--man2/poll.22
-rw-r--r--man2/timerfd_create.24
-rw-r--r--man3/circleq.38
-rw-r--r--man3/list.36
-rw-r--r--man3/qsort.32
-rw-r--r--man3/slist.36
-rw-r--r--man3/stailq.38
-rw-r--r--man3/tailq.38
-rw-r--r--man7/inotify.72
10 files changed, 27 insertions, 27 deletions
diff --git a/man2/eventfd.2 b/man2/eventfd.2
index 6e2d0a99a..8944f4527 100644
--- a/man2/eventfd.2
+++ b/man2/eventfd.2
@@ -422,8 +422,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");
@@ -434,8 +434,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 %"PRIu64" (%#"PRIx64") from efd\en", u, u);
exit(EXIT_SUCCESS);
diff --git a/man2/poll.2 b/man2/poll.2
index 205468f3e..5830ea129 100644
--- a/man2/poll.2
+++ b/man2/poll.2
@@ -595,7 +595,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/timerfd_create.2 b/man2/timerfd_create.2
index 65fdfcc45..dd586493a 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/circleq.3 b/man3/circleq.3
index cb3918b53..50075aac7 100644
--- a/man3/circleq.3
+++ b/man3/circleq.3
@@ -301,16 +301,16 @@ main(void)
CIRCLEQ_INIT(&head); /* Initialize the queue */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the head */
CIRCLEQ_INSERT_HEAD(&head, n1, entries);
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the tail */
CIRCLEQ_INSERT_TAIL(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after */
+ n2 = malloc(sizeof(struct *n2)); /* Insert after */
CIRCLEQ_INSERT_AFTER(&head, n1, n2, entries);
- n3 = malloc(sizeof(struct entry)); /* Insert before */
+ n3 = malloc(sizeof(struct *n3)); /* Insert before */
CIRCLEQ_INSERT_BEFORE(&head, n2, n3, entries);
CIRCLEQ_REMOVE(&head, n2, entries); /* Deletion */
diff --git a/man3/list.3 b/man3/list.3
index 04bb41668..7b8dba092 100644
--- a/man3/list.3
+++ b/man3/list.3
@@ -292,13 +292,13 @@ main(void)
LIST_INIT(&head); /* Initialize the list */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the head */
LIST_INSERT_HEAD(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after */
+ n2 = malloc(sizeof(struct *n2)); /* Insert after */
LIST_INSERT_AFTER(n1, n2, entries);
- n3 = malloc(sizeof(struct entry)); /* Insert before */
+ n3 = malloc(sizeof(struct *n3)); /* Insert before */
LIST_INSERT_BEFORE(n2, n3, entries);
i = 0; /* Forward traversal */
diff --git a/man3/qsort.3 b/man3/qsort.3
index e020da36b..cd415b80c 100644
--- a/man3/qsort.3
+++ b/man3/qsort.3
@@ -151,7 +151,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 (int j = 1; j < argc; j++)
puts(argv[j]);
diff --git a/man3/slist.3 b/man3/slist.3
index 88e10527b..22121046a 100644
--- a/man3/slist.3
+++ b/man3/slist.3
@@ -300,10 +300,10 @@ main(void)
SLIST_INIT(&head); /* Initialize the queue */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the head */
SLIST_INSERT_HEAD(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after */
+ n2 = malloc(sizeof(struct *n2)); /* Insert after */
SLIST_INSERT_AFTER(n1, n2, entries);
SLIST_REMOVE(&head, n2, entry, entries);/* Deletion */
@@ -314,7 +314,7 @@ main(void)
free(n3);
for (int i = 0; i < 5; i++) {
- n1 = malloc(sizeof(struct entry));
+ n1 = malloc(sizeof(struct *n1));
SLIST_INSERT_HEAD(&head, n1, entries);
n1\->data = i;
}
diff --git a/man3/stailq.3 b/man3/stailq.3
index 04738a4df..0a33dab0d 100644
--- a/man3/stailq.3
+++ b/man3/stailq.3
@@ -353,13 +353,13 @@ main(void)
STAILQ_INIT(&head); /* Initialize the queue */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the head */
STAILQ_INSERT_HEAD(&head, n1, entries);
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the tail */
STAILQ_INSERT_TAIL(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after */
+ n2 = malloc(sizeof(struct *n2)); /* Insert after */
STAILQ_INSERT_AFTER(&head, n1, n2, entries);
STAILQ_REMOVE(&head, n2, entry, entries); /* Deletion */
@@ -372,7 +372,7 @@ main(void)
n1 = STAILQ_FIRST(&head);
n1\->data = 0;
for (int i = 1; i < 5; i++) {
- n1 = malloc(sizeof(struct entry));
+ n1 = malloc(sizeof(struct *n1));
STAILQ_INSERT_HEAD(&head, n1, entries);
n1\->data = i;
}
diff --git a/man3/tailq.3 b/man3/tailq.3
index a1fb2fdfa..f479cca9b 100644
--- a/man3/tailq.3
+++ b/man3/tailq.3
@@ -378,16 +378,16 @@ main(void)
TAILQ_INIT(&head); /* Initialize the queue */
- n1 = malloc(sizeof(struct entry)); /* Insert at the head */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the head */
TAILQ_INSERT_HEAD(&head, n1, entries);
- n1 = malloc(sizeof(struct entry)); /* Insert at the tail */
+ n1 = malloc(sizeof(struct *n1)); /* Insert at the tail */
TAILQ_INSERT_TAIL(&head, n1, entries);
- n2 = malloc(sizeof(struct entry)); /* Insert after */
+ n2 = malloc(sizeof(struct *n2)); /* Insert after */
TAILQ_INSERT_AFTER(&head, n1, n2, entries);
- n3 = malloc(sizeof(struct entry)); /* Insert before */
+ n3 = malloc(sizeof(struct *n3)); /* Insert before */
TAILQ_INSERT_BEFORE(n2, n3, entries);
TAILQ_REMOVE(&head, n2, entries); /* Deletion */
diff --git a/man7/inotify.7 b/man7/inotify.7
index 547ceed5d..c16e0358e 100644
--- a/man7/inotify.7
+++ b/man7/inotify.7
@@ -1029,7 +1029,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);