From: "cron2 (Code Review)" Date: Sun, 16 Nov 2025 17:45:18 +0000 In-Reply-To: References: Reply-To: gert@...1296..., arne-openvpn@...1227..., openvpn-devel@lists.sourceforge.net, frank@...2641... Message-ID: <2c8ef8cf806f645141dc4b4d30f4a7dda2f1c021-EmailReplacePatchSet-HTML@...2715...> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Disposition: inline Content-Type: multipart/alternative; boundary="DbUs7wmk3Q4="; charset=UTF-8 Subject: [Openvpn-devel] [M] Change in openvpn[master]: otime: Fix various conversion warnings List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: flichtenheld , plaisthos Cc: openvpn-devel --DbUs7wmk3Q4= Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable cron2 has uploaded a new patch set (#9) to the change originally created by= flichtenheld. ( http://gerrit.openvpn.net/c/openvpn/+/1274?usp=3Demail ) The following approvals got outdated and were removed: Code-Review+2 by cron2 Change subject: otime: Fix various conversion warnings ...................................................................... otime: Fix various conversion warnings Generally just use better types. Use typedef to handle the Win32 situation where tv_sec is long which is smaller than time_t (which is long long). Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9e Signed-off-by: Frank Lichtenheld Acked-by: Gert Doering Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274 Message-Id: <20251116135757.15805-1-gert@...1296...> URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg34= 462.html Signed-off-by: Gert Doering --- M src/openvpn/otime.c M src/openvpn/otime.h 2 files changed, 26 insertions(+), 39 deletions(-) git pull ssh://gerrit.openvpn.net:29418/openvpn refs/changes/74/1274/9 diff --git a/src/openvpn/otime.c b/src/openvpn/otime.c index d9bf157..1b3b096 100644 --- a/src/openvpn/otime.c +++ b/src/openvpn/otime.c @@ -95,50 +95,37 @@ const char * tv_string_abs(const struct timeval *tv, struct gc_arena *gc) { - return time_string((time_t)tv->tv_sec, (long)tv->tv_usec, true, gc); + return time_string(tv->tv_sec, tv->tv_usec, true, gc); } /* format a time_t as ascii, or use current time if 0 */ -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - const char * -time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc) +time_string(time_t t, tv_usec_t usec, bool show_usec, struct gc_arena *gc) { struct buffer out =3D alloc_buf_gc(64, gc); struct timeval tv; - if (t) - { - tv.tv_sec =3D t; - tv.tv_usec =3D usec; - } - else + if (!t) { gettimeofday(&tv, NULL); + t =3D tv.tv_sec; + usec =3D tv.tv_usec; } - t =3D tv.tv_sec; struct tm *tm =3D localtime(&t); buf_printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year + 1900, = tm->tm_mon + 1, tm->tm_mday, tm->tm_hour, tm->tm_min, tm->tm_sec); - if (show_usec && tv.tv_usec) + if (show_usec && usec) { - buf_printf(&out, " us=3D%ld", (long)tv.tv_usec); + buf_printf(&out, " us=3D%ld", (long)usec); } return BSTR(&out); } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - /* * Limit the frequency of an event stream. * diff --git a/src/openvpn/otime.h b/src/openvpn/otime.h index 108d0f2..60533fd 100644 --- a/src/openvpn/otime.h +++ b/src/openvpn/otime.h @@ -27,6 +27,14 @@ #include "integer.h" #include "buffer.h" +#ifdef _WIN32 +typedef long tv_sec_t; +typedef long tv_usec_t; +#else +typedef time_t tv_sec_t; +typedef suseconds_t tv_usec_t; +#endif + struct frequency_limit { int max; @@ -42,7 +50,7 @@ bool frequency_limit_event_allowed(struct frequency_limit *f); /* format a time_t as ascii, or use current time if 0 */ -const char *time_string(time_t t, long usec, bool show_usec, struct gc_are= na *gc); +const char *time_string(time_t t, tv_usec_t usec, bool show_usec, struct g= c_arena *gc); /* struct timeval functions */ =20 @@ -59,11 +67,6 @@ extern time_t now_usec; void update_now_usec(struct timeval *tv); -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic push -#pragma GCC diagnostic ignored "-Wconversion" -#endif - static inline int openvpn_gettimeofday(struct timeval *tv, void *tz) { @@ -71,8 +74,8 @@ if (!status) { update_now_usec(tv); - tv->tv_sec =3D now; - tv->tv_usec =3D now_usec; + tv->tv_sec =3D (tv_sec_t)now; + tv->tv_usec =3D (tv_usec_t)now_usec; } return status; } @@ -116,20 +119,21 @@ /* return tv1 - tv2 in usec, constrained by max_seconds */ static inline int -tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const un= signed int max_seconds) +tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const in= t max_seconds) { const int max_usec =3D max_seconds * 1000000; - const int sec_diff =3D tv1->tv_sec - tv2->tv_sec; + const tv_sec_t sec_diff =3D tv1->tv_sec - tv2->tv_sec; - if (sec_diff > ((int)max_seconds + 10)) + if (sec_diff > (max_seconds + 10)) { return max_usec; } - else if (sec_diff < -((int)max_seconds + 10)) + else if (sec_diff < -(max_seconds + 10)) { return -max_usec; } - return constrain_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec= ), -max_usec, max_usec); + const time_t complete_diff =3D sec_diff * 1000000 + (tv1->tv_usec - tv= 2->tv_usec); + return constrain_int((int)complete_diff, -max_usec, max_usec); } static inline void @@ -223,8 +227,8 @@ static inline void tv_delta(struct timeval *dest, const struct timeval *t1, const struct time= val *t2) { - int sec =3D t2->tv_sec - t1->tv_sec; - int usec =3D t2->tv_usec - t1->tv_usec; + tv_sec_t sec =3D t2->tv_sec - t1->tv_sec; + tv_usec_t usec =3D t2->tv_usec - t1->tv_usec; while (usec < 0) { @@ -241,10 +245,6 @@ dest->tv_usec =3D usec; } -#if defined(__GNUC__) || defined(__clang__) -#pragma GCC diagnostic pop -#endif - #define TV_WITHIN_SIGMA_MAX_SEC 600 #define TV_WITHIN_SIGMA_MAX_USEC (TV_WITHIN_SIGMA_MAX_SEC * 1000000) -- To view, visit http://gerrit.openvpn.net/c/openvpn/+/1274?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: Ie22f4902162b7004542f030c734b968de71e0e9e Gerrit-Change-Number: 1274 Gerrit-PatchSet: 9 Gerrit-Owner: flichtenheld Gerrit-Reviewer: cron2 Gerrit-Reviewer: plaisthos Gerrit-CC: openvpn-devel --DbUs7wmk3Q4= Content-Type: text/html; charset="UTF-8" Content-Transfer-Encoding: quoted-printable

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

View Change

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

otime: Fix various conversion warni=
ngs

Generally just use better types. Use typedef
to handle the Wi= n32 situation where tv_sec
is long which is smaller than time_t (whichis long long).

Change-Id: Ie22f4902162b7004542f030c734b968de71e0e9= e
Signed-off-by: Frank Lichtenheld <frank@...2641...>
Acked-by:= Gert Doering <gert@...1296...>
Gerrit URL: https://gerrit.openvpn= .net/c/openvpn/+/1274
Message-Id: <20251116135757.15805-1-gert@...1826...= 6...>
URL: https://www.mail-archive.com/openvpn-devel@...1768...= ge.net/msg34462.html
Signed-off-by: Gert Doering <gert@...1296...>=
---
M src/openvpn/otime.c
M src/openvpn/otime.h
2 files change= d, 26 insertions(+), 39 deletions(-)

git pull ss=
h://gerrit.openvpn.net:29418/openvpn refs/changes/74/1274/9
diff --=
git a/src/openvpn/otime.c b/src/openvpn/otime.c
index d9bf1= 57..1b3b096 100644
--- a/src/openvpn/otime.c
+++ b/src/openvpn/otime.c
@@ -95,50 +95,37 @@
<= span> const char *
tv_string_abs(const struct timeval *tv,= struct gc_arena *gc)
{
- return time_string((time_t)tv->tv_sec, (long)tv-&= gt;tv_usec, true, gc);
-#if defined(__GNUC__) || defined(__clang__)=
-#pragma GCC diagnostic push<= /span>
-#pragma GCC diagnostic= ignored "-Wconversion"
-#endif
-
const char *
-time_string(time_t t, long usec, bool show_usec, struct gc_arena *gc)=
+time_string(time_t = t, tv_usec_t usec, bool show_usec, struct gc_arena *gc)
{<= /span>
struct buffer out =3D alloc_buf_gc(64, gc);
= struct timeval tv;

- if (t)
- {
- = tv.tv_sec =3D t;
- tv.tv_usec =3D usec;
- }
- els= e
+ if (!t)=
{
gettimeofday(&tv, NULL);

+ t =3D tv.tv_sec;=
+ usec =3D tv= .tv_usec;
}

- t =3D tv.tv_sec;
stru= ct tm *tm =3D localtime(&t);

buf= _printf(&out, "%04d-%02d-%02d %02d:%02d:%02d", tm->tm_year= + 1900, tm->tm_mon + 1,
tm->tm_mday,= tm->tm_hour, tm->tm_min, tm->tm_sec);
- if (show_usec && tv= .tv_usec)
+ if (sh= ow_usec && usec)
{
- buf_printf(&out, " us=3D%ld"= ;, (long)tv.tv_usec);
+ buf_printf(&out, " us=3D%ld", (long)usec); }

return BSTR(&out)= ;
}

-#if defined(__GNUC__) || defined(__clang__)
-#pragma GCC diagnostic pop-#endif
-
/*
* Limit= the frequency of an event stream.
*
diff= --git a/src/openvpn/otime.h b/src/openvpn/otime.h
index 10= 8d0f2..60533fd 100644
--- a/src/openvpn/otime.h
<= span>+++ b/src/openvpn/otime.h
@@ -27,6 +27,14 @@ #include "integer.h"
#include "buff= er.h"

+#ifdef _WIN32
+typedef long tv_usec_t;
+#else
+type= def time_t tv_sec_t;
= +typedef suseconds_t tv_usec_t;
+#endif
+<= /span>
struct frequency_limit
{
= int max;
@@ -42,7 +50,7 @@
bool frequ= ency_limit_event_allowed(struct frequency_limit *f);

/* format a time_t as ascii, or use current time if 0 */
-const char *time_string(tim= e_t t, long usec, bool show_usec, struct gc_arena *gc);
+const char *time_string(time_t t, tv_us= ec_t usec, bool show_usec, struct gc_arena *gc);
/* struct timeval functions */

@= @ -59,11 +67,6 @@
extern time_t now_usec;
= void update_now_usec(struct timeval *tv);

-#if defined(__GNUC__) || defined(__c= lang__)

-#pragma GCC di= agnostic push
-#pragma = GCC diagnostic ignored "-Wconversion"
-#endif
-
static inline int
openvpn_get= timeofday(struct timeval *tv, void *tz)
{
= @@ -71,8 +74,8 @@
if (!status)
{<= /span>
update_now_usec(tv);
- tv->tv_sec =3D now;
- tv->tv_usec =3D now_usec;
+ tv->tv_sec =3D= (tv_sec_t)now;
+ = tv->tv_usec =3D (tv_usec_t)now_usec;
} return status;
}
@@ -116,20 += 119,21 @@

/* return tv1 - tv2 in usec, c= onstrained by max_seconds */
static inline int
<= span style=3D"color: hsl(0, 100%, 40%);">-tv_subtract(const struct timeval = *tv1, const struct timeval *tv2, const unsigned int max_seconds)

= +tv_subtract(const struct timev= al *tv1, const struct timeval *tv2, const int max_seconds)
= {
const int max_usec =3D max_seconds * 1000000;
- const int sec_diff =3D = tv1->tv_sec - tv2->tv_sec;
+ const tv_sec_t sec_diff =3D tv1->tv_sec - tv2->tv_se= c;

- = if (sec_diff > ((int)max_seconds + 10))
+ if (sec_diff > (max_seconds + 10))<= br> {
return max_usec;
= }
- else if (sec= _diff < -((int)max_seconds + 10))
+ else if (sec_diff < -(max_seconds + 10))
= {
return -max_usec;
= }
- return constra= in_int(sec_diff * 1000000 + (tv1->tv_usec - tv2->tv_usec), -max_usec,= max_usec);
+ cons= t time_t complete_diff =3D sec_diff * 1000000 + (tv1->tv_usec - tv2->= tv_usec);
+ return= constrain_int((int)complete_diff, -max_usec, max_usec);
}=

static inline void
@@ -= 223,8 +227,8 @@
static inline void
tv_del= ta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2= )
{
- = int sec =3D t2->tv_sec - t1->tv_sec;
- int usec =3D t2->tv_usec - t1->tv_usec;
+ tv_sec_t sec =3D = t2->tv_sec - t1->tv_sec;
+ tv_usec_t usec =3D t2->tv_usec - t1->tv_usec;
while (usec < 0)
{
@@ -241,10 +245,6 @@
dest->tv_usec = =3D usec;
}

-#if defined(__GNUC__) || defined(__clang__)=
-#pragma GCC diagnostic pop
-#endif
-
#define TV_WITHIN_SI= GMA_MAX_SEC 600
#define TV_WITHIN_SIGMA_MAX_USEC (TV_WITH= IN_SIGMA_MAX_SEC * 1000000)


To view, visit change 1274. To unsubscribe, or for help writing mail fil= ters, visit sett= ings.

<= link itemprop=3D"url" href=3D"http://gerrit.openvpn.net/c/openvpn/+/1274?us= p=3Demail"/>
Gerrit-MessageType: newpatchset
Gerrit-Project: openvpn
Gerrit-Branch: master
Gerrit-Change-Id: Ie22f4902162b7004542f030c734= b968de71e0e9e
Gerrit-Change-Number: 1274
Gerrit-PatchSet: 9
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>
= --DbUs7wmk3Q4=--