Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/sys/dev/rasops Cast attr to uint32_t before right shift to a...
details: https://anonhg.NetBSD.org/src/rev/6da790ca0fde
branches: trunk
changeset: 462219:6da790ca0fde
user: rin <rin%NetBSD.org@localhost>
date: Sun Jul 28 12:06:10 2019 +0000
description:
Cast attr to uint32_t before right shift to avoid undefined behavior.
Also, misc style/cosmetic changes for clarity.
diffstat:
sys/dev/rasops/rasops.c | 14 ++--
sys/dev/rasops/rasops.h | 4 +-
sys/dev/rasops/rasops15.c | 107 ++++++++++++++++-----------------
sys/dev/rasops/rasops2.c | 12 +-
sys/dev/rasops/rasops24.c | 82 ++++++++++++-------------
sys/dev/rasops/rasops32.c | 27 ++++----
sys/dev/rasops/rasops4.c | 12 +-
sys/dev/rasops/rasops8.c | 101 +++++++++++++++----------------
sys/dev/rasops/rasops_bitops.h | 4 +-
sys/dev/rasops/rasops_putchar.h | 12 +-
sys/dev/rasops/rasops_putchar_width.h | 14 ++--
11 files changed, 189 insertions(+), 200 deletions(-)
diffs (truncated from 891 to 300 lines):
diff -r fd4c8ebf4e1f -r 6da790ca0fde sys/dev/rasops/rasops.c
--- a/sys/dev/rasops/rasops.c Sun Jul 28 10:30:44 2019 +0000
+++ b/sys/dev/rasops/rasops.c Sun Jul 28 12:06:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops.c,v 1.93 2019/07/28 10:24:08 martin Exp $ */
+/* $NetBSD: rasops.c,v 1.94 2019/07/28 12:06:10 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.93 2019/07/28 10:24:08 martin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops.c,v 1.94 2019/07/28 12:06:10 rin Exp $");
#include "opt_rasops.h"
#include "rasops_glue.h"
@@ -232,7 +232,7 @@
rasops_init(struct rasops_info *ri, int wantrows, int wantcols)
{
- memset (&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
+ memset(&ri->ri_optfont, 0, sizeof(ri->ri_optfont));
#ifdef _KERNEL
/* Select a font if the caller doesn't care */
if (ri->ri_font == NULL) {
@@ -952,7 +952,7 @@
return;
#endif
- clr = ri->ri_devcmap[(attr >> 16) & 0xf];
+ clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
/*
* XXX The wsdisplay_emulops interface seems a little deficient in
@@ -1138,7 +1138,7 @@
hrp = (uint32_t *)(ri->ri_hwbits + row*ri->ri_yscale +
col*ri->ri_xscale);
height = ri->ri_font->fontheight;
- clr = ri->ri_devcmap[(attr >> 16) & 0xf];
+ clr = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
/* Don't bother using the full loop for <= 32 pels */
if (num <= 32) {
@@ -1357,7 +1357,7 @@
/* XXX this assumes 16-bit color depth */
if ((attr & WSATTR_UNDERLINE) != 0) {
uint16_t c =
- (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
+ (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
while (height--) {
*(uint16_t *)rp = c;
@@ -1480,7 +1480,7 @@
/* XXX this assumes 16-bit color depth */
if ((attr & WSATTR_UNDERLINE) != 0) {
uint16_t c =
- (uint16_t)ri->ri_devcmap[((u_int)attr >> 24) & 0xf];
+ (uint16_t)ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
while (height--) {
*(uint16_t *)rp = c;
diff -r fd4c8ebf4e1f -r 6da790ca0fde sys/dev/rasops/rasops.h
--- a/sys/dev/rasops/rasops.h Sun Jul 28 10:30:44 2019 +0000
+++ b/sys/dev/rasops/rasops.h Sun Jul 28 12:06:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops.h,v 1.36 2019/07/25 03:02:44 rin Exp $ */
+/* $NetBSD: rasops.h,v 1.37 2019/07/28 12:06:10 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -139,7 +139,7 @@
#endif
};
-#define DELTA(p, d, cast) ((p) = (cast)((char *)(p) + (d)))
+#define DELTA(p, d, cast) ((p) = (cast)((uint8_t *)(p) + (d)))
#define CHAR_IN_FONT(c,font) \
((c) >= (font)->firstchar && \
diff -r fd4c8ebf4e1f -r 6da790ca0fde sys/dev/rasops/rasops15.c
--- a/sys/dev/rasops/rasops15.c Sun Jul 28 10:30:44 2019 +0000
+++ b/sys/dev/rasops/rasops15.c Sun Jul 28 12:06:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops15.c,v 1.29 2019/07/28 02:45:52 rin Exp $ */
+/* $NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.29 2019/07/28 02:45:52 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops15.c,v 1.30 2019/07/28 12:06:10 rin Exp $");
#include "opt_rasops.h"
@@ -42,34 +42,31 @@
#include <dev/wscons/wsconsio.h>
#include <dev/rasops/rasops.h>
-static void rasops15_putchar(void *, int, int, u_int, long attr);
-static void rasops15_putchar_aa(void *, int, int, u_int, long attr);
+static void rasops15_putchar(void *, int, int, u_int, long);
+static void rasops15_putchar_aa(void *, int, int, u_int, long);
#ifndef RASOPS_SMALL
-static void rasops15_putchar8(void *, int, int, u_int, long attr);
-static void rasops15_putchar12(void *, int, int, u_int, long attr);
-static void rasops15_putchar16(void *, int, int, u_int, long attr);
+static void rasops15_putchar8(void *, int, int, u_int, long);
+static void rasops15_putchar12(void *, int, int, u_int, long);
+static void rasops15_putchar16(void *, int, int, u_int, long);
static void rasops15_makestamp(struct rasops_info *, long);
#endif
#ifndef RASOPS_SMALL
/*
- * (2x2)x1 stamp for optimized character blitting
+ * 4x1 stamp for optimized character blitting
*/
static uint32_t stamp[32];
static long stamp_attr;
static int stamp_mutex; /* XXX see note in readme */
/*
- * XXX this confuses the hell out of gcc2 (not egcs) which always insists
- * that the shift count is negative.
- *
* offset = STAMP_SHIFT(fontbits, nibble #) & STAMP_MASK
* destination uint32_t[0] = STAMP_READ(offset)
* destination uint32_t[1] = STAMP_READ(offset + 4)
*/
-#define STAMP_SHIFT(fb,n) ((n*4-3) >= 0 ? (fb)>>(n*4-3):(fb)<<-(n*4-3))
-#define STAMP_MASK (15 << 3)
-#define STAMP_READ(o) (*(uint32_t *)((char *)stamp + (o)))
+#define STAMP_SHIFT(fb, n) ((n) ? (fb) >> 1: (fb) << 3)
+#define STAMP_MASK (0xf << 3)
+#define STAMP_READ(o) (*(uint32_t *)((uint8_t *)stamp + (o)))
#endif
/*
@@ -79,36 +76,35 @@
rasops15_init(struct rasops_info *ri)
{
+ if (ri->ri_rnum == 0) {
+ ri->ri_rnum = ri->ri_gnum = ri->ri_bnum = 5;
+ ri->ri_gnum += (ri->ri_depth == 16);
+
+ ri->ri_rpos = 10 + (ri->ri_depth == 16);
+ ri->ri_gpos = 5;
+ ri->ri_bpos = 0;
+ }
+
if (FONT_IS_ALPHA(ri->ri_font)) {
ri->ri_ops.putchar = rasops15_putchar_aa;
- } else {
- switch (ri->ri_font->fontwidth) {
-#ifndef RASOPS_SMALL
- case 8:
- ri->ri_ops.putchar = rasops15_putchar8;
- break;
-
- case 12:
- ri->ri_ops.putchar = rasops15_putchar12;
- break;
-
- case 16:
- ri->ri_ops.putchar = rasops15_putchar16;
- break;
-#endif /* !RASOPS_SMALL */
- default:
- ri->ri_ops.putchar = rasops15_putchar;
- break;
- }
+ return;
}
- if (ri->ri_rnum == 0) {
- ri->ri_rnum = 5;
- ri->ri_rpos = 10 + (ri->ri_depth == 16);
- ri->ri_gnum = 5 + (ri->ri_depth == 16);
- ri->ri_gpos = 5;
- ri->ri_bnum = 5;
- ri->ri_bpos = 0;
+ switch (ri->ri_font->fontwidth) {
+#ifndef RASOPS_SMALL
+ case 8:
+ ri->ri_ops.putchar = rasops15_putchar8;
+ break;
+ case 12:
+ ri->ri_ops.putchar = rasops15_putchar12;
+ break;
+ case 16:
+ ri->ri_ops.putchar = rasops15_putchar16;
+ break;
+#endif /* !RASOPS_SMALL */
+ default:
+ ri->ri_ops.putchar = rasops15_putchar;
+ break;
}
}
@@ -128,7 +124,6 @@
int x, y, r, g, b, aval;
int r1, g1, b1, r0, g0, b0, fgo, bgo;
-
#ifdef RASOPS_CLIPPING
/* Catches 'row < 0' case too */
if ((unsigned)row >= (unsigned)ri->ri_rows)
@@ -148,8 +143,8 @@
height = font->fontheight;
width = font->fontwidth;
- clr[0] = ri->ri_devcmap[(attr >> 16) & 0xf];
- clr[1] = ri->ri_devcmap[(attr >> 24) & 0xf];
+ clr[0] = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf];
+ clr[1] = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf];
if (uc == ' ') {
for (cnt = 0; cnt < width; cnt++)
@@ -162,8 +157,8 @@
} else {
fr = FONT_GLYPH(uc, font, ri);
- fgo = ((attr >> 24) & 0xf) * 3;
- bgo = ((attr >> 16) & 0xf) * 3;
+ fgo = (((uint32_t)attr >> 24) & 0xf) * 3;
+ bgo = (((uint32_t)attr >> 16) & 0xf) * 3;
r0 = rasops_cmap[bgo];
r1 = rasops_cmap[fgo];
@@ -209,7 +204,7 @@
#ifndef RASOPS_SMALL
/*
- * Recompute the (2x2)x1 blitting stamp.
+ * Recompute the 4x1 blitting stamp.
*/
static void
rasops15_makestamp(struct rasops_info *ri, long attr)
@@ -217,21 +212,21 @@
uint32_t fg, bg;
int i;
- fg = ri->ri_devcmap[((u_int)attr >> 24) & 0xf] & 0xffff;
- bg = ri->ri_devcmap[((u_int)attr >> 16) & 0xf] & 0xffff;
+ fg = ri->ri_devcmap[((uint32_t)attr >> 24) & 0xf] & 0xffff;
+ bg = ri->ri_devcmap[((uint32_t)attr >> 16) & 0xf] & 0xffff;
stamp_attr = attr;
for (i = 0; i < 32; i += 2) {
#if BYTE_ORDER == LITTLE_ENDIAN
- stamp[i] = (i & 16 ? fg : bg);
- stamp[i] |= ((i & 8 ? fg : bg) << 16);
- stamp[i + 1] = (i & 4 ? fg : bg);
- stamp[i + 1] |= ((i & 2 ? fg : bg) << 16);
+ stamp[i] = (i & 16 ? fg : bg);
+ stamp[i] |= (i & 8 ? fg : bg) << 16;
+ stamp[i + 1] = (i & 4 ? fg : bg);
+ stamp[i + 1] |= (i & 2 ? fg : bg) << 16;
#else
- stamp[i] = (i & 8 ? fg : bg);
- stamp[i] |= ((i & 16 ? fg : bg) << 16);
- stamp[i + 1] = (i & 2 ? fg : bg);
- stamp[i + 1] |= ((i & 4 ? fg : bg) << 16);
+ stamp[i] = (i & 8 ? fg : bg);
+ stamp[i] |= (i & 16 ? fg : bg) << 16;
+ stamp[i + 1] = (i & 2 ? fg : bg);
+ stamp[i + 1] |= (i & 4 ? fg : bg) << 16;
#endif
}
}
diff -r fd4c8ebf4e1f -r 6da790ca0fde sys/dev/rasops/rasops2.c
--- a/sys/dev/rasops/rasops2.c Sun Jul 28 10:30:44 2019 +0000
+++ b/sys/dev/rasops/rasops2.c Sun Jul 28 12:06:10 2019 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: rasops2.c,v 1.24 2019/07/28 02:51:38 rin Exp $ */
+/* $NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $ */
/*-
* Copyright (c) 1999 The NetBSD Foundation, Inc.
@@ -30,7 +30,7 @@
*/
#include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.24 2019/07/28 02:51:38 rin Exp $");
+__KERNEL_RCSID(0, "$NetBSD: rasops2.c,v 1.25 2019/07/28 12:06:10 rin Exp $");
#include "opt_rasops.h"
@@ -124,8 +124,8 @@
col = col & 31;
rs = ri->ri_stride;
- bg = ri->ri_devcmap[(attr >> 16) & 0xf];
- fg = ri->ri_devcmap[(attr >> 24) & 0xf];
Home |
Main Index |
Thread Index |
Old Index