]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
dsdb: Simplify samdb_dn_to_dns_domain() with talloc_asprintf_addbuf()
authorVolker Lendecke <vl@samba.org>
Tue, 24 Feb 2026 10:54:30 +0000 (11:54 +0100)
committerVolker Lendecke <vl@samba.org>
Wed, 25 Feb 2026 12:33:39 +0000 (12:33 +0000)
Only check for NULL once

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Martin Schwenke <martin@meltin.net>
source4/dsdb/common/util.c

index 9e50982f97a8caf04c82e3da1be5f15d4fb44bb7..18a4a3eba3d6e30ddef487301080e7d463c4bda1 100644 (file)
@@ -3240,24 +3240,22 @@ char *samdb_dn_to_dns_domain(TALLOC_CTX *mem_ctx, struct ldb_dn *dn)
 {
        int i, num_components = ldb_dn_get_comp_num(dn);
        char *dns_name = talloc_strdup(mem_ctx, "");
-       if (dns_name == NULL) {
-               return NULL;
-       }
 
        for (i=0; i<num_components; i++) {
                const struct ldb_val *v = ldb_dn_get_component_val(dn, i);
-               char *s;
                if (v == NULL) {
                        talloc_free(dns_name);
                        return NULL;
                }
-               s = talloc_asprintf_append_buffer(dns_name, "%*.*s.",
-                                                 (int)v->length, (int)v->length, (char *)v->data);
-               if (s == NULL) {
-                       talloc_free(dns_name);
-                       return NULL;
-               }
-               dns_name = s;
+               talloc_asprintf_addbuf(&dns_name,
+                                      "%*.*s.",
+                                      (int)v->length,
+                                      (int)v->length,
+                                      (char *)v->data);
+       }
+
+       if (dns_name == NULL) {
+               return NULL;
        }
 
        /* remove the last '.' */