Skip to content

Commit cb4d542

Browse files
flichtenheldcron2
authored andcommitted
buffer: Change buf_prepend and buf_advance to accept ssize_t for length
We already have tests to make sure the value is sane. Changing the argument to ssize_t allows to use it in more places without needing to do a cast before the checks. Change-Id: I123002255b37160d48ef6481f68a89d03073236b Signed-off-by: Frank Lichtenheld <[email protected]> Acked-by: Gert Doering <[email protected]> Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1437 Message-Id: <[email protected]> URL: https://www.mail-archive.com/[email protected]/msg35099.html Signed-off-by: Gert Doering <[email protected]>
1 parent a4b51e6 commit cb4d542

File tree

3 files changed

+10
-10
lines changed

3 files changed

+10
-10
lines changed

src/openvpn/buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -789,7 +789,7 @@ buf_string_compare_advance(struct buffer *src, const char *match)
789789
{
790790
if (buf_string_match_head_str(src, match))
791791
{
792-
buf_advance(src, (int)strlen(match));
792+
buf_advance(src, strlen(match));
793793
return true;
794794
}
795795
else
@@ -1312,7 +1312,7 @@ buffer_list_pop(struct buffer_list *ol)
13121312
}
13131313

13141314
void
1315-
buffer_list_advance(struct buffer_list *ol, int n)
1315+
buffer_list_advance(struct buffer_list *ol, ssize_t n)
13161316
{
13171317
if (ol->head)
13181318
{

src/openvpn/buffer.h

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -601,26 +601,26 @@ buf_inc_len(struct buffer *buf, int inc)
601601
*/
602602

603603
static inline uint8_t *
604-
buf_prepend(struct buffer *buf, int size)
604+
buf_prepend(struct buffer *buf, ssize_t size)
605605
{
606606
if (!buf_valid(buf) || size < 0 || size > buf->offset)
607607
{
608608
return NULL;
609609
}
610-
buf->offset -= size;
611-
buf->len += size;
610+
buf->offset -= (int)size;
611+
buf->len += (int)size;
612612
return BPTR(buf);
613613
}
614614

615615
static inline bool
616-
buf_advance(struct buffer *buf, int size)
616+
buf_advance(struct buffer *buf, ssize_t size)
617617
{
618618
if (!buf_valid(buf) || size < 0 || buf->len < size)
619619
{
620620
return false;
621621
}
622-
buf->offset += size;
623-
buf->len -= size;
622+
buf->offset += (int)size;
623+
buf->len -= (int)size;
624624
return true;
625625
}
626626

@@ -1187,7 +1187,7 @@ struct buffer_entry *buffer_list_push_data(struct buffer_list *ol, const void *d
11871187
*/
11881188
struct buffer *buffer_list_peek(struct buffer_list *ol);
11891189

1190-
void buffer_list_advance(struct buffer_list *ol, int n);
1190+
void buffer_list_advance(struct buffer_list *ol, ssize_t n);
11911191

11921192
void buffer_list_pop(struct buffer_list *ol);
11931193

src/openvpn/ps.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -596,7 +596,7 @@ proxy_connection_io_send(struct proxy_connection *pc, int *bytes_sent)
596596
{
597597
dmsg(D_PS_PROXY_DEBUG, "PORT SHARE PROXY: partial write[%d], tried=%d got=%zd", (int)sd,
598598
pc->buf.len, status);
599-
buf_advance(&pc->buf, (int)status);
599+
buf_advance(&pc->buf, status);
600600
return IOSTAT_EAGAIN_ON_WRITE;
601601
}
602602
else

0 commit comments

Comments
 (0)