Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sbin/newfs newfs(8): Ensure A divides S before aligned_alloc...
details: https://anonhg.NetBSD.org/src/rev/18e7821bbdb5
branches: trunk
changeset: 377267:18e7821bbdb5
user: riastradh <riastradh%NetBSD.org@localhost>
date: Tue Jul 04 20:40:34 2023 +0000
description:
newfs(8): Ensure A divides S before aligned_alloc(A, S).
Required by C11 Sec. 7.22.3.1 The aligned_alloc function, para. 2,
p. 348:
The value of alignment shall be a valid alignment supported by the
implementation and the value of size shall be an integral multiple
of alignment.
XXX pullup-10
diffstat:
sbin/newfs/mkfs.c | 6 ++++--
sbin/newfs/newfs.c | 8 +++++---
2 files changed, 9 insertions(+), 5 deletions(-)
diffs (59 lines):
diff -r 05b3b074ab1c -r 18e7821bbdb5 sbin/newfs/mkfs.c
--- a/sbin/newfs/mkfs.c Tue Jul 04 20:40:22 2023 +0000
+++ b/sbin/newfs/mkfs.c Tue Jul 04 20:40:34 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $ */
+/* $NetBSD: mkfs.c,v 1.134 2023/07/04 20:40:34 riastradh Exp $ */
/*
* Copyright (c) 1980, 1989, 1993
@@ -73,7 +73,7 @@
#if 0
static char sccsid[] = "@(#)mkfs.c 8.11 (Berkeley) 5/3/95";
#else
-__RCSID("$NetBSD: mkfs.c,v 1.133 2023/01/07 19:41:29 chs Exp $");
+__RCSID("$NetBSD: mkfs.c,v 1.134 2023/07/04 20:40:34 riastradh Exp $");
#endif
#endif /* not lint */
@@ -201,9 +201,11 @@ mkfs(const char *fsys, int fi, int fo,
exit(12);
}
#endif
+ __CTASSERT((sizeof(*fsun) % DEV_BSIZE) == 0);
if ((fsun = aligned_alloc(DEV_BSIZE, sizeof(*fsun))) == NULL)
exit(12);
memset(fsun, 0, sizeof(*fsun));
+ __CTASSERT((sizeof(*cgun) % DEV_BSIZE) == 0);
if ((cgun = aligned_alloc(DEV_BSIZE, sizeof(*cgun))) == NULL)
exit(12);
memset(cgun, 0, sizeof(*cgun));
diff -r 05b3b074ab1c -r 18e7821bbdb5 sbin/newfs/newfs.c
--- a/sbin/newfs/newfs.c Tue Jul 04 20:40:22 2023 +0000
+++ b/sbin/newfs/newfs.c Tue Jul 04 20:40:34 2023 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: newfs.c,v 1.118 2022/11/17 06:40:39 chs Exp $ */
+/* $NetBSD: newfs.c,v 1.119 2023/07/04 20:40:34 riastradh Exp $ */
/*
* Copyright (c) 1983, 1989, 1993, 1994
@@ -78,7 +78,7 @@
#if 0
static char sccsid[] = "@(#)newfs.c 8.13 (Berkeley) 5/1/95";
#else
-__RCSID("$NetBSD: newfs.c,v 1.118 2022/11/17 06:40:39 chs Exp $");
+__RCSID("$NetBSD: newfs.c,v 1.119 2023/07/04 20:40:34 riastradh Exp $");
#endif
#endif /* not lint */
@@ -624,7 +624,9 @@ main(int argc, char *argv[])
} else
bufsize = sfs.f_iosize;
- if ((buf = aligned_alloc(DEV_BSIZE, bufsize)) == NULL)
+ __CTASSERT(powerof2(DEV_BSIZE));
+ if ((buf = aligned_alloc(DEV_BSIZE,
+ roundup2(bufsize, DEV_BSIZE))) == NULL)
err(1, "can't malloc buffer of %d",
bufsize);
memset(buf, 0, bufsize);
Home |
Main Index |
Thread Index |
Old Index