apm code

Grover, Andrew andrew.grover at intel.com
Thu May 20 15:04:37 PDT 2004


> Just writing to the list to make sure am correct here. The 
> issue concerns /usr/src/usr.sbin/apm/apm.c. 
> 
> --- /usr/src/usr.sbin/apm/apm.c	Thu May 20 20:30:57 2004
> +++ /hd2/apm.c	Thu May 20 20:44:36 2004
> @@ -174,7 +174,7 @@
>  	printf("Remaining battery life: ");
>  	if (aip->ai_batt_life == 255)
>  		printf("unknown\n");
> -	else if (aip->ai_batt_life <= 100)
> +	else if (aip->ai_batt_life >= 0 && aip->ai_batt_life <= 100)
>  		printf("%d%%\n", aip->ai_batt_life);
>  	else
>  		printf("invalid value (0x%x)\n", aip->ai_batt_life);
> 
> The above patch will make apm print invalid value when 
> ai_batt_life does not equal 0-100. The reason for this was 
> the the current code was printing -1 as a so called valid 
> value(normally when acline is connected). I dont think 
> printing -1 is correct, and really it should be printing 
> invalid value since that is what it is. Do you guys agree 
> with me or does -1 symbolise something?

if (aip->ai_batt_life == 255)
	printf("unknown\n");

The above line should catch the -1 case. There's a uint/uchar sign
extension problem. Changing the 255 to -1 will probably fix things.

Regards -- Andy



More information about the freebsd-acpi mailing list