]> pilppa.org Git - libplp.git/commitdiff
fix more errors from uninitalized variables master
authorMika Laitio <lamikr@pilppa.org>
Mon, 7 Sep 2015 07:22:26 +0000 (10:22 +0300)
committerMika Laitio <lamikr@pilppa.org>
Mon, 7 Sep 2015 07:22:26 +0000 (10:22 +0300)
Signed-off-by: Mika Laitio <lamikr@pilppa.org>
src/StoreCache.cc
src_test/test_config1.c

index fe5c5834be8e64f5b40d7216ba048dfd26a20034..a289f54bd242568160e2a3021e6a67901b8bd3c3 100644 (file)
@@ -156,8 +156,9 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) {
                                        res_data        = NULL;
                                        cnt             = 0;
                                        val_cnt         = 0;
-                                       dr              = NULL;
                                        while(cur_date->before(max_date)) {
+                                               store   = NULL;
+                                               dr      = NULL;
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        store   = new StoreCache(device_id, cur_date);
                                                        dr      = store->get_mean(PERIOD_MONTHLY);
@@ -192,7 +193,8 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) {
                                                        }
                                                        delete(dr);
                                                }
-                                               delete(store);
+                                               if (store != NULL)
+                                                       delete(store);
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        cur_date->next_month();
                                                }
@@ -218,7 +220,7 @@ DataRange *StoreCache::get_mean(EnumSummaryPeriod period_type_param) {
                        case PERIOD_MINUTELY:
                        case PERIOD_SECONDLY:
                                if (StoreDay::exist(device_id, date, false)) {
-                                       StoreDay        *store;
+                                       StoreDay        *store;
 
                                        store   = new StoreDay(device_id, date);
                                        ret_val = store->get_mean(period_type_param);
@@ -541,6 +543,8 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) {
                                        res_data        = NULL;
                                        cnt             = 0;
                                        while(cur_date->before(max_date)) {
+                                               store   = NULL;
+                                               dr      = NULL;
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        store   = new StoreCache(device_id, cur_date);
                                                        dr      = store->get_max(PERIOD_MONTHLY);
@@ -584,7 +588,8 @@ DataRange *StoreCache::get_max(EnumSummaryPeriod period_type_param) {
                                                        }
                                                        delete(dr);
                                                }
-                                               delete(store);
+                                               if (store != NULL)
+                                                       delete(store);
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        cur_date->next_month();
                                                }
@@ -667,6 +672,8 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) {
                                        res_data        = NULL;
                                        cnt             = 0;
                                        while(cur_date->before(max_date)) {
+                                               store   = NULL;
+                                               dr      = NULL;
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        store   = new StoreCache(device_id, cur_date);
                                                        dr      = store->get_min(PERIOD_MONTHLY);
@@ -710,7 +717,8 @@ DataRange *StoreCache::get_min(EnumSummaryPeriod period_type_param) {
                                                        }
                                                        delete(dr);
                                                }
-                                               delete(store);
+                                               if (store != NULL)
+                                                       delete(store);
                                                if (period_type_param == PERIOD_YEARLY) {
                                                        cur_date->next_month();
                                                }
index 8bddb50e2561b86e2597757508ee087d5e617f4f..e520dc3c240bee6da1e4f219643fdb32410eaae9 100644 (file)
 int test_config() {
        char work_dir[FILENAME_MAX];
        char *val;
+       char *ret;
 
-       getcwd(work_dir, sizeof(work_dir));
-       printf("working directory: %s\n", work_dir);
+       ret     = getcwd(work_dir, sizeof(work_dir));
+       if (ret != NULL) {
+               printf("working directory: %s\n", work_dir);
 
-       set_config_value_and_save(work_dir,
-                       CONF_FILENAME,
-                       SECTION_TYPE,
-                       SECTION_NAME,
-                       KEY_NAME,
-                       VALUE1);
-       val     = get_config_value_and_close(work_dir,
-                                       CONF_FILENAME,
-                                       SECTION_NAME,
-                                       KEY_NAME);
-       if ((val != NULL) &&
-           (strcmp(val, VALUE1) == 0)) {
-               printf("value 1 read ok: %s\n", val);
-               free(val);
-       }
-       else {
-               printf("failed to read value\n");
-               return 1;
-       }
-
-       val     = get_config_value_and_close(work_dir,
+               set_config_value_and_save(work_dir,
+                               CONF_FILENAME,
+                               SECTION_TYPE,
+                               SECTION_NAME,
+                               KEY_NAME,
+                               VALUE1);
+               val     = get_config_value_and_close(work_dir,
                                                CONF_FILENAME,
                                                SECTION_NAME,
-                                               KEY_NAME_INVALID_READ);
-       if ((val != NULL) &&
-           (strcmp(val, VALUE1) == 0)) {
-               printf("pl, should not be possible to read invalid key value.\n");
-               return 0;
-       }
-       else {
-               printf("error, value was supposed to be NULL, but is: %s\n", val);
+                                               KEY_NAME);
+               if ((val != NULL) &&
+                   (strcmp(val, VALUE1) == 0)) {
+                       printf("value 1 read ok: %s\n", val);
+                       free(val);
+               }
+               else {
+                       printf("failed to read value\n");
+                       return 1;
+               }
+
+               val     = get_config_value_and_close(work_dir,
+                                                       CONF_FILENAME,
+                                                       SECTION_NAME,
+                                                       KEY_NAME_INVALID_READ);
+               if ((val != NULL) &&
+                   (strcmp(val, VALUE1) == 0)) {
+                       printf("pl, should not be possible to read invalid key value.\n");
+                       return 0;
+               }
+               else {
+                       printf("error, value was supposed to be NULL, but is: %s\n", val);
+               }
+               set_config_value_and_save(work_dir,
+                               CONF_FILENAME,
+                               SECTION_TYPE,
+                               SECTION_NAME,
+                               KEY_NAME,
+                               VALUE2);
+               set_config_value_and_save(work_dir,
+                               CONF_FILENAME,
+                               SECTION_TYPE,
+                               SECTION_NAME,
+                               KEY_NAME2,
+                               VALUE3);
+               set_config_value_and_save(work_dir,
+                               CONF_FILENAME,
+                               SECTION_TYPE2,
+                               SECTION_NAME2,
+                               KEY_NAME3,
+                               VALUE4);
        }
-       set_config_value_and_save(work_dir,
-                       CONF_FILENAME,
-                       SECTION_TYPE,
-                       SECTION_NAME,
-                       KEY_NAME,
-                       VALUE2);
-       set_config_value_and_save(work_dir,
-                       CONF_FILENAME,
-                       SECTION_TYPE,
-                       SECTION_NAME,
-                       KEY_NAME2,
-                       VALUE3);
-       set_config_value_and_save(work_dir,
-                       CONF_FILENAME,
-                       SECTION_TYPE2,
-                       SECTION_NAME2,
-                       KEY_NAME3,
-                       VALUE4);
        return 0;
 }