]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
lib: Simplify tdb_fetch_int32()
authorVolker Lendecke <vl@samba.org>
Mon, 12 Apr 2021 08:37:11 +0000 (08:37 +0000)
committerJeremy Allison <jra@samba.org>
Mon, 19 Apr 2021 18:18:31 +0000 (18:18 +0000)
With tdb_parse_record we don't need malloc/SAFE_FREE.

The semantics are a bit different from tdb_parse_uint32: We just return
-1 on error, but this could be overloaded with a valid -1 record value.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Jeremy Allison <jra@samba.org>
lib/util/util_tdb.c

index 66caaa5af609d77d2981483271a8a132df547dc1..70eeceff391c3e152ac4a789b59abac21f815c46 100644 (file)
@@ -132,20 +132,19 @@ void tdb_read_unlock_bystring(struct tdb_context *tdb, const char *keyval)
  Output is int32_t in native byte order.
 ****************************************************************************/
 
-static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key)
+static int fetch_int32_parser(TDB_DATA key, TDB_DATA data, void *private_data)
 {
-       TDB_DATA data;
-       int32_t ret;
-
-       data = tdb_fetch(tdb, key);
-       if (!data.dptr || data.dsize != sizeof(int32_t)) {
-               SAFE_FREE(data.dptr);
-               return -1;
+       if (data.dsize == sizeof(int32_t)) {
+               *((int32_t *)private_data) = PULL_LE_I32(data.dptr, 0);
        }
+       return 0;
+}
 
-       ret = IVAL(data.dptr,0);
-       SAFE_FREE(data.dptr);
-       return ret;
+static int32_t tdb_fetch_int32_byblob(struct tdb_context *tdb, TDB_DATA key)
+{
+       int v = -1;
+       tdb_parse_record(tdb, key, fetch_int32_parser, &v);
+       return v;
 }
 
 /****************************************************************************