From: Alan T. DeKok Date: Mon, 10 Jul 2023 18:16:10 +0000 (-0400) Subject: simplify and canonicalize encode_child() X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dfa54d2fb0b02846ff07da2127eda9f2df62a682;p=thirdparty%2Ffreeradius-server.git simplify and canonicalize encode_child() --- diff --git a/src/protocols/dhcpv4/encode.c b/src/protocols/dhcpv4/encode.c index e8138f218e2..64ed9948f2a 100644 --- a/src/protocols/dhcpv4/encode.c +++ b/src/protocols/dhcpv4/encode.c @@ -413,34 +413,22 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_VSA: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; return encode_vsio(dbuff, da_stack, depth, cursor, encode_ctx); default: - break; + return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - - return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - if (!da_stack->da[depth]) { - switch (vp->da->type) { - case FR_TYPE_STRUCTURAL: - break; - - default: - fr_strerror_printf("%s: Internal sanity check failed", __FUNCTION__); - return -1; - } - } + fr_assert(fr_type_is_structural(vp->da->type)); -do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff); diff --git a/src/protocols/dhcpv6/encode.c b/src/protocols/dhcpv6/encode.c index ac0e4da9066..060aaab926f 100644 --- a/src/protocols/dhcpv6/encode.c +++ b/src/protocols/dhcpv6/encode.c @@ -389,38 +389,26 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_VSA: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; return encode_vsio(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_GROUP: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; FALL_THROUGH; default: - break; + return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - - return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - if (!da_stack->da[depth]) { - switch (vp->da->type) { - case FR_TYPE_STRUCTURAL: - break; - - default: - fr_strerror_printf("%s: Internal sanity check failed", __FUNCTION__); - return -1; - } - } + fr_assert(fr_type_is_structural(vp->da->type)); -do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff); diff --git a/src/protocols/dns/encode.c b/src/protocols/dns/encode.c index 3e479e64a85..664e767235c 100644 --- a/src/protocols/dns/encode.c +++ b/src/protocols/dns/encode.c @@ -243,33 +243,21 @@ static ssize_t encode_child(fr_dbuff_t *dbuff, */ switch (da_stack->da[depth]->type) { case FR_TYPE_TLV: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; return encode_tlv(dbuff, da_stack, depth, cursor, encode_ctx); case FR_TYPE_GROUP: - if (!da_stack->da[depth + 1]) goto do_nested_children; + if (!da_stack->da[depth + 1]) break; FALL_THROUGH; default: - break; + return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - - return encode_rfc(dbuff, da_stack, depth, cursor, encode_ctx); } - if (!da_stack->da[depth]) { - switch (vp->da->type) { - case FR_TYPE_STRUCTURAL: - break; - - default: - fr_strerror_printf("%s: Internal sanity check failed", __FUNCTION__); - return -1; - } - } + fr_assert(fr_type_is_structural(vp->da->type)); -do_nested_children: fr_pair_dcursor_init(&child_cursor, &vp->vp_group); work_dbuff = FR_DBUFF(dbuff);