# HG changeset patch # User Rik # Date 1590944216 25200 # Node ID c4cf47906bd2f930748ad1a759ac76a1f76882f0 # Parent 7d63f42e94becbc983958ac80cec72ba3f0fd731 Fix input validation for audioplayer (bug #57939). * audiodevinfo.cc (F__player_audioplayer__): Replace '||' with '&&' in if conditional checking for correct NBITS input. * audioplayer.m: Add BIST tests for checking NBITS input. diff -r 7d63f42e94be -r c4cf47906bd2 libinterp/dldfcn/audiodevinfo.cc --- a/libinterp/dldfcn/audiodevinfo.cc Wed Sep 09 15:15:47 2020 -0400 +++ b/libinterp/dldfcn/audiodevinfo.cc Sun May 31 09:56:56 2020 -0700 @@ -2383,7 +2383,7 @@ { // FIXME: Should be able to support 32-bit streams (bug #57939) int nbits = args(2).int_value (); - if (nbits != 8 || nbits != 16 || nbits != 24) + if (nbits != 8 && nbits != 16 && nbits != 24) error ("audioplayer: NBITS must be 8, 16, or 24"); switch (args.length ()) diff -r 7d63f42e94be -r c4cf47906bd2 scripts/audio/@audioplayer/audioplayer.m --- a/scripts/audio/@audioplayer/audioplayer.m Wed Sep 09 15:15:47 2020 -0400 +++ b/scripts/audio/@audioplayer/audioplayer.m Sun May 31 09:56:56 2020 -0700 @@ -175,6 +175,15 @@ %! properties = get (player, {"SampleRate", "Tag", "UserData"}); %! assert (properties, {8000, "tag", [1, 2; 3, 4]}); +%!testif HAVE_PORTAUDIO; audiodevinfo (0) > 0 +%! ## Verify nbits option only accepts 8, 16, 24 +%! fail ("audioplayer (1, 8e3, 9)", "NBITS must be 8, 16, or 24"); +%! fail ("audioplayer (1, 8e3, 32)", "NBITS must be 8, 16, or 24"); +%! player = audioplayer (1, 8e3, 8); +%! player = audioplayer (1, 8e3, 16); +%! player = audioplayer (1, 8e3, 24); + +## FIXME: Callbacks do not work currently (5/31/2020) so BIST tests commented. #%!function [sound, status] = callback (samples) #%! sound = rand (samples, 2) - 0.5; #%! status = 0;