make WebPSetWorkerInterface() check its arguments

Change-Id: I522c58cfe05e864a50cacb58bdfa14d5369c6d60
This commit is contained in:
skal 2014-06-23 07:39:56 +02:00
parent a9ef7ef991
commit 5584d9d2fc
2 changed files with 10 additions and 5 deletions

View File

@ -290,9 +290,15 @@ static WebPWorkerInterface g_worker_interface = {
Init, Reset, Sync, Launch, Execute, End
};
void WebPSetWorkerInterface(const WebPWorkerInterface* const interface) {
assert(interface != NULL);
int WebPSetWorkerInterface(const WebPWorkerInterface* const interface) {
if (interface == NULL ||
interface->Init == NULL || interface->Reset == NULL ||
interface->Sync == NULL || interface->Launch == NULL ||
interface->Execute == NULL || interface->End == NULL) {
return 0;
}
g_worker_interface = *interface;
return 1;
}
const WebPWorkerInterface* WebPGetWorkerInterface(void) {
@ -300,4 +306,3 @@ const WebPWorkerInterface* WebPGetWorkerInterface(void) {
}
//------------------------------------------------------------------------------

View File

@ -77,8 +77,8 @@ typedef struct {
// should be done before any workers are started, i.e., before any encoding or
// decoding takes place. The contents of the interface struct are copied, it
// is safe to free the corresponding memory after this call. This function is
// not thread-safe.
WEBP_EXTERN(void) WebPSetWorkerInterface(
// not thread-safe. Return false in case of invalid pointer or methods.
WEBP_EXTERN(int) WebPSetWorkerInterface(
const WebPWorkerInterface* const interface);
// Retrieve the currently set thread worker interface.