Module Name:    src
Committed By:   dsl
Date:           Sat Nov 14 13:18:41 UTC 2009

Modified Files:
        src/sys/kern: tty_subr.c

Log Message:
Christos was worried about clrbits() being called with a length of zero.
This can't happen, but rework so it doesn't matter.
Remove 'optimisation' for length 1, that doesn't happen often enough.


To generate a diff of this commit:
cvs rdiff -u -r1.38 -r1.39 src/sys/kern/tty_subr.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/kern/tty_subr.c
diff -u src/sys/kern/tty_subr.c:1.38 src/sys/kern/tty_subr.c:1.39
--- src/sys/kern/tty_subr.c:1.38	Fri Nov 13 19:15:24 2009
+++ src/sys/kern/tty_subr.c	Sat Nov 14 13:18:41 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: tty_subr.c,v 1.38 2009/11/13 19:15:24 dsl Exp $	*/
+/*	$NetBSD: tty_subr.c,v 1.39 2009/11/14 13:18:41 dsl Exp $	*/
 
 /*
  * Copyright (c) 1993, 1994 Theo de Raadt
@@ -29,7 +29,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.38 2009/11/13 19:15:24 dsl Exp $");
+__KERNEL_RCSID(0, "$NetBSD: tty_subr.c,v 1.39 2009/11/14 13:18:41 dsl Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -303,32 +303,28 @@
 static void
 clrbits(u_char *cp, unsigned int off, unsigned int len)
 {
-	unsigned int sby, sbi, eby, ebi;
-	unsigned int i;
-	u_char mask;
+	unsigned int sbi, ebi;
+	u_char *scp, *ecp;
+	unsigned int end;
+	unsigned char mask;
 
-	if (len==1) {
-		clrbit(cp, off);
-		return;
-	}
-
-	len--;
-	sby = off / NBBY;
+	scp = cp + off / NBBY;
 	sbi = off % NBBY;
-	eby = (off+len) / NBBY;
-	ebi = (off+len) % NBBY + 1;
-	if (sby == eby) {
-		mask = ((1 << (ebi - sbi)) - 1) << sbi;
-		cp[sby] &= ~mask;
+	end = off + len + NBBY - 1;
+	ecp = cp + end / NBBY - 1;
+	ebi = end % NBBY + 1;
+	if (scp >= ecp) {
+		mask = ((1 << len) - 1) << sbi;
+		*scp &= ~mask;
 	} else {
 		mask = (1 << sbi) - 1;
-		cp[sby++] &= mask;
+		*scp++ &= mask;
 
 		mask = (1 << ebi) - 1;
-		cp[eby] &= ~mask;
+		*ecp &= ~mask;
 
-		for (i = sby; i < eby; i++)
-			cp[i] = 0x00;
+		while (scp < ecp)
+			*scp++ = 0x00;
 	}
 }
 #endif

Reply via email to