From db9ced4236847cfca52b232935838ee80dcfd047 Mon Sep 17 00:00:00 2001 From: Mika Laitio Date: Thu, 10 Mar 2011 16:51:49 +0200 Subject: [PATCH] Nullpointer bug fix if device's datastore was empty while reading data. Signed-off-by: Mika Laitio --- src/DataReader.cc | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/DataReader.cc b/src/DataReader.cc index 9ba2872..72a44bd 100644 --- a/src/DataReader.cc +++ b/src/DataReader.cc @@ -74,7 +74,9 @@ Data *DataReader::get_latest_data() { ret_val = NULL; y_list = FileUtil::get_subdirectories(device_dir); - ret_val = find_latest_data(y_list); + if (y_list.size() > 0) { + ret_val = find_latest_data(y_list); + } return ret_val; } @@ -297,12 +299,17 @@ DataRange *DataReader::get_daily_summary() { * Get Daily summary specified by the calc_type from the latest date. */ DataRange *DataReader::get_daily_summary(EnumSummaryCalculationType calc_type_param) { - Data *data; - Date date; + Data *data; + Date date; + DataRange *ret_val; + ret_val = NULL; data = get_latest_data(); - date = data->get_date(); - return get_daily_summary(&date, calc_type_param); + if (data != NULL) { + date = data->get_date(); + ret_val = get_daily_summary(&date, calc_type_param); + } + return ret_val; } DataRange *DataReader::get_daily_summary(Date *date, -- 2.41.1