Blame SOURCES/d5221655dfd1a2156aa6be83b5aadea7c1e0f5bd.diff

2977ff
diff --git a/src/audio_out.c b/src/audio_out.c
2977ff
index bd8f6fc..f5942d6 100644
2977ff
--- a/src/audio_out.c
2977ff
+++ b/src/audio_out.c
2977ff
@@ -634,6 +634,10 @@ static char *_sanitize_matrix(int maxchannels, char *matrix, ao_device *device){
2977ff
     char *ret = calloc(strlen(matrix)+1,1); /* can only get smaller */
2977ff
     char *p=matrix;
2977ff
     int count=0;
2977ff
+
2977ff
+    if(!ret)
2977ff
+      return NULL;
2977ff
+
2977ff
     while(count
2977ff
       char *h,*t;
2977ff
       int m=0;
2977ff
@@ -706,6 +710,15 @@ static int _find_channel(int needle, char *haystack){
2977ff
   return -1;
2977ff
 }
2977ff
 
2977ff
+static void _free_map(char **m){
2977ff
+  char **in=m;
2977ff
+  while(m && *m){
2977ff
+    free(*m);
2977ff
+    m++;
2977ff
+  }
2977ff
+  if(in)free(in);
2977ff
+}
2977ff
+
2977ff
 static char **_tokenize_matrix(char *matrix){
2977ff
   char **ret=NULL;
2977ff
   char *p=matrix;
2977ff
@@ -730,6 +743,8 @@ static char **_tokenize_matrix(char *matrix){
2977ff
   }
2977ff
 
2977ff
   ret = calloc(count+1,sizeof(*ret));
2977ff
+  if(!ret)
2977ff
+    return NULL;
2977ff
 
2977ff
   p=matrix;
2977ff
   count=0;
2977ff
@@ -748,6 +763,10 @@ static char **_tokenize_matrix(char *matrix){
2977ff
     while(t>p && isspace(*(t-1)))t--;
2977ff
 
2977ff
     ret[count] = calloc(t-p+1,1);
2977ff
+    if(!ret[count]){
2977ff
+      _free_map(ret);
2977ff
+      return NULL;
2977ff
+    }
2977ff
     memcpy(ret[count],p,t-p);
2977ff
     count++;
2977ff
     if(!*h)break;
2977ff
@@ -755,16 +774,6 @@ static char **_tokenize_matrix(char *matrix){
2977ff
   }
2977ff
 
2977ff
   return ret;
2977ff
-
2977ff
-}
2977ff
-
2977ff
-static void _free_map(char **m){
2977ff
-  char **in=m;
2977ff
-  while(m && *m){
2977ff
-    free(*m);
2977ff
-    m++;
2977ff
-  }
2977ff
-  if(in)free(in);
2977ff
 }
2977ff
 
2977ff
 static unsigned int _matrix_to_channelmask(int ch, char *matrix, char *premap, int **mout){
2977ff
@@ -772,7 +781,14 @@ static unsigned int _matrix_to_channelmask(int ch, char *matrix, char *premap, i
2977ff
   char *p=matrix;
2977ff
   int *perm=(*mout=malloc(ch*sizeof(*mout)));
2977ff
   int i;
2977ff
-  char **map = _tokenize_matrix(premap);
2977ff
+  char **map;
2977ff
+
2977ff
+  if(!perm)
2977ff
+    return 0;
2977ff
+
2977ff
+  map = _tokenize_matrix(premap);
2977ff
+  if(!map)
2977ff
+    return 0;
2977ff
 
2977ff
   for(i=0;i
2977ff
   i=0;
2977ff
@@ -810,6 +826,9 @@ static char *_channelmask_to_matrix(unsigned int mask, char *premap){
2977ff
   char buffer[257]={0};
2977ff
   char **map = _tokenize_matrix(premap);
2977ff
 
2977ff
+  if(!map)
2977ff
+    return NULL;
2977ff
+
2977ff
   while(map[m]){
2977ff
     if(mask & (1<
2977ff
       if(count)
2977ff
@@ -849,6 +868,9 @@ static char *_matrix_intersect(char *matrix,char *premap){
2977ff
   int count=0;
2977ff
   char **map = _tokenize_matrix(premap);
2977ff
 
2977ff
+  if(!map)
2977ff
+    return NULL;
2977ff
+
2977ff
   while(1){
2977ff
     char *h=p;
2977ff
     int m=0;
2977ff
@@ -1039,7 +1061,7 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
2977ff
                                                          device->output_matrix,
2977ff
                                                          &device->input_map);
2977ff
               int channels = _channelmask_bits(mask);
2977ff
-              if(channels<0){
2977ff
+              if(channels<=0){
2977ff
                 aerror("Unable to map any channels from input matrix to output");
2977ff
                 errno = AO_EBADFORMAT;
2977ff
                 goto error;
2977ff
@@ -1060,7 +1082,7 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
2977ff
                                                          device->output_matrix,
2977ff
                                                          &device->input_map);
2977ff
               int channels = _channelmask_bits(mask);
2977ff
-              if(channels<0){
2977ff
+              if(channels<=0){
2977ff
                 aerror("Unable to map any channels from input matrix to output");
2977ff
                 errno = AO_EBADFORMAT;
2977ff
                 goto error;
2977ff
@@ -1111,6 +1133,10 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
2977ff
             int count=0;
2977ff
             device->inter_permute = calloc(device->output_channels,sizeof(int));
2977ff
 
2977ff
+            if (!device->inter_permute) {
2977ff
+              errno = AO_EFAIL;
2977ff
+              goto error;
2977ff
+            }
2977ff
             adebug("\n");
2977ff
 
2977ff
             while(count<device->output_channels){
2977ff
@@ -1157,8 +1183,10 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
2977ff
                 for(i=0;i<device->output_channels;i++)
2977ff
                   if(device->inter_permute[i]==j)break;
2977ff
                 if(i==device->output_channels){
2977ff
-                  adebug("input %d (%s)\t -> none\n",
2977ff
-                         j,inch[j]);
2977ff
+                  if(inch){
2977ff
+                    adebug("input %d (%s)\t -> none\n",
2977ff
+                           j,inch[j]);
2977ff
+                  }
2977ff
                   unflag=1;
2977ff
                 }
2977ff
               }
2977ff
diff --git a/src/plugins/macosx/ao_macosx.c b/src/plugins/macosx/ao_macosx.c
2977ff
index a3daf1b..129020d 100644
2977ff
--- a/src/plugins/macosx/ao_macosx.c
2977ff
+++ b/src/plugins/macosx/ao_macosx.c
2977ff
@@ -594,11 +594,11 @@ int ao_plugin_open(ao_device *device, ao_sample_format *format)
2977ff
   internal->firstValidByteOffset = 0;
2977ff
   internal->validByteCount = 0;
2977ff
   internal->buffer = malloc(internal->bufferByteCount);
2977ff
-  memset(internal->buffer, 0, internal->bufferByteCount);
2977ff
   if (!internal->buffer) {
2977ff
     aerror("Unable to allocate queue buffer.\n");
2977ff
     return 0;
2977ff
   }
2977ff
+  memset(internal->buffer, 0, internal->bufferByteCount);
2977ff
 
2977ff
   /* limited to stereo for now */
2977ff
   //if(!device->output_matrix)
2977ff
diff --git a/src/plugins/sndio/ao_sndio.c b/src/plugins/sndio/ao_sndio.c
2977ff
index ec251fb..e23fd47 100644
2977ff
--- a/src/plugins/sndio/ao_sndio.c
2977ff
+++ b/src/plugins/sndio/ao_sndio.c
2977ff
@@ -67,6 +67,9 @@ int ao_plugin_device_init(ao_device *device)
2977ff
 {
2977ff
   ao_sndio_internal *internal;
2977ff
   internal = (ao_sndio_internal *) calloc(1,sizeof(*internal));
2977ff
+  if (internal == NULL)
2977ff
+    return 0;
2977ff
+
2977ff
   internal->id=-1;
2977ff
   device->internal = internal;
2977ff
   device->output_matrix_order = AO_OUTPUT_MATRIX_FIXED;