Skip to content

Commit ecb548e

Browse files
lstipakovcron2
authored andcommitted
TRY_GETPROP: make it more pretty for VOID callers
Because TRY_GETPROP(hwnd, cfgProp, c, ); looks a bit scary. Signed-off-by: Lev Stipakov <[email protected]>
1 parent 211cc8c commit ecb548e

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

openvpn.h

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,20 +35,25 @@
3535
return false; \
3636
} while (0)
3737

38-
/* A macro to set lval = GetProp(hwnd, name) or log an error and return err_return */
39-
#define TRY_GETPROP(hwnd, name, lval, err_return) \
38+
/* A macro to set lval = GetProp(hwnd, name) or log and execute on_fail statement on error */
39+
#define TRY_GETPROP_IMPL(hwnd, name, lval, on_fail) \
4040
do \
4141
{ \
4242
HANDLE handle_##lval = GetProp(hwnd, name); \
4343
if (!handle_##lval) \
4444
{ \
4545
MsgToEventLog( \
4646
EVENTLOG_ERROR_TYPE, L"%hs:%d GetProp returned null", __func__, __LINE__); \
47-
return err_return; \
47+
on_fail; \
4848
} \
4949
lval = (__typeof__(lval))handle_##lval; \
5050
} while (0)
5151

52+
#define TRY_GETPROP(hwnd, name, lval, err_return) \
53+
TRY_GETPROP_IMPL(hwnd, name, lval, return err_return)
54+
55+
#define TRY_GETPROP_VOID(hwnd, name, lval) TRY_GETPROP_IMPL(hwnd, name, lval, return)
56+
5257
BOOL StartOpenVPN(connection_t *);
5358

5459
void StopOpenVPN(connection_t *);

pkcs11.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -477,7 +477,7 @@ static void CALLBACK
477477
pkcs11_listview_fill(HWND hwnd, UINT UNUSED msg, UINT_PTR id, DWORD UNUSED now)
478478
{
479479
connection_t *c;
480-
TRY_GETPROP(hwnd, cfgProp, c, );
480+
TRY_GETPROP_VOID(hwnd, cfgProp, c);
481481

482482
struct pkcs11_list *l = &c->pkcs11_list;
483483

@@ -542,7 +542,7 @@ static void
542542
pkcs11_listview_reset(HWND parent)
543543
{
544544
connection_t *c;
545-
TRY_GETPROP(parent, cfgProp, c, );
545+
TRY_GETPROP_VOID(parent, cfgProp, c);
546546
struct pkcs11_list *l = &c->pkcs11_list;
547547
HWND lv = GetDlgItem(parent, ID_LVW_PKCS11);
548548

0 commit comments

Comments
 (0)