@@ -634,6 +634,10 @@ static char *_sanitize_matrix(int maxchannels, char *matrix, ao_device *device){
634
634
char * ret = calloc (strlen (matrix )+ 1 ,1 ); /* can only get smaller */
635
635
char * p = matrix ;
636
636
int count = 0 ;
637
+
638
+ if (!ret )
639
+ return NULL ;
640
+
637
641
while (count < maxchannels ){
638
642
char * h ,* t ;
639
643
int m = 0 ;
@@ -706,6 +710,15 @@ static int _find_channel(int needle, char *haystack){
706
710
return -1 ;
707
711
}
708
712
713
+ static void _free_map (char * * m ){
714
+ char * * in = m ;
715
+ while (m && * m ){
716
+ free (* m );
717
+ m ++ ;
718
+ }
719
+ if (in )free (in );
720
+ }
721
+
709
722
static char * * _tokenize_matrix (char * matrix ){
710
723
char * * ret = NULL ;
711
724
char * p = matrix ;
@@ -730,6 +743,8 @@ static char **_tokenize_matrix(char *matrix){
730
743
}
731
744
732
745
ret = calloc (count + 1 ,sizeof (* ret ));
746
+ if (!ret )
747
+ return NULL ;
733
748
734
749
p = matrix ;
735
750
count = 0 ;
@@ -748,31 +763,32 @@ static char **_tokenize_matrix(char *matrix){
748
763
while (t > p && isspace (* (t - 1 )))t -- ;
749
764
750
765
ret [count ] = calloc (t - p + 1 ,1 );
766
+ if (!ret [count ]){
767
+ _free_map (ret );
768
+ return NULL ;
769
+ }
751
770
memcpy (ret [count ],p ,t - p );
752
771
count ++ ;
753
772
if (!* h )break ;
754
773
p = h + 1 ;
755
774
}
756
775
757
776
return ret ;
758
-
759
- }
760
-
761
- static void _free_map (char * * m ){
762
- char * * in = m ;
763
- while (m && * m ){
764
- free (* m );
765
- m ++ ;
766
- }
767
- if (in )free (in );
768
777
}
769
778
770
779
static unsigned int _matrix_to_channelmask (int ch , char * matrix , char * premap , int * * mout ){
771
780
unsigned int ret = 0 ;
772
781
char * p = matrix ;
773
782
int * perm = (* mout = malloc (ch * sizeof (* mout )));
774
783
int i ;
775
- char * * map = _tokenize_matrix (premap );
784
+ char * * map ;
785
+
786
+ if (!perm )
787
+ return 0 ;
788
+
789
+ map = _tokenize_matrix (premap );
790
+ if (!map )
791
+ return 0 ;
776
792
777
793
for (i = 0 ;i < ch ;i ++ ) perm [i ] = -1 ;
778
794
i = 0 ;
@@ -810,6 +826,9 @@ static char *_channelmask_to_matrix(unsigned int mask, char *premap){
810
826
char buffer [257 ]= {0 };
811
827
char * * map = _tokenize_matrix (premap );
812
828
829
+ if (!map )
830
+ return NULL ;
831
+
813
832
while (map [m ]){
814
833
if (mask & (1 <<m )){
815
834
if (count )
@@ -849,6 +868,9 @@ static char *_matrix_intersect(char *matrix,char *premap){
849
868
int count = 0 ;
850
869
char * * map = _tokenize_matrix (premap );
851
870
871
+ if (!map )
872
+ return NULL ;
873
+
852
874
while (1 ){
853
875
char * h = p ;
854
876
int m = 0 ;
@@ -1039,7 +1061,7 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
1039
1061
device -> output_matrix ,
1040
1062
& device -> input_map );
1041
1063
int channels = _channelmask_bits (mask );
1042
- if (channels < 0 ){
1064
+ if (channels <= 0 ){
1043
1065
aerror ("Unable to map any channels from input matrix to output" );
1044
1066
errno = AO_EBADFORMAT ;
1045
1067
goto error ;
@@ -1060,7 +1082,7 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
1060
1082
device -> output_matrix ,
1061
1083
& device -> input_map );
1062
1084
int channels = _channelmask_bits (mask );
1063
- if (channels < 0 ){
1085
+ if (channels <= 0 ){
1064
1086
aerror ("Unable to map any channels from input matrix to output" );
1065
1087
errno = AO_EBADFORMAT ;
1066
1088
goto error ;
@@ -1111,6 +1133,10 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
1111
1133
int count = 0 ;
1112
1134
device -> inter_permute = calloc (device -> output_channels ,sizeof (int ));
1113
1135
1136
+ if (!device -> inter_permute ) {
1137
+ errno = AO_EFAIL ;
1138
+ goto error ;
1139
+ }
1114
1140
adebug ("\n" );
1115
1141
1116
1142
while (count < device -> output_channels ){
@@ -1157,8 +1183,10 @@ static ao_device* _open_device(int driver_id, ao_sample_format *format,
1157
1183
for (i = 0 ;i < device -> output_channels ;i ++ )
1158
1184
if (device -> inter_permute [i ]== j )break ;
1159
1185
if (i == device -> output_channels ){
1160
- adebug ("input %d (%s)\t -> none\n" ,
1161
- j ,inch [j ]);
1186
+ if (inch ){
1187
+ adebug ("input %d (%s)\t -> none\n" ,
1188
+ j ,inch [j ]);
1189
+ }
1162
1190
unflag = 1 ;
1163
1191
}
1164
1192
}
0 commit comments