From: "cron2 (Code Review)" Date: Mon, 30 Mar 2026 14:16:15 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <3f41d80550c1d715c15e55f3f3d68eb1f4ae59d1-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="szL3ZQ58DgU="; charset=UTF-8 Subject: [Openvpn-devel] [S] Change in openvpn[master]: buffer: Avoid sign-compare warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --szL3ZQ58DgU= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#6) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1561?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: buffer: Avoid sign-compare warnings ...................................................................... buffer: Avoid sign-compare warnings - Switch buffer_list size and max_size to size_t - Guard some unavoidable size_t -> int conversions Change-Id: Iecc3e3d5d13cb85c1f287ad4816e1e6a7b2bcdef Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1561 Message-Id: <20260330113648.19896-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg36= 335.html Signed-off-by: Gert Doering --- M src/openvpn/buffer.c M src/openvpn/buffer.h 2 files changed, 10 insertions(+), 18 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/61/1561/6 diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c index 75110ed..71f3769 100644 --- a/src/openvpn/buffer.c +++ b/src/openvpn/buffer.c @@ -53,7 +53,7 @@ void buf_size_error(const size_t size) { - msg(M_FATAL, "fatal buffer size error, size=3D%lu", (unsigned long)siz= e); + msg(M_FATAL, "fatal buffer size error, size=3D%zu", size); } struct buffer @@ -280,11 +280,6 @@ return ret; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wsign-compare" -#endif - /* * write a string to the end of a buffer that was * truncated by buf_printf @@ -295,7 +290,7 @@ if (buf_forward_capacity(buf) <=3D 1) { size_t len =3D strlen(str) + 1; - if (len < buf_forward_capacity_total(buf)) + if (buf_size_valid(len) && (int)len < buf_forward_capacity_total(b= uf)) { memcpy(buf->data + buf->capacity - len, str, len); } @@ -782,7 +777,7 @@ buf_string_match_head_str(const struct buffer *src, const char *match) { const size_t size =3D strlen(match); - if (size > src->len) + if (!buf_size_valid(size) || (int)size > src->len) { return false; } @@ -1196,7 +1191,7 @@ bool buffer_list_defined(const struct buffer_list *ol) { - return ol && ol->head !=3D NULL; + return ol && ol->head !=3D NULL && ol->size > 0; } void @@ -1223,7 +1218,7 @@ struct buffer_entry *e =3D buffer_list_push_data(ol, str, len + 1); if (e) { - e->buf.len =3D (int)len; /* Don't count trailing '\0' as part = of length */ + e->buf.len--; /* Don't count trailing '\0' as part of length */ } } } @@ -1249,6 +1244,7 @@ } e->buf =3D alloc_buf(size); memcpy(e->buf.data, data, size); + /* Note: size implicitly checked by alloc_buf */ e->buf.len =3D (int)size; ol->tail =3D e; } @@ -1274,7 +1270,7 @@ const size_t sep_len =3D strlen(sep); struct buffer_entry *more =3D bl->head; size_t size =3D 0; - int count =3D 0; + size_t count =3D 0; for (; more; ++count) { size_t extra_len =3D BLENZ(&more->buf) + sep_len; @@ -1313,10 +1309,6 @@ } } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - void buffer_list_aggregate(struct buffer_list *bl, const size_t max) { @@ -1326,7 +1318,7 @@ void buffer_list_pop(struct buffer_list *ol) { - if (ol && ol->head) + if (buffer_list_defined(ol)) { struct buffer_entry *e =3D ol->head->next; free_buf(&ol->head->buf); diff --git a/src/openvpn/buffer.h b/src/openvpn/buffer.h index 040f752..fcc923b 100644 --- a/src/openvpn/buffer.h +++ b/src/openvpn/buffer.h @@ -1149,8 +1149,8 @@ { struct buffer_entry *head; /* next item to pop/peek */ struct buffer_entry *tail; /* last item pushed */ - int size; /* current number of entries */ - int max_size; /* maximum size list should grow to */ + size_t size; /* current number of entries */ + size_t max_size; /* maximum size list should grow to */ }; /** -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1561?usp=3Demail To unsubscribe, or for help writing mail filters, visit http://gerrit.openv= pn.net/settings?usp=3Demail Gerrit-MessageType: newpatchset Gerrit-Project: openvpn Gerrit-Branch: master Gerrit-Change-Id: Iecc3e3d5d13cb85c1f287ad4816e1e6a7b2bcdef Gerrit-Change-Number: 1561 Gerrit-PatchSet: 6 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --szL3ZQ58DgU= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

cron2 upl= oaded patch set #6 to the change originally created by flichtenhel= d.

View Change

The following approvals got outdated and were remove= d: Code-Review+2 by cron2

buffer: Avoid sign-compare warnings=


