summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorwm4 <wm4@nowhere>2015-01-20 14:32:01 +0100
committerDiogo Franco (Kovensky) <diogomfranco@gmail.com>2015-01-25 17:00:20 +0900
commit7d523cd47a0efecb0ff01d24bad398f5d2a26ab0 (patch)
tree656d05c8d7e5843367c3822e91e058ce29d62607
parent224abe9e23f1ea8e34401e8fab59262501b70c46 (diff)
downloadmpv-7d523cd47a0efecb0ff01d24bad398f5d2a26ab0.tar.bz2
mpv-7d523cd47a0efecb0ff01d24bad398f5d2a26ab0.tar.xz
ao_coreaudio: reset possibly random errno value
In general, you need to check errno when using strtol(), but as far as I know, strtol() won't reset errno on success. This has to be done manually. The code could have failed sporadically if strtol() succeeded, and errno was already set to one of the checked values. (This strtol() still isn't fully error checked, but I don't know if it's intentional, e.g. for parsing a numeric prefix only.)
-rw-r--r--audio/out/ao_coreaudio_utils.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/audio/out/ao_coreaudio_utils.c b/audio/out/ao_coreaudio_utils.c
index 8d85842dfd..fe8354939a 100644
--- a/audio/out/ao_coreaudio_utils.c
+++ b/audio/out/ao_coreaudio_utils.c
@@ -65,7 +65,8 @@ coreaudio_error:
OSStatus ca_select_device(struct ao *ao, char* name, AudioDeviceID *device)
{
OSStatus err = noErr;
- int selection = name ? strtol(name, (char **)NULL, 10) : -1;
+ errno = 0;
+ int selection = name && name[0] ? strtol(name, (char **)NULL, 10) : -1;
if (errno == EINVAL || errno == ERANGE) {
selection = -1;
MP_WARN(ao, "device identifier '%s' is invalid\n", name);