alsa-project / alsa-lib

The Advanced Linux Sound Architecture (ALSA) - library
GNU Lesser General Public License v2.1
366 stars 177 forks source link

Add support for some non-alphanumeric variable names in the math expr evaluator #197

Closed ranj063 closed 2 years ago

ranj063 commented 2 years ago

The math expression evaluator expects variable names to only be alpha-numeric. So if I have something like "[$DYNAMIC_PIPELINE + 2]", I get the error:

ALSA lib confeval.c:263:(snd_config_evaluate_string) wrong expression '$[$DYNAMIC_PIPELINE + 2]' ALSA lib conf.c:5632:(snd_config_expand_custom) Expand error (walk): Invalid argument Failed to expand pre-processor definitions in input config

Is it possible to add support for some non-alphanumeric characters in the variable names , esp '_'? I tried this change it seems to suffice:

diff --git a/src/confeval.c b/src/confeval.c
index a971bf38..7330d67e 100644
--- a/src/confeval.c
+++ b/src/confeval.c
@@ -190,7 +190,7 @@ int _snd_eval_string(snd_config_t **dst, const char *s,
                        } else {
                                e = s + 1;
                                while (*e) {
-                                       if (!isalnum(*e))
+                                       if (!isalnum(*e) && (*e != '_'))
                                                break;
                                        e++;
                                }
perexg commented 2 years ago

Thanks. It makes sense. Applied in https://github.com/alsa-project/alsa-lib/commit/f44c94f24c2422c5ee1c4c58253ec17412b248a9 .