OSDN Git Service

Dont allow zero division to happen
authorwifiextender <router@archlinux.info>
Sat, 20 Aug 2016 04:38:56 +0000 (06:38 +0200)
committerwifiextender <router@archlinux.info>
Sat, 20 Aug 2016 04:38:56 +0000 (06:38 +0200)
src/cpu.c
src/linux_functions.c
src/sound.c

index 90c02dd..4f74e11 100644 (file)
--- a/src/cpu.c
+++ b/src/cpu.c
@@ -81,7 +81,7 @@ get_cpu(char *str1) {
   previous_idle  = cpu_active[IDLE_NUM];
 
   percent        = 0;
-  if (0 != diff_total) {
+  if (0 != diff_total && 0 != diff_idle) {
     percent      = ((uintmax_t)TICKZ * (diff_total - diff_idle)) / diff_total;
   }
 
@@ -169,7 +169,7 @@ get_cores_load(char *str1) {
     previous_idle[x]  = core_active[x][IDLE_NUM];
 
     percent[x]        = 0;
-    if (0 != diff_total[x]) {
+    if (0 != diff_total[x] && 0 != diff_idle[x]) {
       percent[x]      = ((uintmax_t)TICKZ * (diff_total[x] - diff_idle[x]))
                             / diff_total[x];
     }
index 3e7d243..ad460d8 100644 (file)
@@ -218,7 +218,7 @@ get_battery(char *str1) {
 #pragma GCC diagnostic pop
 
   percent = 0;
-  if (0 != total) {
+  if (0 != total && 0 != used) {
     percent = (used * 100) / total;
   }
   FILL_UINT_ARR(str1, percent);
index b34f07e..91c4848 100644 (file)
@@ -74,7 +74,7 @@ get_volume(char *str1) {
   snd_mixer_selem_get_playback_volume_range(elem, &min, &max);
 
   percent = 0L;
-  if (0 != max) {
+  if (0 != max && 0 != vol) {
     percent = (vol * 100) / max;
   }