Skip to content

Commit

Permalink
Fix stringstream-not-empty check for Visual Studio 2008
Browse files Browse the repository at this point in the history
- Check if the stringstream is not empty by using
  if(ss.tellp() > 0) instead of if(ss.tellp()).

Prior to this change the latter was used, but Visual Studio 2008 returns
-1 when the stringstream is empty instead of 0 like later versions.

Ref: https://stackoverflow.com/q/526270
  • Loading branch information
jay committed Sep 1, 2017
1 parent ae4fd5f commit 065ad7d
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions battstatus.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -278,7 +278,7 @@ string CapabilitiesStr(ULONG Capabilities)
stringstream ss;
#define EXTRACT_CAPABILITIES(flag) \
if((Capabilities & flag)) { \
if(ss.tellp()) \
if(ss.tellp() > 0) \
ss << " | "; \
ss << #flag; \
Capabilities &= ~flag; \
Expand All @@ -289,7 +289,7 @@ string CapabilitiesStr(ULONG Capabilities)
EXTRACT_CAPABILITIES(BATTERY_SET_DISCHARGE_SUPPORTED);
EXTRACT_CAPABILITIES(BATTERY_SYSTEM_BATTERY);
if(Capabilities) {
if(ss.tellp())
if(ss.tellp() > 0)
ss << " | ";
ss << UndocumentedValueStr(Capabilities);
}
Expand Down Expand Up @@ -714,7 +714,7 @@ string BatteryFlagStr(unsigned BatteryFlag)
stringstream ss;
#define EXTRACT_BATTERYFLAG(flag, name) \
if((BatteryFlag & flag)) { \
if(ss.tellp()) \
if(ss.tellp() > 0) \
ss << " | "; \
ss << name; \
BatteryFlag &= ~flag; \
Expand All @@ -726,7 +726,7 @@ string BatteryFlagStr(unsigned BatteryFlag)
EXTRACT_BATTERYFLAG(SPSF_BATTERYNOBATTERY, "No system battery");
EXTRACT_BATTERYFLAG(255, "Unknown status");
if(BatteryFlag) {
if(ss.tellp())
if(ss.tellp() > 0)
ss << " | ";
ss << UndocumentedValueStr(BatteryFlag);
}
Expand Down

0 comments on commit 065ad7d

Please sign in to comment.