Attention is currently required from: plaisthos.

Hello plaisthos,

I'd like you to do a code review.
Please visit

    http://gerrit.openvpn.net/c/openvpn/+/1740?usp=email

to review the following change.


Change subject: buffer: Add buf_read_u64() and buf_write_u64()
......................................................................

buffer: Add buf_read_u64() and buf_write_u64()

Add 64-bit big-endian buffer accessors alongside the existing 8/16/32-bit
helpers. There is no portable 64-bit byte-order primitive, so the value is
handled as two big-endian 32-bit halves (most significant first).

buf_read_u64() reports success via a bool out-parameter, mirroring
buf_read_u32(): every 64-bit value is a legal result, leaving no room for
an in-band sentinel.

Change-Id: Ic677f43fc3eb0052f8e80d9a7f098d34ad03dfe1
Signed-off-by: Lev Stipakov <[email protected]>
---
M src/openvpn/buffer.h
1 file changed, 28 insertions(+), 0 deletions(-)



  git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/40/1740/1

diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index fcc923b..5748430 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -701,6 +701,15 @@
     return buf_write(dest, &u32, sizeof(uint32_t));
 }

+/* There is no portable 64-bit byte-order helper, so write the value as two
+ * big-endian 32-bit halves (most significant first). */
+static inline bool
+buf_write_u64(struct buffer *dest, uint64_t data)
+{
+    return buf_write_u32(dest, (uint32_t)(data >> 32))
+           && buf_write_u32(dest, (uint32_t)(data & 0xffffffff));
+}
+
 static inline bool
 buf_copy(struct buffer *dest, const struct buffer *src)
 {
@@ -827,6 +836,25 @@
     }
 }

+/* Read a 64-bit value written as two big-endian 32-bit halves (see
+ * buf_write_u64()). Sets *good to indicate success, like buf_read_u32(). */
+static inline uint64_t
+buf_read_u64(struct buffer *buf, bool *good)
+{
+    bool ok = true;
+    uint32_t high = buf_read_u32(buf, &ok);
+    uint32_t low = ok ? buf_read_u32(buf, &ok) : 0;
+    if (good)
+    {
+        *good = ok;
+    }
+    if (!ok)
+    {
+        return 0;
+    }
+    return ((uint64_t)high << 32) | low;
+}
+
 /** Return true if buffer contents are equal */
 static inline bool
 buf_equal(const struct buffer *a, const struct buffer *b)

--
To view, visit http://gerrit.openvpn.net/c/openvpn/+/1740?usp=email
To unsubscribe, or for help writing mail filters, visit 
http://gerrit.openvpn.net/settings?usp=email

Gerrit-MessageType: newchange
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ic677f43fc3eb0052f8e80d9a7f098d34ad03dfe1
Gerrit-Change-Number: 1740
Gerrit-PatchSet: 1
Gerrit-Owner: stipa <[email protected]>
Gerrit-Reviewer: plaisthos <[email protected]>
Gerrit-CC: openvpn-devel <[email protected]>
Gerrit-Attention: plaisthos <[email protected]>
_______________________________________________
Openvpn-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openvpn-devel

Reply via email to