From b8b8792bb076f6a8c1ee84459e6a5c95d5274aec Mon Sep 17 00:00:00 2001 From: Jan Engelhardt Date: Tue, 10 Oct 2023 11:18:29 +0200 Subject: [PATCH] Revert "tools: use initialization rather than assignment to construct serialize descriptors" This reverts commit 23d59548904908c8c095ede4570b718da2bb6ac9. clang gets confused when seeing brace-init-lists and emits what I see as false positive warnings: lib/exmdb_rpc.cpp:27:28: warning: suggest braces around initialization of subobject [-Wmissing-braces] 27 | exreq_get_named_propids q{exmdb_callid::get_named_propids, deconst(dir), b_create, deconst(ppropnames)}; Since the rules for brace-init-lists are kind of intransparent for human readers as well, do without initialization of this kind. --- exch/exmdb_provider/exmdb_client.cpp | 11 ++++++++--- include/gromox/exmdb_rpc.hpp | 8 +++++--- lib/exmdb_ext.cpp | 4 ++-- tools/exmidl.pl | 12 +++++++----- tools/zcidl.pl | 10 +++++----- 5 files changed, 27 insertions(+), 18 deletions(-) diff --git a/exch/exmdb_provider/exmdb_client.cpp b/exch/exmdb_provider/exmdb_client.cpp index 9d5702771..3d22c8d4e 100644 --- a/exch/exmdb_provider/exmdb_client.cpp +++ b/exch/exmdb_provider/exmdb_client.cpp @@ -44,10 +44,15 @@ BOOL exmdb_client_relay_delivery(const char *dir, const char *from_address, exmdb_server::set_dir(original_dir); return b_result; } - exreq_deliver_message q{exmdb_callid::deliver_message, deconst(dir), - deconst(from_address), deconst(account), cpid, 0, - deconst(pmsg), deconst(pdigest)}; + exreq_deliver_message q{}; exresp_deliver_message r{}; + q.call_id = exmdb_callid::deliver_message; + q.dir = deconst(dir); + q.from_address = deconst(from_address); + q.account = deconst(account); + q.cpid = cpid; + q.pmsg = deconst(pmsg); + q.pdigest = deconst(pdigest); if (!exmdb_client_do_rpc(&q, &r)) return FALSE; *presult = r.result; diff --git a/include/gromox/exmdb_rpc.hpp b/include/gromox/exmdb_rpc.hpp index 1cd6e2d12..83b9fefa4 100644 --- a/include/gromox/exmdb_rpc.hpp +++ b/include/gromox/exmdb_rpc.hpp @@ -166,8 +166,9 @@ enum class exmdb_callid : uint8_t { }; struct exreq { - exmdb_callid call_id; - char *dir; + exreq() = default; /* Prevent use of direct-list-init */ + exmdb_callid call_id{}; + char *dir = nullptr; }; struct exreq_connect : public exreq { @@ -856,7 +857,8 @@ struct exreq_recalc_store_size : public exreq { }; struct exresp { - exmdb_callid call_id; + exresp() = default; /* Prevent use of direct-init-list */ + exmdb_callid call_id{}; }; struct exresp_get_all_named_propids : public exresp { diff --git a/lib/exmdb_ext.cpp b/lib/exmdb_ext.cpp index a33299e92..38980a9a3 100644 --- a/lib/exmdb_ext.cpp +++ b/lib/exmdb_ext.cpp @@ -1891,7 +1891,7 @@ static pack_result exmdb_pull(EXT_PULL &x, exreq_get_content_sync &d) BINARY tmp_bin; uint8_t tmp_byte; - memset(&d, 0, sizeof(d)); + d = {}; TRY(x.g_uint64(&d.folder_id)); TRY(x.g_uint8(&tmp_byte)); if (tmp_byte != 0) @@ -2038,7 +2038,7 @@ static pack_result exmdb_pull(EXT_PULL &x, exreq_get_hierarchy_sync &d) BINARY tmp_bin; uint8_t tmp_byte; - memset(&d, 0, sizeof(d)); + d = {}; TRY(x.g_uint64(&d.folder_id)); TRY(x.g_uint8(&tmp_byte)); if (tmp_byte != 0) diff --git a/tools/exmidl.pl b/tools/exmidl.pl index 0dfa0916e..32e83cca0 100755 --- a/tools/exmidl.pl +++ b/tools/exmidl.pl @@ -63,21 +63,23 @@ } print "BOOL exmdb_client_remote::$func($rbsig)\n{\n"; - print "\texreq_$func q{exmdb_callid::$func, deconst(dir)"; + print "\texreq_$func q{};\n\texresp_$func r{};\n"; + print "\n"; + print "\tq.call_id = exmdb_callid::$func;\n"; + print "\tq.dir = deconst(dir);\n"; for (@$iargs) { my($type, $field) = @$_; if (substr($type, -1, 1) eq "*") { - print ", deconst($field)"; + print "\tq.$field = deconst($field);\n"; } elsif (substr($type, -1, 1) eq "&") { # struct members should continue to use a pointer, # because refs are so awkward to assign (more so during # deserialization than with serialization) - print ", deconst(&$field)"; + print "\tq.$field = deconst(&$field);\n"; } else { - print ", $field"; + print "\tq.$field = $field;\n"; } } - print "};\n\texresp_$func r{};\n"; print "\tif (!exmdb_client_do_rpc(&q, &r))\n\t\treturn false;\n"; for (@$oargs) { my($type, $field) = @$_; diff --git a/tools/zcidl.pl b/tools/zcidl.pl index f86fd5251..07864b19c 100755 --- a/tools/zcidl.pl +++ b/tools/zcidl.pl @@ -47,18 +47,18 @@ } print "uint32_t zclient_$func($rbsig)\n{\n"; - print "\tzcreq_$func q{zcore_callid::$func"; + print "\tzcreq_$func q{};\n\tzcresp_$func r{};\n\n"; + print "\tq.call_id = zcore_callid::$func;\n"; for (@$iargs) { my($type, $field) = @$_; if (substr($type, -1, 1) eq "*") { - print ", deconst($field)"; + print "\tq.$field = deconst($field);\n"; } elsif (substr($type, -1, 1) eq "&") { - print ", deconst(&$field)"; + print "\tq.$field = deconst(&$field);\n"; } else { - print ", $field"; + print "\tq.$field = $field;\n"; } } - print "};\n\tzcresp_$func r{};\n\n"; print "\tif (!zclient_do_rpc(&q, &r))\n\t\treturn ecRpcFailed;\n"; if (scalar(@$oargs) > 0) { print "\tif (r.result != ecSuccess)\n\t\treturn r.result;\n";