[Scilab-users] Possible bug in wavread
Samuel Gougeon
sgougeon at free.fr
Mon Feb 25 01:40:56 CET 2019
Hello Federico,
Le 25/02/2019 à 01:06, Federico Miyara a écrit :
>
> Dear all,
>
> I'm reviewing the wavread function code which I could find (on Windows
> 7) at the following path:
>
> C:\Program Files\scilab-6.0.2\modules\sound\macros\wavread.sci
>
> There is a code segment at the beginninig intended to detect if the
> wavfile has or not the .wav extension:
>
> // Append .wav extension if necessary
> if ( strindex(wavfile, ".") == [] ) then
> wavfile = wavfile + ".wav";
> end
>
> This contains a bug, since the wavfile name might contain a dot
> different from the one between the name and the extension. The normal
> case would be
>
> sound.wav
>
> and in this case the code works fine if the trailing .wav is absent.
> But in a case such as
>
> sound_v1.1.wav
>
> the code will detect a dot within the abbreviated name 'sound_v1.1'
> and will not append the .wav extension, hence the function will fail
> to find and open the file.
>
> Fortunately the issue is solved quite easily:
>
> // Append .wav extension if necessary
> if (~(max(strindex(wavfile,'.wav')) == length(wavfile)-3)) then
> wavfile = wavfile + '.wav';
> end
You are right. The current test is very fragile.
The regular way would rather be
if fileparts(wavfile,"extension")<>"wav",
wavfile = wavfile+ ".wav"
end
Maybe fileparts() did not yet exist when the code was written.
Please do not hesitate to open another bug report to gather all this in
a trackable place.
Regards
Samuel
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.scilab.org/pipermail/users/attachments/20190225/83303dc2/attachment.htm>
More information about the users
mailing list