From: millert Date: Tue, 22 Feb 2022 17:42:52 +0000 (+0000) Subject: Use sizeof() instead of KI_MAXCOMLEN and KI_WMESGLEN in structs. X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=e9b1e889bf9adde1a0ad10d8087a775b132d0d26;p=openbsd Use sizeof() instead of KI_MAXCOMLEN and KI_WMESGLEN in structs. This way we keep the size of the strings in the private struct in sync with what the kernel gives us. OK deraadt@ --- diff --git a/bin/ps/keyword.c b/bin/ps/keyword.c index 0075be9da0f..f27a12b7054 100644 --- a/bin/ps/keyword.c +++ b/bin/ps/keyword.c @@ -1,4 +1,4 @@ -/* $OpenBSD: keyword.c,v 1.50 2022/02/22 17:30:07 deraadt Exp $ */ +/* $OpenBSD: keyword.c,v 1.51 2022/02/22 17:42:52 millert Exp $ */ /* $NetBSD: keyword.c,v 1.12.6.1 1996/05/30 21:25:13 cgd Exp $ */ /*- @@ -33,7 +33,6 @@ #include #include #include -#include #include #include @@ -82,6 +81,8 @@ int utime(), stime(), ixrss(), idrss(), isrss(); #define USERLEN 8 #define CWDLEN 40 +#define UCOMMLEN (sizeof(((struct kinfo_proc *)NULL)->p_comm) - 1) +#define WCHANLEN (sizeof(((struct kinfo_proc *)NULL)->p_wmesg) - 1) /* Bit types must match their respective entries in struct kinfo_proc */ /* Entries must be sorted in lexical ascending order! */ @@ -180,14 +181,14 @@ VAR var[] = { {"tsiz", "TSIZ", NULL, 0, tsize, 4}, {"tt", "TT", NULL, LJUST, tname, 3}, {"tty", "TTY", NULL, LJUST, longtname, 8}, - {"ucomm", "UCOMM", NULL, LJUST, ucomm, KI_MAXCOMLEN}, + {"ucomm", "UCOMM", NULL, LJUST, ucomm, UCOMMLEN}, UID("uid", "UID", pvar, POFF(p_uid)), {"upr", "UPR", NULL, 0, pvar, 3, 0, POFF(p_usrpri), UINT8, "d"}, {"user", "USER", NULL, LJUST, euname, USERLEN}, {"usrpri", "", "upr"}, {"vsize", "", "vsz"}, {"vsz", "VSZ", NULL, 0, vsize, 5}, - {"wchan", "WCHAN", NULL, LJUST, wchan, KI_WMESGLEN - 1}, + {"wchan", "WCHAN", NULL, LJUST, wchan, WCHANLEN}, {"xstat", "XSTAT", NULL, 0, pvar, 4, 0, POFF(p_xstat), UINT16, "x"}, {""}, }; diff --git a/usr.sbin/sa/extern.h b/usr.sbin/sa/extern.h index 4ab2142daa9..0a89300ceba 100644 --- a/usr.sbin/sa/extern.h +++ b/usr.sbin/sa/extern.h @@ -1,4 +1,4 @@ -/* $OpenBSD: extern.h,v 1.7 2022/02/22 17:22:29 deraadt Exp $ */ +/* $OpenBSD: extern.h,v 1.8 2022/02/22 17:42:52 millert Exp $ */ /* * Copyright (c) 1994 Christopher G. Demetriou * All rights reserved. @@ -30,13 +30,14 @@ * */ -#include #include +#define CI_COMMLEN (sizeof(((struct acct *)NULL)->ac_comm)) + /* structures */ struct cmdinfo { - char ci_comm[KI_MAXCOMLEN+1]; /* command name (+ '*') */ + char ci_comm[CI_COMMLEN+1]; /* command name (+ '*') */ uid_t ci_uid; /* user id */ pid_t ci_pid; /* pid */ uint64_t ci_calls; /* number of calls */