Checking whether a name is empty via dns_name_countlabels() walks the
whole name just to compare the label count with zero. An empty name
is simply one with zero length, so add dns_name_empty() that checks
the length directly, along with a coccinelle patch that converts the
existing callers.
--- /dev/null
+@@
+constant ZERO =~ "^0[uUlL]*$";
+expression E;
+@@
+
+- dns_name_countlabels(E) > ZERO
++ !dns_name_empty(E)
+
+@@
+constant ZERO =~ "^0[uUlL]*$";
+expression E;
+@@
+
+- dns_name_countlabels(E) == ZERO
++ dns_name_empty(E)
+
+@@
+constant ZERO =~ "^0[uUlL]*$";
+expression E;
+@@
+
+- dns_name_countlabels(E) != ZERO
++ !dns_name_empty(E)
* individual labels in the name
*/
+static inline bool
+dns_name_empty(const dns_name_t *name) {
+ REQUIRE(DNS_NAME_VALID(name));
+
+ return name->length == 0;
+}
+/*%<
+ * Return whether the name is empty.
+ *
+ * Requires:
+ * \li 'name' is a valid name
+ *
+ */
+
static inline uint8_t
dns_name_countlabels(const dns_name_t *name) {
REQUIRE(DNS_NAME_VALID(name));