--- /home/reimar/MPlayer-cvs/libao2/ao_alsa.c 2004-06-27 00:22:48.000000000 +0200 +++ ao_alsa.c 2004-06-27 14:48:50.000000000 +0200 @@ -53,7 +53,6 @@ static snd_pcm_format_t alsa_format; static snd_pcm_hw_params_t *alsa_hwparams; static snd_pcm_sw_params_t *alsa_swparams; -static char *alsa_device; /* possible 4096, original 8192 * was only needed for calculating chunksize? */ @@ -77,7 +76,7 @@ static int set_block_mode; static int alsa_can_pause = 0; -#define ALSA_DEVICE_SIZE 48 +#define ALSA_DEVICE_SIZE 256 #undef BUFFERTIME #undef SET_CHUNKSIZE @@ -213,6 +212,9 @@ int device_set = 0; int dir = 0; snd_pcm_uframes_t bufsize; + char alsa_device[ALSA_DEVICE_SIZE + 1]; + // make sure alsa_device is null-terminated even when using strncpy etc. + memset(alsa_device, 0, ALSA_DEVICE_SIZE + 1); mp_msg(MSGT_AO,MSGL_V,"alsa-init: requested format: %d Hz, %d channels, %s\n", rate_hz, channels, audio_out_format_name(format)); @@ -331,7 +333,6 @@ if ((i3 < i2-1) && (strcmp(*(token_str+i3+1), "noblock") != 0) && (strcmp(*(token_str+i3+1), "mmap") != 0)) { char *tmp; - alsa_device = alloca(ALSA_DEVICE_SIZE); snprintf(alsa_device, ALSA_DEVICE_SIZE, "hw:%s", *(token_str+(i3+1))); if ((tmp = strrchr(alsa_device, '.')) && isdigit(*(tmp+1))) *tmp = ','; @@ -352,8 +353,6 @@ /* in any case for multichannel playback we should select * appropriate device */ - char devstr[128]; - switch (channels) { case 1: case 2: @@ -362,18 +361,18 @@ case 4: if (alsa_format == SND_PCM_FORMAT_FLOAT_LE) // hack - use the converter plugin - strcpy(devstr, "plug:surround40"); + strncpy(alsa_device, "plug:surround40", ALSA_DEVICE_SIZE); else - strcpy(devstr, "surround40"); - alsa_device = devstr; + strncpy(alsa_device, "surround40", ALSA_DEVICE_SIZE); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-init: device set to surround40\n"); break; case 6: if (alsa_format == SND_PCM_FORMAT_FLOAT_LE) - strcpy(devstr, "plug:surround51"); + strncpy(alsa_device, "plug:surround51", ALSA_DEVICE_SIZE); else - strcpy(devstr, "surround51"); - alsa_device = devstr; + strncpy(alsa_device, "surround51", ALSA_DEVICE_SIZE); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-init: device set to surround51\n"); break; default: @@ -388,7 +387,6 @@ * 'iec958' */ if (format == AFMT_AC3) { - char devstr[128]; unsigned char s[4]; //int err, c; //unused @@ -403,27 +401,30 @@ s[2] = 0; s[3] = IEC958_AES3_CON_FS_48000; - sprintf(devstr, "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x", + snprintf(alsa_device, ALSA_DEVICE_SIZE, + "iec958:AES0=0x%x,AES1=0x%x,AES2=0x%x,AES3=0x%x", s[0], s[1], s[2], s[3]); + device_set = 1; mp_msg(MSGT_AO,MSGL_V,"alsa-spdif-init: playing AC3, %i channels\n", channels); break; case 4: - strcpy(devstr, "surround40"); + strncpy(alsa_device, "surround40", ALSA_DEVICE_SIZE); + device_set = 1; break; case 6: - strcpy(devstr, "surround51"); + strncpy(alsa_device, "surround51", ALSA_DEVICE_SIZE); + device_set = 1; break; default: mp_msg(MSGT_AO,MSGL_ERR,"alsa-spdif-init: %d channels are not supported\n", channels); } - alsa_device = devstr; } - if (alsa_device == NULL) + if (!device_set) { int tmp_device, tmp_subdevice, err; @@ -432,11 +433,6 @@ mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: memory allocation error: %s\n", snd_strerror(err)); } - if ((alsa_device = alloca(ALSA_DEVICE_SIZE)) == NULL) - { - mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: memory allocation error: %s\n", strerror(errno)); - } - if ((tmp_device = snd_pcm_info_get_device(alsa_info)) < 0) { mp_msg(MSGT_AO,MSGL_ERR,"alsa-init: can't get device\n"); @@ -750,7 +746,6 @@ } else { alsa_handler = NULL; - alsa_device = NULL; mp_msg(MSGT_AO,MSGL_INFO,"alsa-uninit: pcm closed\n"); } }