- Switch buffer_list size and max_size to size_t
- Guard some un= avoidable size_t -> int conversions

Change-Id: Iecc3e3d5d13cb85c1= f287ad4816e1e6a7b2bcdef
Signed-off-by: Frank Lichtenheld <frank@...2375...= 41...>
Acked-by: Gert Doering <gert@...1296...>
Gerrit URL: = https://gerrit.openvpn.net/c/openvpn/+/1561
Message-Id: <202603301136= 48.19896-1-gert@...1296...>
URL: https://www.mail-archive.com/openvpn= -devel@lists.sourceforge.net/msg36335.html
Signed-off-by: Gert Doering &= lt;gert@...1296...>
---
M src/openvpn/buffer.c
M src/openvpn/bu= ffer.h
2 files changed, 10 insertions(+), 18 deletions(-)

<= pre class=3D"blocks" style=3D"font-family: monospace,monospace; white-space= : pre-wrap;">git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/6= 1/1561/6
diff --git a/src/openvpn/buffer.c b/src/openvpn/buffer.c
index 75110ed..71f3769 100644
--- a/src/open= vpn/buffer.c
+++ b/src/openvpn/buffer.c
@@ = -53,7 +53,7 @@
void
buf_size_error(const = size_t size)
{
- msg(M_FATAL, "fatal buffer size error, size=3D%lu",= (unsigned long)size);
-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic push
-#pragma GCC diagnostic ignored "-Wsign= -compare"
-#endif<= /span>
-
/*
* write a string to the end of a buffer that was * truncated by buf_printf
@@ -295,7 +290,7 @@
if (buf_forward_capacity(buf) <=3D 1)
= {
size_t len =3D strlen(str) + 1;
- if (len < buf_forward_c= apacity_total(buf))

+= if (buf_size_valid(len) && (int)len < buf_forward_capaci= ty_total(buf))
{
memc= py(buf->data + buf->capacity - len, str, len);
= }
@@ -782,7 +777,7 @@
buf_string_match_= head_str(const struct buffer *src, const char *match)
{
const size_t size =3D strlen(match);
- if (size > src->len)
= + if (!buf_size_valid(size) = || (int)size > src->len)
{
= return false;
}
@@ -1196,7 +1191,7= @@
bool
buffer_list_defined(const struct= buffer_list *ol)
{
- return ol && ol->head !=3D NULL;
+ return ol && ol->= head !=3D NULL && ol->size > 0;

}
=
void
@@ -1223,7 +1218,7 @@<= br> struct buffer_entry *e =3D buffer_list_push_data(ol, str,= len + 1);
if (e)
{
- e->buf.len = =3D (int)len; /* Don't count trailing '\0' as part of length */=
+ e->b= uf.len--; /* Don't count trailing '\0' as part of length */
}
}
}@@ -1249,6 +1244,7 @@
}
= e->buf =3D alloc_buf(size);
memcpy(e->= buf.data, data, size);
- int count = =3D 0;
+ size_t co= unt =3D 0;
for (; more; ++count)
= {
size_t extra_len =3D BLENZ(&more->buf) + = sep_len;
@@ -1313,10 +1309,6 @@
}
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop
-#endif

-
void
buffer_list_= aggregate(struct buffer_list *bl, const size_t max)
{
@@ -1326,7 +1318,7 @@
void
bu= ffer_list_pop(struct buffer_list *ol)
{
- if (ol && ol->head)
+ if (buffer_list_defin= ed(ol))
{
struct buffer_entry= *e =3D ol->head->next;
free_buf(&ol->= ;head->buf);
diff --git a/src/openvpn/buffer.h b/src/ope= nvpn/buffer.h
index 040f752..fcc923b 100644
--- a/src/openvpn/buffer.h

+++ b/src/openvpn/buffer.h
@@ -1149,8 +1149,8 @@
{
s= truct buffer_entry *head; /* next item to pop/peek */
= struct buffer_entry *tail; /* last item pushed */
- int size; /* current numbe= r of entries */
- in= t max_size; /* maximum size list should grow to */
<= span style=3D"color: hsl(120, 100%, 40%);">+ size_t size; = /* current number of entries */

+ size_t max_size; /* maximum size list should grow= to */
};

/**

To view, visit change 1561. To unsubscribe, or for h= elp writing mail filters, visit settings.

Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Iecc3e3d5d13cb85c1f287ad4816= e1e6a7b2bcdef
Gerrit-Change-Number: 1561
Gerrit-PatchSet: 6
Gerrit-Owner: flichtenheld <frank@...2723...= .>
Gerrit-Reviewer: cron2 <gert@...1296...>=
Gerrit-Reviewer: plaisthos <arne-openvpn@...1186...= .1227...>
Gerrit-CC: openvpn-devel <openvpn-devel@...1484...= ts.sourceforge.net>
= --szL3ZQ58DgU=--