summaryrefslogtreecommitdiff
path: root/sutils/0003-volume.c-take-some-care.patch
diff options
context:
space:
mode:
authorJohn Vogel <jvogel4@stny.rr.com>2023-10-09 10:50:09 -0400
committerJohn Vogel <jvogel4@stny.rr.com>2023-10-09 11:12:58 -0400
commita81715067469da5d17f9219ebe729ac549336dd6 (patch)
treea117fdcc31ad1d63545434bce18c96d012f93de0 /sutils/0003-volume.c-take-some-care.patch
parent6dff416c1d6721891bbabf48c186096a33708bbb (diff)
downloadmy-aports-a81715067469da5d17f9219ebe729ac549336dd6.tar.gz
local/sutils: fix some code issues
Diffstat (limited to 'sutils/0003-volume.c-take-some-care.patch')
-rw-r--r--sutils/0003-volume.c-take-some-care.patch55
1 files changed, 55 insertions, 0 deletions
diff --git a/sutils/0003-volume.c-take-some-care.patch b/sutils/0003-volume.c-take-some-care.patch
new file mode 100644
index 0000000..1ad3c28
--- /dev/null
+++ b/sutils/0003-volume.c-take-some-care.patch
@@ -0,0 +1,55 @@
+From 9c99628bb8a13ce825cf6ee7a3544a40b5527068 Mon Sep 17 00:00:00 2001
+From: John Vogel <jvogel4@stny.rr.com>
+Date: Mon, 9 Oct 2023 10:36:06 -0400
+Subject: [PATCH 3/4] volume.c: take some care
+
+Use strcpy instead of sprintf.
+Be more careful with the printf format.
+---
+ volume.c | 19 +++++++++++++------
+ 1 file changed, 13 insertions(+), 6 deletions(-)
+
+diff --git a/volume.c b/volume.c
+index 8117279..b0c49ee 100644
+--- a/volume.c
++++ b/volume.c
+@@ -25,6 +25,8 @@ int put_infos(int vol_min, int vol_max,
+ int volume;
+ int volume_percent;
+ bool mute_switch;
++ bool print_switch_state;
++ bool print_volume_percent;
+ char switch_state[4];
+
+ snd_hctl_elem_read(volume_elem, volume_ctl);
+@@ -36,16 +38,21 @@ int put_infos(int vol_min, int vol_max,
+ volume_percent = (int)(100.0f * ((float)volume - vol_min) / (vol_max - vol_min));
+
+ if (mute_switch == true)
+- sprintf(switch_state, "on");
++ strcpy(switch_state, "on");
+ else
+- sprintf(switch_state, "off");
++ strcpy(switch_state, "off");
+
+- if (strstr(format, "%s") == NULL)
+- printf(format, volume_percent);
+- else if (strstr(format, "%i") == NULL)
++ print_switch_state = (strstr(format, "%s") == NULL) ? false : true;
++ print_volume_percent = (strstr(format, "%i") == NULL) ? false : true;
++
++ if (print_switch_state && print_volume_percent)
++ printf(format, switch_state, volume_percent);
++ else if (print_switch_state)
+ printf(format, switch_state);
++ else if (print_volume_percent)
++ printf(format, volume_percent);
+ else
+- printf(format, switch_state, volume_percent);
++ exit(EXIT_FAILURE);
+ printf("\n");
+ fflush(stdout);
+
+--
+2.42.0
+