]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
clean it up to do less work
authorAlan T. DeKok <aland@freeradius.org>
Thu, 11 Oct 2018 18:38:21 +0000 (14:38 -0400)
committerAlan T. DeKok <aland@freeradius.org>
Thu, 11 Oct 2018 18:38:21 +0000 (14:38 -0400)
src/protocols/radius/encode.c

index 36d23961d4cca40247066ce35794194904c355cf..8854e24d007a206f6425dc5b40e6d2ea969769a4 100644 (file)
@@ -474,24 +474,16 @@ static ssize_t encode_struct(uint8_t *out, size_t outlen,
                child_num++;
 
                vp = next_encodable(cursor);
+               fr_proto_tlv_stack_build(tlv_stack, vp ? vp->da : NULL);
 
                /*
-                *      Nothing more to do, we're done.
-                */
-               if (!vp) break;
-
-               /*
-                *      If the next VP isn't from the same parent, then stop.
+                *      Nothing more to do, or we've done all of the
+                *      entries in this structure, stop.
                 */
-               if (vp->da->parent != da) {
-                       break;
-               }
-
-               fr_proto_tlv_stack_build(tlv_stack, vp->da);
-               FR_PROTO_HEX_DUMP("Done STRUCT", out, p - out);
+               if (!vp || (vp->da->parent != da)) break;
        }
 
-       fr_proto_tlv_stack_build(tlv_stack, NULL);
+       FR_PROTO_HEX_DUMP("Done STRUCT", out, p - out);
 
        return p - out;
 }
@@ -622,12 +614,7 @@ static ssize_t encode_value(uint8_t *out, size_t outlen,
         *      This has special requirements.
         */
        if (da->type == FR_TYPE_STRUCT) {
-               len = encode_struct(out, outlen, tlv_stack, depth, cursor);
-               if (len < 0) return len;
-
-               vp = fr_cursor_current(cursor);
-               fr_proto_tlv_stack_build(tlv_stack, vp ? vp->da : NULL);
-               return len;
+               return encode_struct(out, outlen, tlv_stack, depth, cursor);
        }
 
        /*