]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
simplify and canonicalize encode_child()
authorAlan T. DeKok <aland@freeradius.org>
Mon, 10 Jul 2023 18:16:10 +0000 (14:16 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Mon, 10 Jul 2023 19:55:08 +0000 (15:55 -0400)
src/protocols/dhcpv4/encode.c
src/protocols/dhcpv6/encode.c
src/protocols/dns/encode.c

index e8138f218e268871863062a3b138da2039fe3d10..64ed9948f2a8feece90fab5a1efd4fa7d7a6b04f 100644 (file)
@@ -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);
 
index ac0e4da9066cff306aff6fd81fc3e1cbe9a03e3a..060aaab926f9cdb3f2f73cb914e3b7827b9eeaeb 100644 (file)
@@ -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);
 
index 3e479e64a85d75e1cd09f5d8ac87a843d7e25043..664e767235cc433789705a5e31abd08ca75483a6 100644 (file)
@@ -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);