fixed coredump when there are no sensors
[psensor.git] / src / lib / psensor.c
index c5e412b..f8c0a83 100644 (file)
@@ -45,8 +45,13 @@ struct psensor *psensor_create(char *id,
        psensor->sess_lowest = UNKNOWN_DBL_VALUE;
        psensor->sess_highest = UNKNOWN_DBL_VALUE;
 
-       psensor->min = UNKNOWN_DBL_VALUE;
-       psensor->max = UNKNOWN_DBL_VALUE;
+       if (type & SENSOR_TYPE_PERCENT) {
+               psensor->min = 0;
+               psensor->max = 100;
+       } else {
+               psensor->min = UNKNOWN_DBL_VALUE;
+               psensor->max = UNKNOWN_DBL_VALUE;
+       }
 
        psensor->type = type;
 
@@ -277,8 +282,8 @@ struct measure *psensor_get_current_measure(struct psensor *sensor)
 }
 
 /*
-  Returns the minimal value of a given 'type' (SENSOR_TYPE_TEMP or
-  SENSOR_TYPE_FAN)
* Returns the minimal value of a given 'type' (SENSOR_TYPE_TEMP or
* SENSOR_TYPE_FAN)
  */
 static double get_min_value(struct psensor **sensors, int type)
 {
@@ -309,8 +314,8 @@ static double get_min_value(struct psensor **sensors, int type)
 }
 
 /*
-  Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or
-  SENSOR_TYPE_FAN)
* Returns the maximal value of a given 'type' (SENSOR_TYPE_TEMP or
* SENSOR_TYPE_FAN)
  */
 double get_max_value(struct psensor **sensors, int type)
 {
@@ -427,7 +432,10 @@ const char *psensor_type_to_unit_str(unsigned int type, int use_celsius)
 
 void psensor_log_measures(struct psensor **sensors)
 {
-       if (log_level == LOG_DEBUG)
+       if (log_level == LOG_DEBUG) {
+               if (!sensors)
+                       return;
+
                while (*sensors) {
                        log_debug("Measure: %s %.2f",
                                   (*sensors)->name,
@@ -435,6 +443,7 @@ void psensor_log_measures(struct psensor **sensors)
 
                        sensors++;
                }
+       }
 }
 
 struct psensor **psensor_list_copy(struct psensor **sensors)