]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
Fix calculation of padding in the enc/dec routines
authorDavid Howells <dhowells@redhat.com>
Fri, 3 Mar 2017 15:00:34 +0000 (15:00 +0000)
committerDavid Howells <dhowells@redhat.com>
Fri, 3 Mar 2017 15:00:34 +0000 (15:00 +0000)
Fix calculation of that amount of padding around a blob or string in the
encoding and decoding routines.

Signed-off-by: David Howells <dhowells@redhat.com>
kafs/py_rxgen.c

index b3c903904b696f807d539962fa2580372c267c39..27ed55338ebfcc70176a2b0b226f8b254cf7f883 100644 (file)
@@ -18,6 +18,8 @@
 
 #define debug(fmt, ...) do { if (0) printf(fmt, ## __VA_ARGS__); } while (0)
 
+#define calc_pad_to_4(n) ((4 - (n)) & 3)
+
 struct py_dec_index {
        Py_ssize_t val;
        void *ptr;
@@ -833,7 +835,7 @@ int py_enc_buffer(struct rx_call *call, Py_buffer *view, Py_ssize_t dim)
                return -1;
 
        if (view->len & 3)
-               rxrpc_enc_blob(call, &zero, 4 - (view->len & 3));
+               rxrpc_enc_blob(call, &zero, calc_pad_to_4(view->len));
        return rxrpc_post_enc(call);
 }
 
@@ -1025,7 +1027,7 @@ int py_dec_into_buffer(struct rx_call *call)
        if (ret == 0 && call->padding_size > 0) {
                /* Soak up the padding to a 32-bit boundary */
                call->blob = &rxgen_dec_padding_sink;
-               call->blob_size = 4 - (call->blob_size & 3);
+               call->blob_size = calc_pad_to_4(call->blob_size);
                call->blob_offset = 0;
                return 1;
        }
@@ -1059,7 +1061,7 @@ int py_dec_init_buffer(struct rx_call *call, Py_buffer *view, bool padded)
                return 0;
        }
 
-       call->padding_size = padded ? 4 - (view->len & 3) : 0;
+       call->padding_size = padded ? calc_pad_to_4(view->len) : 0;
 
        size = sizeof(struct py_dec_manager);
        size += view->ndim * sizeof(struct py_dec_index);
@@ -1202,7 +1204,7 @@ int py_dec_init_string(struct rx_call *call, PyObject **_str)
 
        call->blob = str;
        call->blob_offset = 0;
-       call->padding_size = 4 - (call->blob_size & 3);
+       call->padding_size = calc_pad_to_4(call->blob_size);
        return 1;
 }