[Openvpn-devel,19/28] Make buf_write_u8/16/32 take the type they pretend to take

Message ID 20220422142953.3805364-10-arne@rfc2549.org
State Accepted
Headers show
Series Stateless three-way handshake and control channel improvements | expand

Commit Message

Arne Schwabe April 22, 2022, 4:29 a.m. UTC
This functions should accept the type of integer they say to write. Calling
the u32 function with an integer that is actually 32 bit unsigned gives
compiler warnings.
---
 src/openvpn/buffer.h | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)

Comments

Frank Lichtenheld April 24, 2022, 10:57 p.m. UTC | #1
Acked-By: Frank Lichtenheld <frank@lichtenheld.com>

Trivial enough and can be applied independently from the rest of the series.

> Arne Schwabe <arne@rfc2549.org> hat am 22.04.2022 16:29 geschrieben:
> 
>  
> This functions should accept the type of integer they say to write. Calling
> the u32 function with an integer that is actually 32 bit unsigned gives
> compiler warnings.

--
Frank Lichtenheld
Gert Doering April 25, 2022, 2:19 a.m. UTC | #2
Indeed :-) - code looks good, test compiled on Linux and FreeBSD
("does it bring any surprise warnings?")

Your patch has been applied to the master branch.

commit dc6e00e2e75eae58bf94bcf384ae2ba68c5c6bd3
Author: Arne Schwabe
Date:   Fri Apr 22 16:29:44 2022 +0200

     Make buf_write_u8/16/32 take the type they pretend to take

     Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
     Message-Id: <20220422142953.3805364-10-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg24165.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h
index 97cc86241..231f1b0d4 100644
--- a/src/openvpn/buffer.h
+++ b/src/openvpn/buffer.h
@@ -694,23 +694,22 @@  buf_write_prepend(struct buffer *dest, const void *src, int size)
 }
 
 static inline bool
-buf_write_u8(struct buffer *dest, int data)
+buf_write_u8(struct buffer *dest, uint8_t data)
 {
-    uint8_t u8 = (uint8_t) data;
-    return buf_write(dest, &u8, sizeof(uint8_t));
+    return buf_write(dest, &data, sizeof(uint8_t));
 }
 
 static inline bool
-buf_write_u16(struct buffer *dest, int data)
+buf_write_u16(struct buffer *dest, uint16_t data)
 {
-    uint16_t u16 = htons((uint16_t) data);
+    uint16_t u16 = htons(data);
     return buf_write(dest, &u16, sizeof(uint16_t));
 }
 
 static inline bool
-buf_write_u32(struct buffer *dest, int data)
+buf_write_u32(struct buffer *dest, uint32_t data)
 {
-    uint32_t u32 = htonl((uint32_t) data);
+    uint32_t u32 = htonl(data);
     return buf_write(dest, &u32, sizeof(uint32_t));
 }