r25215: replace talloc_append_string() with talloc_strdup_append_buffer()
authorStefan Metzmacher <metze@samba.org>
Tue, 18 Sep 2007 13:41:50 +0000 (13:41 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 20:06:55 +0000 (15:06 -0500)
metze

source/lib/ldb/common/ldb_dn.c
source/lib/ldb/ldb_tdb/ldb_tdb.c

index 41e70cffd15ee74d7f117ef83d525786d7daadf6..f0bd72e0098dfa3eb8a261b45d5bb4ea9a679b5e 100644 (file)
@@ -1279,6 +1279,7 @@ static char *ldb_dn_canonical(void *mem_ctx, struct ldb_dn *dn, int ex_format) {
        int i;
        TALLOC_CTX *tmpctx;
        char *cracked = NULL;
+       const char *format = (ex_format ? "\n" : "/" );
  
        if ( ! ldb_dn_validate(dn)) {
                return NULL;
@@ -1305,32 +1306,23 @@ static char *ldb_dn_canonical(void *mem_ctx, struct ldb_dn *dn, int ex_format) {
 
        /* Only domain components?  Finish here */
        if (i < 0) {
-               if (ex_format) {
-                       cracked = talloc_append_string(tmpctx, cracked, "\n");
-               } else {
-                       cracked = talloc_append_string(tmpctx, cracked, "/");
-               }
+               cracked = talloc_strdup_append_buffer(cracked, format);
                talloc_steal(mem_ctx, cracked);
                goto done;
        }
 
        /* Now walk backwards appending remaining components */
        for (; i > 0; i--) {
-               cracked = talloc_asprintf_append(cracked, "/%s", 
-                                         ldb_dn_escape_value(tmpctx, dn->components[i].value));
+               cracked = talloc_asprintf_append_buffer(cracked, "/%s", 
+                                                       ldb_dn_escape_value(tmpctx, dn->components[i].value));
                if (!cracked) {
                        goto done;
                }
        }
 
        /* Last one, possibly a newline for the 'ex' format */
-       if (ex_format) {
-               cracked = talloc_asprintf_append(cracked, "\n%s",
-                                         ldb_dn_escape_value(tmpctx, dn->components[i].value));
-       } else {
-               cracked = talloc_asprintf_append(cracked, "/%s", 
-                                         ldb_dn_escape_value(tmpctx, dn->components[i].value));
-       }
+       cracked = talloc_asprintf_append_buffer(cracked, "%s%s", format,
+                                               ldb_dn_escape_value(tmpctx, dn->components[i].value));
 
        talloc_steal(mem_ctx, cracked);
 done:
index 21661b1d46d066514ffbb77736cfb19ed16c5b28..3461f98d5f3f46d44dd5eda73b47a3baa20d37d9 100644 (file)
@@ -145,7 +145,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, struct ldb_dn *dn)
                goto failed;
        }
 
-       key_str = talloc_append_string(ldb, key_str, dn_folded);
+       key_str = talloc_strdup_append_buffer(key_str, dn_folded);
        if (!key_str) {
                goto failed;
        }