Skip to content

Commit

Permalink
Fix Coverity issues in Weather.cpp
Browse files Browse the repository at this point in the history
This changeset fixes possible uninitialized reads and NULL pointer
dereferences in Weather.cpp
  • Loading branch information
Kyle Hill committed Sep 1, 2012
1 parent 19f481c commit 8d305fe
Showing 1 changed file with 59 additions and 51 deletions.
110 changes: 59 additions & 51 deletions xbmc/utils/Weather.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,7 @@ bool CWeatherJob::m_imagesOkay = false;
CWeatherJob::CWeatherJob(int location)
{
m_location = location;
m_info.Reset();
}

bool CWeatherJob::DoWork()
Expand Down Expand Up @@ -330,55 +331,58 @@ void CWeatherJob::SetFromProperties()
if (!m_localizedTokens.size())
LoadLocalizedToken();

CGUIWindow* window = g_windowManager.GetWindow(WINDOW_WEATHER);
CDateTime time=CDateTime::GetCurrentDateTime();
m_info.lastUpdateTime = time.GetAsLocalizedDateTime(false, false);
m_info.currentConditions = window->GetProperty("Current.Condition").asString();
m_info.currentIcon = ConstructPath(window->GetProperty("Current.OutlookIcon").asString());
LocalizeOverview(m_info.currentConditions);
FormatTemperature(m_info.currentTemperature,
strtol(window->GetProperty("Current.Temperature").asString().c_str(),0,10));
FormatTemperature(m_info.currentFeelsLike,
strtol(window->GetProperty("Current.FeelsLike").asString().c_str(),0,10));
m_info.currentUVIndex = window->GetProperty("Current.UVIndex").asString();
LocalizeOverview(m_info.currentUVIndex);
int speed = ConvertSpeed(strtol(window->GetProperty("Current.Wind").asString().c_str(),0,10));
CStdString direction = window->GetProperty("Current.WindDirection").asString();
if (direction == "CALM")
m_info.currentWind = g_localizeStrings.Get(1410);
else
{
LocalizeOverviewToken(direction);
m_info.currentWind.Format(g_localizeStrings.Get(434).c_str(),
direction, speed, g_langInfo.GetSpeedUnitString().c_str());
}
CStdString windspeed;
windspeed.Format("%i %s",speed,g_langInfo.GetSpeedUnitString().c_str());
window->SetProperty("Current.WindSpeed",windspeed);
FormatTemperature(m_info.currentDewPoint,
strtol(window->GetProperty("Current.DewPoint").asString().c_str(),0,10));
if (window->GetProperty("Current.Humidity").asString().empty())
m_info.currentHumidity.clear();
else
m_info.currentHumidity.Format("%s%%",window->GetProperty("Current.Humidity").asString().c_str());
m_info.location = window->GetProperty("Current.Location").asString();
for (int i=0;i<NUM_DAYS;++i)
CGUIWindow* window = g_windowManager.GetWindow(WINDOW_WEATHER);
if (window)
{
CStdString strDay;
strDay.Format("Day%i.Title",i);
m_info.forecast[i].m_day = window->GetProperty(strDay).asString();
LocalizeOverviewToken(m_info.forecast[i].m_day);
strDay.Format("Day%i.HighTemp",i);
FormatTemperature(m_info.forecast[i].m_high,
strtol(window->GetProperty(strDay).asString().c_str(),0,10));
strDay.Format("Day%i.LowTemp",i);
FormatTemperature(m_info.forecast[i].m_low,
strtol(window->GetProperty(strDay).asString().c_str(),0,10));
strDay.Format("Day%i.OutlookIcon",i);
m_info.forecast[i].m_icon = ConstructPath(window->GetProperty(strDay).asString());
strDay.Format("Day%i.Outlook",i);
m_info.forecast[i].m_overview = window->GetProperty(strDay).asString();
LocalizeOverview(m_info.forecast[i].m_overview);
CDateTime time = CDateTime::GetCurrentDateTime();
m_info.lastUpdateTime = time.GetAsLocalizedDateTime(false, false);
m_info.currentConditions = window->GetProperty("Current.Condition").asString();
m_info.currentIcon = ConstructPath(window->GetProperty("Current.OutlookIcon").asString());
LocalizeOverview(m_info.currentConditions);
FormatTemperature(m_info.currentTemperature,
strtol(window->GetProperty("Current.Temperature").asString().c_str(),0,10));
FormatTemperature(m_info.currentFeelsLike,
strtol(window->GetProperty("Current.FeelsLike").asString().c_str(),0,10));
m_info.currentUVIndex = window->GetProperty("Current.UVIndex").asString();
LocalizeOverview(m_info.currentUVIndex);
int speed = ConvertSpeed(strtol(window->GetProperty("Current.Wind").asString().c_str(),0,10));
CStdString direction = window->GetProperty("Current.WindDirection").asString();
if (direction == "CALM")
m_info.currentWind = g_localizeStrings.Get(1410);
else
{
LocalizeOverviewToken(direction);
m_info.currentWind.Format(g_localizeStrings.Get(434).c_str(),
direction, speed, g_langInfo.GetSpeedUnitString().c_str());
}
CStdString windspeed;
windspeed.Format("%i %s",speed,g_langInfo.GetSpeedUnitString().c_str());
window->SetProperty("Current.WindSpeed",windspeed);
FormatTemperature(m_info.currentDewPoint,
strtol(window->GetProperty("Current.DewPoint").asString().c_str(),0,10));
if (window->GetProperty("Current.Humidity").asString().empty())
m_info.currentHumidity.clear();
else
m_info.currentHumidity.Format("%s%%",window->GetProperty("Current.Humidity").asString().c_str());
m_info.location = window->GetProperty("Current.Location").asString();
for (int i=0;i<NUM_DAYS;++i)
{
CStdString strDay;
strDay.Format("Day%i.Title",i);
m_info.forecast[i].m_day = window->GetProperty(strDay).asString();
LocalizeOverviewToken(m_info.forecast[i].m_day);
strDay.Format("Day%i.HighTemp",i);
FormatTemperature(m_info.forecast[i].m_high,
strtol(window->GetProperty(strDay).asString().c_str(),0,10));
strDay.Format("Day%i.LowTemp",i);
FormatTemperature(m_info.forecast[i].m_low,
strtol(window->GetProperty(strDay).asString().c_str(),0,10));
strDay.Format("Day%i.OutlookIcon",i);
m_info.forecast[i].m_icon = ConstructPath(window->GetProperty(strDay).asString());
strDay.Format("Day%i.Outlook",i);
m_info.forecast[i].m_overview = window->GetProperty(strDay).asString();
LocalizeOverview(m_info.forecast[i].m_overview);
}
}
}

Expand Down Expand Up @@ -421,9 +425,13 @@ CStdString CWeather::TranslateInfo(int info) const
CStdString CWeather::GetLocation(int iLocation)
{
CGUIWindow* window = g_windowManager.GetWindow(WINDOW_WEATHER);
CStdString setting;
setting.Format("Location%i", iLocation);
return window->GetProperty(setting).asString();
if (window)
{
CStdString setting;
setting.Format("Location%i", iLocation);
return window->GetProperty(setting).asString();
}
return "";
}

void CWeather::Reset()
Expand Down

0 comments on commit 8d305fe

Please sign in to comment.