Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Jul 1999 17:40:28 -0700 (PDT)
From:      Michael Constant <mconst@csua.berkeley.edu>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/12613: [patch] apm reports wrong resume time
Message-ID:  <199907130040.RAA01440@not.there.com>

next in thread | raw e-mail | index | archive | help

>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




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