Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 7 May 2014 13:53:39 +0000 (UTC)
From:      Aleksandr Rybalko <ray@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r265546 - head/sys/dev/vt
Message-ID:  <201405071353.s47DrdBI094063@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: ray
Date: Wed May  7 13:53:38 2014
New Revision: 265546
URL: http://svnweb.freebsd.org/changeset/base/265546

Log:
  Fix possible divide by zero.
  
  Spotted by:	many
  
  Sponsored by:	The FreeBSD Foundation

Modified:
  head/sys/dev/vt/vt_core.c

Modified: head/sys/dev/vt/vt_core.c
==============================================================================
--- head/sys/dev/vt/vt_core.c	Wed May  7 12:48:18 2014	(r265545)
+++ head/sys/dev/vt/vt_core.c	Wed May  7 13:53:38 2014	(r265546)
@@ -678,6 +678,22 @@ vtterm_bell(struct terminal *tm)
 }
 
 static void
+vtterm_beep(struct terminal *tm, u_int param)
+{
+	u_int freq, period;
+
+	if ((param == 0) || ((param & 0xffff) == 0)) {
+		vtterm_bell(tm);
+		return;
+	}
+
+	period = ((param >> 16) & 0xffff) * hz / 1000;
+	freq = 1193182 / (param & 0xffff);
+
+	sysbeep(freq, period);
+}
+
+static void
 vtterm_cursor(struct terminal *tm, const term_pos_t *p)
 {
 	struct vt_window *vw = tm->tm_softc;
@@ -1732,17 +1748,9 @@ skip_thunk:
 		td->td_frame->tf_rflags &= ~PSL_IOPL;
 #endif
 		return (0);
-	case KDMKTONE: {      	/* sound the bell */
-		int freq, period;
-
-		freq = 1193182 / ((*(int*)data) & 0xffff);
-		period = (((*(int*)data)>>16) & 0xffff) * hz / 1000;
-		if(*(int*)data)
-			sysbeep(freq, period);
-		else
-			vtterm_bell(tm);
+	case KDMKTONE:      	/* sound the bell */
+		vtterm_beep(tm, *(u_int *)data);
 		return (0);
-	}
 	case KIOCSOUND:     	/* make tone (*data) hz */
 		/* TODO */
 		return (0);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405071353.s47DrdBI094063>