diff mbox series

ALSA: conf: Save SND_CONFIG_TYPE_REAL with at least one decimal

Message ID f9a7ad6a256d4ad7a31642dcf875d436@axis.com (mailing list archive)
State New, archived
Headers show
Series ALSA: conf: Save SND_CONFIG_TYPE_REAL with at least one decimal | expand

Commit Message

Simon Svanbom Dec. 13, 2022, 7:55 a.m. UTC
Hi,
patch for saving SND_CONFIG_TYPE_REAL with at least one decimal as to not misinterpret the value as an integer in snd_config_get_real. Example would be the sofvol configuration property min_dB and max_dB, that are required to have at least one decimal.

All the best

// Simon

Comments

Jaroslav Kysela Dec. 13, 2022, 11:12 a.m. UTC | #1
On 13. 12. 22 8:55, Simon Svanbom wrote:
> Hi,
> patch for saving SND_CONFIG_TYPE_REAL with at least one decimal as to not 
> misinterpret the value asĀ an integer in snd_config_get_real. Example would be 
> the sofvol configuration property min_dB and max_dB, that are required to have 
> at least one decimal.

Thanks. I pushed this fix to repo using the snd_config_get_ireal() function in the configuration parsing code:

https://github.com/alsa-project/alsa-lib/commit/9f2c68cef716aa45942b502a42d94b84289f23bc

					Jaroslav
diff mbox series

Patch

From d679d469cd048d01edfec952c5550aca8fd4b04a Mon Sep 17 00:00:00 2001
From: Simon Svanbom <simochr@axis.com>
Date: Tue, 13 Dec 2022 08:23:53 +0100
Subject: [PATCH] conf: Save SND_CONFIG_TYPE_REAL with at least one decimal

Save node values of type SND_CONFIG_TYPE_REAL with at least
one decimal in order not to misinterpret the value as
an integer in snd_config_get_real.

Change-Id: I5897ba8ea6be3217f40dd382a98e17ffca3d56be
---
 src/conf.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/conf.c b/src/conf.c
index 65f2e1a7..de051283 100644
--- a/src/conf.c
+++ b/src/conf.c
@@ -1634,7 +1634,12 @@  int _snd_config_save_node_value(snd_config_t *n, snd_output_t *out,
 		snd_output_printf(out, "%lld", n->u.integer64);
 		break;
 	case SND_CONFIG_TYPE_REAL:
-		snd_output_printf(out, "%-16g", n->u.real);
+		/* If no decimals provided, print at least one */
+		if (n->u.real == (int)n->u.real) {
+			snd_output_printf(out, "%-.1f", n->u.real);
+		} else {
+			snd_output_printf(out, "%-16g", n->u.real);
+		}
 		break;
 	case SND_CONFIG_TYPE_STRING:
 		string_print(n->u.string, 0, out);
-- 
2.20.1