From 7720a1195ae9e90a427e0fc5d14023405d224b6a Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 14 Nov 2008 18:15:33 +0100 Subject: [PATCH] volume: eliminate alloca() usage alloca() is not a portable function. Don't use it. Using strncasecmp() is much more efficient anyway, because no memory needs to be allocated and copied. --- src/volume.c | 15 ++++----------- 1 file changed, 4 insertions(+), 11 deletions(-) diff --git a/src/volume.c b/src/volume.c index b1f7f186b..9fd33f010 100644 --- a/src/volume.c +++ b/src/volume.c @@ -79,8 +79,6 @@ static int volume_alsaSet = -1; #ifdef HAVE_OSS -#include /* only alloca user in mpd atm, may change ... */ - static void closeOssMixer(void) { while (close(volume_ossFd) && errno == EINTR) ; @@ -91,17 +89,12 @@ static int oss_find_mixer(const char *name) { const char *labels[SOUND_MIXER_NRDEVICES] = SOUND_DEVICE_LABELS; + size_t name_length = strlen(name); for (unsigned i = 0; i < SOUND_MIXER_NRDEVICES; i++) { - ssize_t len = strlen(labels[i]); - char *duplicated = alloca(len + 1); - - /* eliminate spaces at the end */ - memcpy(duplicated, labels[i], len + 1); - len -= 2; - while (len >= 0 && duplicated[len] == ' ') - duplicated[len--] = '\0'; - if (strcasecmp(duplicated, name) == 0) + if (strncasecmp(name, labels[i], name_length) == 0 && + (labels[i][name_length] == 0 || + labels[i][name_length] == ' ')) return i; }