]> git.ipfire.org Git - thirdparty/samba.git/commitdiff
smbd: Simplify share_mode_entry_get()
authorVolker Lendecke <vl@samba.org>
Thu, 23 Apr 2020 15:00:25 +0000 (17:00 +0200)
committerRalph Boehme <slow@samba.org>
Tue, 5 May 2020 11:48:39 +0000 (11:48 +0000)
If we don't use a DATA_BLOB, we can more correctly state in the
prototype that the buffer we parse is constant.

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Ralph Boehme <slow@samba.org>
source3/locking/share_mode_lock.c

index ed96541c36d3f06ae85887fbd97a07d421cbd933..87468bd7f3f4d9257f82f47482969838679a3606 100644 (file)
@@ -1438,9 +1438,13 @@ static bool share_mode_entry_put(
 }
 
 static bool share_mode_entry_get(
-       DATA_BLOB blob, struct share_mode_entry *e)
+       const uint8_t ptr[SHARE_MODE_ENTRY_SIZE], struct share_mode_entry *e)
 {
        enum ndr_err_code ndr_err = NDR_ERR_SUCCESS;
+       DATA_BLOB blob = {
+               .data = discard_const_p(uint8_t, ptr),
+               .length = SHARE_MODE_ENTRY_SIZE,
+       };
 
        ndr_err = ndr_pull_struct_blob_all_noalloc(
                &blob, e, (ndr_pull_flags_fn_t)ndr_pull_share_mode_entry);
@@ -1470,27 +1474,20 @@ static size_t share_mode_entry_find(
        right = (num_share_modes-1);
 
        while (left <= right) {
-               DATA_BLOB blob;
+               const uint8_t *middle_ptr = NULL;
                int cmp;
                bool ok;
 
                middle = left + ((right - left) / 2);
+               middle_ptr = data + middle * SHARE_MODE_ENTRY_SIZE;
 
-               DBG_DEBUG("left=%zu, right=%zu, middle=%zu\n",
+               DBG_DEBUG("left=%zu, right=%zu, middle=%zu, middle_ptr=%p\n",
                          left,
                          right,
-                         middle);
-
-               blob = (DATA_BLOB) {
-                       .data = data + middle * SHARE_MODE_ENTRY_SIZE,
-                       .length = SHARE_MODE_ENTRY_SIZE,
-               };
-
-               DBG_DEBUG("blob.data=%p, blob.length=%zu\n",
-                         blob.data,
-                         blob.length);
+                         middle,
+                         middle_ptr);
 
-               ok = share_mode_entry_get(blob, e);
+               ok = share_mode_entry_get(middle_ptr, e);
                if (!ok) {
                        DBG_DEBUG("share_mode_entry_get failed\n");
                        return false;