From 7cf7fa23f491cc1a7d4350b696c38968de554e2a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?J=C3=A9r=C3=B4me=20Duval?= Date: Thu, 28 Nov 2013 18:18:54 +0100 Subject: [PATCH] PowerStatus: fix a possible division error. * also fix some types misuses. --- src/apps/powerstatus/ACPIDriverInterface.cpp | 8 +++----- src/apps/powerstatus/PowerStatusView.cpp | 15 +++++++-------- 2 files changed, 10 insertions(+), 13 deletions(-) diff --git a/src/apps/powerstatus/ACPIDriverInterface.cpp b/src/apps/powerstatus/ACPIDriverInterface.cpp index 9b8ef80382..5fe318793e 100644 --- a/src/apps/powerstatus/ACPIDriverInterface.cpp +++ b/src/apps/powerstatus/ACPIDriverInterface.cpp @@ -43,8 +43,8 @@ RateBuffer::AddRate(int32 rate) int32 RateBuffer::GetMeanRate() { - int mean = 0; - for (int i = 0; i < fCurrentSize; i++) { + int32 mean = 0; + for (int8 i = 0; i < fCurrentSize; i++) { mean += fRateBuffer[i]; } @@ -98,7 +98,7 @@ Battery::GetBatteryInfoCached(battery_info* info) info->capacity = fCachedAcpiInfo.capacity; info->full_capacity = fExtendedBatteryInfo.last_full_charge; fRateBuffer.AddRate(fCachedAcpiInfo.current_rate); - if (fCachedAcpiInfo.current_rate > 0) + if (fCachedAcpiInfo.current_rate > 0 && fRateBuffer.GetMeanRate() != 0) info->time_left = 3600 * fCachedAcpiInfo.capacity / fRateBuffer.GetMeanRate(); else @@ -254,5 +254,3 @@ ACPIDriverInterface::_FindDrivers(const char* dirpath) } return status; } - - diff --git a/src/apps/powerstatus/PowerStatusView.cpp b/src/apps/powerstatus/PowerStatusView.cpp index c7a6968243..b36a9d1568 100644 --- a/src/apps/powerstatus/PowerStatusView.cpp +++ b/src/apps/powerstatus/PowerStatusView.cpp @@ -5,7 +5,7 @@ * Authors: * Axel Dörfler, axeld@pinc-software.de * Clemens Zeidler, haiku@Clemens-Zeidler.de - * Alexander von Gluck, kallisti5@unixzen.com + * Alexander von Gluck, kallisti5@unixzen.com */ @@ -336,7 +336,7 @@ void PowerStatusView::Update(bool force) { int32 previousPercent = fPercent; - bool previousTimeLeft = fTimeLeft; + time_t previousTimeLeft = fTimeLeft; bool wasOnline = fOnline; _GetBatteryInfo(&fBatteryInfo, fBatteryID); @@ -350,7 +350,7 @@ PowerStatusView::Update(bool force) } else { fPercent = 0; fOnline = false; - fTimeLeft = false; + fTimeLeft = -1; } @@ -375,7 +375,7 @@ PowerStatusView::Update(bool force) if (fHasBattery) { size_t length = snprintf(text, sizeof(text), "%s%" B_PRId32 "%%%s", open, fPercent, close); - if (fTimeLeft) { + if (fTimeLeft >= 0) { length += snprintf(text + length, sizeof(text) - length, "\n%" B_PRId32 ":%02" B_PRId32, fTimeLeft / 3600, (fTimeLeft / 60) % 60); @@ -421,7 +421,7 @@ PowerStatusView::FromMessage(const BMessage* archive) fShowStatusIcon = value; if (archive->FindBool("show time", &value) == B_OK) fShowTime = value; - + //Incase we have a bad saving and none are showed.. if (!fShowLabel && !fShowStatusIcon) fShowLabel = true; @@ -548,7 +548,7 @@ PowerStatusReplicant::MessageReceived(BMessage *message) fShowLabel = !fShowLabel; else fShowLabel = true; - + Update(true); break; @@ -610,7 +610,7 @@ PowerStatusReplicant::MouseDown(BPoint point) menu->AddSeparatorItem(); menu->AddItem(new BMenuItem(B_TRANSLATE("About" B_UTF8_ELLIPSIS), new BMessage(B_ABOUT_REQUESTED))); - menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), + menu->AddItem(new BMenuItem(B_TRANSLATE("Quit"), new BMessage(B_QUIT_REQUESTED))); menu->SetTargetForItems(this); @@ -751,4 +751,3 @@ instantiate_deskbar_item(void) { return new PowerStatusReplicant(BRect(0, 0, 15, 15), B_FOLLOW_NONE, true); } -