mirror of
https://git.tartarus.org/simon/putty.git
synced 2025-01-09 17:38:00 +00:00
testcrypt: refactor return_opt_foo functions.
There are already three tediously similar functions that wrap a NULL check around some existing function to return one or another kind of pointer, and I'm about to want to add another one. Make a macro so that it's easy to make more functions identical to these three.
This commit is contained in:
parent
4b8aad76f8
commit
4d0c2ca90f
33
testcrypt.c
33
testcrypt.c
@ -503,29 +503,18 @@ static void return_val_string_asciz(strbuf *out, char *s)
|
||||
return_val_string(out, sb);
|
||||
}
|
||||
|
||||
static void return_opt_val_string_asciz(strbuf *out, char *s)
|
||||
{
|
||||
if (!s)
|
||||
strbuf_catf(out, "NULL\n");
|
||||
else
|
||||
return_val_string_asciz(out, s);
|
||||
}
|
||||
#define NULLABLE_RETURN_WRAPPER(type_name, c_type) \
|
||||
static void return_opt_##type_name(strbuf *out, c_type ptr) \
|
||||
{ \
|
||||
if (!ptr) \
|
||||
strbuf_catf(out, "NULL\n"); \
|
||||
else \
|
||||
return_##type_name(out, ptr); \
|
||||
}
|
||||
|
||||
static void return_opt_val_cipher(strbuf *out, ssh_cipher *c)
|
||||
{
|
||||
if (!c)
|
||||
strbuf_catf(out, "NULL\n");
|
||||
else
|
||||
return_val_cipher(out, c);
|
||||
}
|
||||
|
||||
static void return_opt_val_hash(strbuf *out, ssh_hash *h)
|
||||
{
|
||||
if (!h)
|
||||
strbuf_catf(out, "NULL\n");
|
||||
else
|
||||
return_val_hash(out, h);
|
||||
}
|
||||
NULLABLE_RETURN_WRAPPER(val_string_asciz, char *)
|
||||
NULLABLE_RETURN_WRAPPER(val_cipher, ssh_cipher *)
|
||||
NULLABLE_RETURN_WRAPPER(val_hash, ssh_hash *)
|
||||
|
||||
static void handle_hello(BinarySource *in, strbuf *out)
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user