From 7fc6c09ef4d722c2106b0d8ff6854c46fe7e17aa Mon Sep 17 00:00:00 2001 From: gallatin Date: Thu, 26 Oct 2000 17:35:46 +0000 Subject: fix unaligned access errors by copying untyped data to properly aligned locals PR: alpha/13912 obtained from: NetBSD tested by: Marcin Gryszkalis --- usr.sbin/sa/main.c | 92 ++++++++++++++++++++++++++--------------------------- usr.sbin/sa/usrdb.c | 4 +-- 2 files changed, 48 insertions(+), 48 deletions(-) (limited to 'usr.sbin') diff --git a/usr.sbin/sa/main.c b/usr.sbin/sa/main.c index de84396..33bc1c1 100644 --- a/usr.sbin/sa/main.c +++ b/usr.sbin/sa/main.c @@ -408,19 +408,19 @@ static int cmp_usrsys(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; u_quad_t t1, t2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; + t1 = c1.ci_utime + c1.ci_stime; + t2 = c2.ci_utime + c2.ci_stime; if (t1 < t2) return -1; else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -430,22 +430,22 @@ static int cmp_avgusrsys(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; double t1, t2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - t1 = c1->ci_utime + c1->ci_stime; - t1 /= (double) (c1->ci_calls ? c1->ci_calls : 1); + t1 = c1.ci_utime + c1.ci_stime; + t1 /= (double) (c1.ci_calls ? c1.ci_calls : 1); - t2 = c2->ci_utime + c2->ci_stime; - t2 /= (double) (c2->ci_calls ? c2->ci_calls : 1); + t2 = c2.ci_utime + c2.ci_stime; + t2 /= (double) (c2.ci_calls ? c2.ci_calls : 1); if (t1 < t2) return -1; else if (t1 == t2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -455,15 +455,15 @@ static int cmp_dkio(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - if (c1->ci_io < c2->ci_io) + if (c1.ci_io < c2.ci_io) return -1; - else if (c1->ci_io == c2->ci_io) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + else if (c1.ci_io == c2.ci_io) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -473,19 +473,19 @@ static int cmp_avgdkio(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; double n1, n2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - n1 = (double) c1->ci_io / (double) (c1->ci_calls ? c1->ci_calls : 1); - n2 = (double) c2->ci_io / (double) (c2->ci_calls ? c2->ci_calls : 1); + n1 = (double) c1.ci_io / (double) (c1.ci_calls ? c1.ci_calls : 1); + n2 = (double) c2.ci_io / (double) (c2.ci_calls ? c2.ci_calls : 1); if (n1 < n2) return -1; else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -495,15 +495,15 @@ static int cmp_cpumem(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - if (c1->ci_mem < c2->ci_mem) + if (c1.ci_mem < c2.ci_mem) return -1; - else if (c1->ci_mem == c2->ci_mem) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + else if (c1.ci_mem == c2.ci_mem) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -513,23 +513,23 @@ static int cmp_avgcpumem(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; u_quad_t t1, t2; double n1, n2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - t1 = c1->ci_utime + c1->ci_stime; - t2 = c2->ci_utime + c2->ci_stime; + t1 = c1.ci_utime + c1.ci_stime; + t2 = c2.ci_utime + c2.ci_stime; - n1 = (double) c1->ci_mem / (double) (t1 ? t1 : 1); - n2 = (double) c2->ci_mem / (double) (t2 ? t2 : 1); + n1 = (double) c1.ci_mem / (double) (t1 ? t1 : 1); + n2 = (double) c2.ci_mem / (double) (t2 ? t2 : 1); if (n1 < n2) return -1; else if (n1 == n2) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } @@ -539,15 +539,15 @@ static int cmp_calls(d1, d2) const DBT *d1, *d2; { - struct cmdinfo *c1, *c2; + struct cmdinfo c1, c2; - c1 = (struct cmdinfo *) d1->data; - c2 = (struct cmdinfo *) d2->data; + memcpy(&c1, d1->data, sizeof(c1)); + memcpy(&c2, d2->data, sizeof(c2)); - if (c1->ci_calls < c2->ci_calls) + if (c1.ci_calls < c2.ci_calls) return -1; - else if (c1->ci_calls == c2->ci_calls) - return (cmp_comm(c1->ci_comm, c2->ci_comm)); + else if (c1.ci_calls == c2.ci_calls) + return (cmp_comm(c1.ci_comm, c2.ci_comm)); else return 1; } diff --git a/usr.sbin/sa/usrdb.c b/usr.sbin/sa/usrdb.c index 0c7cb27..9ca5f74 100644 --- a/usr.sbin/sa/usrdb.c +++ b/usr.sbin/sa/usrdb.c @@ -226,7 +226,7 @@ void usracct_print() { DBT key, data; - struct userinfo *ui; + struct userinfo uistore, *ui = &uistore; double t; int rv; @@ -235,7 +235,7 @@ usracct_print() warn("retrieving user accounting stats"); while (rv == 0) { - ui = (struct userinfo *) data.data; + memcpy(ui, data.data, sizeof(struct userinfo)); printf("%-*s %9qu ", MAXLOGNAME - 1, user_from_uid(ui->ui_uid, 0), ui->ui_calls); -- cgit v1.1