Subject: port-macppc/30034: Logic error in determining battery type on macppc
To: None <port-macppc-maintainer@netbsd.org, gnats-admin@netbsd.org,>
From: Magnus Henoch <mange@freemail.hu>
List: netbsd-bugs
Date: 04/22/2005 18:36:00
>Number: 30034
>Category: port-macppc
>Synopsis: Logic error in determining battery type on macppc
>Confidential: no
>Severity: non-critical
>Priority: medium
>Responsible: port-macppc-maintainer
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Fri Apr 22 18:36:00 +0000 2005
>Originator: Magnus Henoch
>Release: NetBSD 3.99.3
>Organization:
>Environment:
System: NetBSD zemdatav 3.99.3 NetBSD 3.99.3 (IBOOKFAN) #11: Fri Apr 22 19:38:27 CEST 2005 magnus@zemdatav:/usr/src/sys/arch/macppc/compile/IBOOKFAN macppc
Architecture: powerpc
Machine: macppc
>Description:
On my iBook G4 of 1 GHz, the battery type is incorrectly
detected, which means that data about battery life is bogus.
>How-To-Repeat:
Run "apm" on affected hardware. Output:
Battery charge state: CRITICAL
Battery remaining: 0 percent (0 minutes)
A/C adapter state: connected
Power management enabled
regardless of actual battery state.
>Fix:
Apply the following patch to
src/sys/arch/macppc/dev/pm_direct.c. The direct cause of the
problem is that the compatibility list on which strinlist is
used has a zero-length string at the end, which means that the
first 0 bytes of the two strings are compared.
--- pm_direct.c 02 Feb 2005 04:03:49 +0100 1.25
+++ pm_direct.c 22 Apr 2005 19:44:59 +0200
@@ -251,16 +251,21 @@
{
}
+/*
+ * Search for targ in list. list is an area of listlen bytes
+ * containing null-terminated strings.
+ */
static int
strinlist(char *targ, char *list, int listlen)
{
char *str;
int sl;
+ int targlen = strlen(targ);
str = list;
while (listlen > 0) {
sl = strlen(str);
- if (strncmp(targ, str, sl) == 0)
+ if (sl == targlen && strncmp(targ, str, sl) == 0)
return 1;
str += sl+1;
listlen -= sl+1;
>Unformatted: