mirror of
https://github.com/morgan9e/FreeRDP
synced 2026-04-15 00:44:19 +09:00
[winpr,collections] fix PubSub_OnEvent return checks
* proper return checks on use * fix return on invalid input arguments * fix return on no event registered
This commit is contained in:
@@ -23,6 +23,9 @@
|
||||
|
||||
#include <winpr/collections.h>
|
||||
|
||||
#include "../log.h"
|
||||
#define TAG WINPR_TAG("pubsub")
|
||||
|
||||
/**
|
||||
* Events (C# Programming Guide)
|
||||
* http://msdn.microsoft.com/en-us/library/awbftdfh.aspx
|
||||
@@ -196,25 +199,23 @@ int PubSub_Unsubscribe(wPubSub* pubSub, const char* EventName, ...)
|
||||
|
||||
int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, const wEventArgs* e)
|
||||
{
|
||||
wEventType* event = nullptr;
|
||||
int status = -1;
|
||||
WINPR_ASSERT(pubSub);
|
||||
WINPR_ASSERT(EventName);
|
||||
WINPR_ASSERT(e);
|
||||
|
||||
if (!pubSub)
|
||||
{
|
||||
WLog_ERR(TAG, "pubSub(%s)=nullptr!", EventName);
|
||||
return -1;
|
||||
WINPR_ASSERT(e);
|
||||
}
|
||||
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Lock(pubSub);
|
||||
|
||||
event = PubSub_FindEventType(pubSub, EventName);
|
||||
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Unlock(pubSub);
|
||||
|
||||
int status = 0;
|
||||
wEventType* event = PubSub_FindEventType(pubSub, EventName);
|
||||
if (event)
|
||||
{
|
||||
status = 0;
|
||||
|
||||
for (size_t index = 0; index < event->EventHandlerCount; index++)
|
||||
{
|
||||
if (event->EventHandlers[index])
|
||||
@@ -224,6 +225,8 @@ int PubSub_OnEvent(wPubSub* pubSub, const char* EventName, void* context, const
|
||||
}
|
||||
}
|
||||
}
|
||||
if (pubSub->synchronized)
|
||||
PubSub_Unlock(pubSub);
|
||||
|
||||
return status;
|
||||
}
|
||||
|
||||
@@ -55,7 +55,8 @@ int TestPubSub(int argc, char* argv[])
|
||||
e.x = 64;
|
||||
e.y = 128;
|
||||
|
||||
PubSub_OnMouseMotion(node, nullptr, &e);
|
||||
if (PubSub_OnMouseMotion(node, nullptr, &e) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
{
|
||||
@@ -66,7 +67,8 @@ int TestPubSub(int argc, char* argv[])
|
||||
e.flags = 7;
|
||||
e.button = 1;
|
||||
|
||||
PubSub_OnMouseButton(node, nullptr, &e);
|
||||
if (PubSub_OnMouseButton(node, nullptr, &e) < 0)
|
||||
return -1;
|
||||
}
|
||||
|
||||
PubSub_Free(node);
|
||||
|
||||
Reference in New Issue
Block a user