7d0af0856e42 — Chris Cannam 5 months ago
Don't allow a stream with no channels to be returned
1 files changed, 9 insertions(+), 8 deletions(-)

M ffi/bqaudiostream.sml
M ffi/bqaudiostream.sml +9 -8
@@ 26,14 26,15 @@ structure BqAudioReadStream :>
     fun stream_or_error stream =
         let val error_ptr = bqar_get_read_stream_error_text stream
         in
-            if error_ptr = MLton.Pointer.null
-            then OK stream
-            else
-                let val text = FFIStringConvert.convert_cstring error_ptr
-                in
-                    bqar_delete_read_stream stream;
-                    ERROR text
-                end
+            if error_ptr <> MLton.Pointer.null
+            then let val text = FFIStringConvert.convert_cstring error_ptr
+                 in
+                     bqar_delete_read_stream stream;
+                     ERROR text
+                 end
+            else if Int64.toInt (bqar_get_channel_count stream) = 0
+            then ERROR "Audio stream reports no channels"
+            else OK stream
         end            
             
     fun open_stream filename =