From owner-freebsd-bugs Mon Jul 12 17:50: 4 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id D1431152DB for ; Mon, 12 Jul 1999 17:50:00 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id RAA89997; Mon, 12 Jul 1999 17:50:01 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: from not.there.com (mg131-151.ricochet.net [204.179.131.151]) by hub.freebsd.org (Postfix) with ESMTP id BEC1615256 for ; Mon, 12 Jul 1999 17:46:27 -0700 (PDT) (envelope-from mconst@not.there.com) Received: (from mconst@localhost) by not.there.com (8.9.3/8.9.3) id RAA01440; Mon, 12 Jul 1999 17:40:28 -0700 (PDT) (envelope-from mconst) Message-Id: <199907130040.RAA01440@not.there.com> Date: Mon, 12 Jul 1999 17:40:28 -0700 (PDT) From: Michael Constant Reply-To: mconst@csua.berkeley.edu To: FreeBSD-gnats-submit@freebsd.org X-Send-Pr-Version: 3.2 Subject: bin/12613: [patch] apm reports wrong resume time Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org >Number: 12613 >Category: bin >Synopsis: [patch] apm reports wrong resume time >Confidential: no >Severity: non-critical >Priority: low >Responsible: freebsd-bugs >State: open >Quarter: >Keywords: >Date-Required: >Class: sw-bug >Submitter-Id: current-users >Arrival-Date: Mon Jul 12 17:50:00 PDT 1999 >Closed-Date: >Last-Modified: >Originator: Michael Constant >Release: FreeBSD 4.0-CURRENT i386 >Organization: >Environment: Thinkpad 570 running 4.0-CURRENT, last updated July 11, 1999. >Description: (This is a different apm problem than the one I sent out a patch for a few minutes ago.) After using "apm -r" to set a resume timer, you can view the timer by running apm. However, the time apm reports is often wrong -- a bug in apm's bcd2int function causes incorrect output when any time or date fields have trailing zeros, and an incompletely initialized struct tm sometimes causes the hour to be off by one. >How-To-Repeat: This is most easily noticed as a year 2000 problem, since all dates in 2000 will trigger the bug: $ apm -r20000000 $ apm APM version: 1.2 APM Managment: Enabled AC Line status: on-line Battery status: high Remaining battery life: 100% Remaining battery time: unknown Number of batteries: 2 Resume timer: Wed Dec 31 15:59:59 1969 <==== that's not right! Resume on ring indicator: disabled APM Capacities: global standby state global suspend state resume timer from suspend >Fix: The following patch fixes both problems, and also makes the bcd2int routine look much more like the (correct) int2bcd routine. --- /usr/src/usr.sbin/apm/apm.c.orig Fri Sep 4 09:08:54 1998 +++ /usr/src/usr.sbin/apm/apm.c Mon Jul 12 17:20:56 1999 @@ -66,13 +66,15 @@ bcd2int(int bcd) { int retval = 0; + int place = 1; if (bcd > 0x9999) return -1; while (bcd) { - retval = retval * 10 + ((bcd & 0xf000) >> 12); - bcd = (bcd & 0xfff) << 4; + retval += (bcd & 0xf) * place; + bcd >>= 4; + place *= 10; } return retval; } @@ -194,6 +198,7 @@ tm.tm_mday = bcd2int(xl(args.esi)); tm.tm_mon = bcd2int(xh(args.esi)) - 1; tm.tm_year = bcd2int(args.edi) - 1900; + tm.tm_isdst = -1; if (cmos_wall) t = mktime(&tm); else >Release-Note: >Audit-Trail: >Unformatted: To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message