tests don't check for NULL return value of Pa_GetDeviceInfo()
[Trac: Originally assigned to none]
Pa_GetDeviceInfo() returns NULL on error (usually an invalid device index is passed)
Many tests have code similar to:
Pa_GetDeviceInfo( Pa_GetDefaultOutputDevice() )->defaultLowOutputLatency;
Which will segfault if there is no default device (ie when Pa_GetDefaultOutputDevice() returns -1).
All tests and code should be corrected to check for a valid pointer return from Pa_GetDeviceInfo(), and also for a positive result from GetDefault*Device().
Pa_GetDeviceInfo() returns NULL on error (usually an invalid device index is passed)
Many tests have code similar to:
Pa_GetDeviceInfo( Pa_GetDefaultOutputDevice() )->defaultLowOutputLatency;
Which will segfault if there is no default device (ie when Pa_GetDefaultOutputDevice() returns -1).
All tests and code should be corrected to check for a valid pointer return from Pa_GetDeviceInfo(), and also for a positive result from GetDefault*Device().
Leave a comment
Magnus Jonsson used the following technique to fix this in paqa_errs.c in r1368
+ info = Pa_GetDeviceInfo(Pa_GetDefaultInputDevice());
+ ipp.suggestedLatency = info ? info->defaultLowInputLatency : 0.100;
+ info = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
+ opp.suggestedLatency = info ? info->defaultLowOutputLatency : 0.100;
+ info = Pa_GetDeviceInfo(Pa_GetDefaultInputDevice());
+ ipp.suggestedLatency = info ? info->defaultLowInputLatency : 0.100;
+ info = Pa_GetDeviceInfo(Pa_GetDefaultOutputDevice());
+ opp.suggestedLatency = info ? info->defaultLowOutputLatency : 0.100;
I don't really like Magnus Jonsson's solution, it masks an underlying bug (you shouldn't call Pa_GetDeviceInfo in such a way that it returns NULL).
To close this ticket you'd need to:
1. check the use of Pa_GetDeviceInfo in every file in the /tests directory to identify the tests that have the problem.
2. Fix the tests (preferably by bailing with an error message if Pa_GetDeviceInfo returns null). eg:
const PaDeviceInfo *info = Pa_GetDeviceInfo( x );
if( !info ){
Pa_Terminate();
fprintf(stderr, "PaGetDeviceInfo returned NULL");
exit(-1);
}
Usually the bug is encountered because there is no input (or output) device. The test should probably check this as a pre-condition before calling Pa_GetDeviceInfo().
To close this ticket you'd need to:
1. check the use of Pa_GetDeviceInfo in every file in the /tests directory to identify the tests that have the problem.
2. Fix the tests (preferably by bailing with an error message if Pa_GetDeviceInfo returns null). eg:
const PaDeviceInfo *info = Pa_GetDeviceInfo( x );
if( !info ){
Pa_Terminate();
fprintf(stderr, "PaGetDeviceInfo returned NULL");
exit(-1);
}
Usually the bug is encountered because there is no input (or output) device. The test should probably check this as a pre-condition before calling Pa_GetDeviceInfo().