From patchwork Sun Nov 16 13:57:52 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 4604 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:6d04:b0:7b1:439f:bdf with SMTP id e4csp2684316may; Sun, 16 Nov 2025 05:58:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCV/+MfzxubtKxtKtZY5DVYyx6TjbzGQz9q7VuRZFghkTZCdkH/B8YWI+A9/icShOf0YrfwryDFUv8I=@openvpn.net X-Google-Smtp-Source: AGHT+IFyKgoLy3EKhCt3NdUg84PkzXY9f4gnbby5+eW58LaL/dRl8fKiN7obAWu+SCiZi73ce3R7 X-Received: by 2002:a05:6830:418c:b0:7b7:59c5:766c with SMTP id 46e09a7af769-7c74458f11bmr6448322a34.33.1763301496664; Sun, 16 Nov 2025 05:58:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1763301496; cv=none; d=google.com; s=arc-20240605; b=jAIvyEpvwdppjpNdx4triyDhYNhg3rRcrTneyOm7FBttXZeNdwM4U4ttF10mPwXfdb g6OSw3aJaL2yHkUK2yjmbIZkAVoTqK4CRvedlF314BXCiRM1eK8iz3OgVnzM7wejb0eq 6McoUACv6ZdeO6IvVxpNRPyetcAIXblTF9pMPVXVQLzT7L1diESyMUeFBPN5G1+NT/zX K7bxnAAkuI+GPMOZ9an5cnaLXRcfccX2ufMsmyJ2/jTgyBNdlal+Rom4/RO0Oj0p+MUn /R7pp4Z8eGMMxdHfkHwcbfbeLKalSKMqcDBG7Fp/dl6tRrR3aeOZ7/WItqt6hFCpEo1t X/eQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature:dkim-signature:dkim-signature; bh=hvLz0YgfBKK6vXWOuH3q8su/W1+7j9u+XKCgcz317rM=; fh=4NbAC/LsuMLI0S0hprUlLSLCiHwg6SCAifhH718Jh0Q=; b=DXQU7edJ/b6sFgcQJIRCCOi/qSlbd7f0wdFCrGtEW6oL/IskfsMQ1Zg7ubsA1ZhFjN OdA2o0t2w82/SG+wuuaqLbUi8f9r0NN6X2vFTTTWawgg6ZcQmzXZSry1W7Tg19RaH+tp qktFvIfd3MeSLCthf5Sy9mxF0aPsr39QVWJCCLMWhfVNQUNnzX9CvVUWOxW9TDhQG06W /BXWZt4EUEioLxuWejmp12oN1lZoE2gBTyEuEDVEtF8Gy4i3a4BBsIGyGYHnQpY70oPd v4tkaHr0esFIocyt70JQhOAo6mAGj93Q6QeeGYhzJrI1ApQb92H3u/gy6Y3+W5+xtN3a yTVQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="j55M/dix"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=mGEqg+Ho; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RYHzMDbf; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-7c75610f6ecsi983529a34.508.2025.11.16.05.58.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 16 Nov 2025 05:58:16 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=pass header.i=@lists.sourceforge.net header.s=beta header.b="j55M/dix"; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b=mGEqg+Ho; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=RYHzMDbf; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=muc.de DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.sourceforge.net; s=beta; h=Content-Transfer-Encoding:Content-Type: List-Subscribe:List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: Subject:MIME-Version:References:In-Reply-To:Message-ID:Date:To:From:Sender: Reply-To:Cc:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=hvLz0YgfBKK6vXWOuH3q8su/W1+7j9u+XKCgcz317rM=; b=j55M/dix2UHeiMvjtW71lhrHOe TjUV87wSeI/0lVQNdQPRkQFTeo8zp6acGOaOvDg961xvz9U90AdmjM4emSuqE3aLZEdwGXfp5wASI 671q85SK/0KgisHnjYfQOpNkt2l/sYpUXK4zcGyWRiD9aO5vXg6oZCm8u+Zzsw8OQG+o=; Received: from [127.0.0.1] (helo=sfs-ml-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1vKdGe-0008Eo-QP; Sun, 16 Nov 2025 13:58:13 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1vKdGc-0008Eg-PJ for openvpn-devel@lists.sourceforge.net; Sun, 16 Nov 2025 13:58:11 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:References: In-Reply-To:Message-ID:Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type: Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender: Resent-To:Resent-Cc:Resent-Message-ID:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=O7OA556D1Ks95sfPHgQRjexlT25MVBObNmp+2yB6em8=; b=mGEqg+Ho612rjLBZjr8fKRhF4/ bH3096XOD0neut36czLKLAyT9xx225WnL9MpJEGHe3ksyF+1WH0hFqe4jTkmdlLtSLKrJTODw/0GG IqHyxbGLf2wDsHMEi29VMBwE2My+rh+CplvUDiPJuSqbkSV8sT0WtmWDT4flMnMUV4j4=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:References:In-Reply-To:Message-ID: Date:Subject:To:From:Sender:Reply-To:Cc:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Id:List-Help:List-Unsubscribe:List-Subscribe: List-Post:List-Owner:List-Archive; bh=O7OA556D1Ks95sfPHgQRjexlT25MVBObNmp+2yB6em8=; b=RYHzMDbfQBZcJlT2YZJ4rknkE9 y6TBwevyY4PimBgljrJFTv5pd+yB9KF/up/2dTbJ/u4+wi6r4D3NA4f7yaNQ3LHwjY+4uw+NQd62D 4gx8TtRtZH531SzKpWrNGQiee/MGdVe8lvYVyKbykNW1t2Vk/vS4Z+JOi8QAiMxHZIW8=; Received: from [193.149.48.134] (helo=blue.greenie.muc.de) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.95) id 1vKdGc-0006cN-A4 for openvpn-devel@lists.sourceforge.net; Sun, 16 Nov 2025 13:58:11 +0000 Received: from blue.greenie.muc.de (localhost [127.0.0.1]) by blue.greenie.muc.de (8.18.1/8.18.1) with ESMTP id 5AGDvw2Z015835 for ; Sun, 16 Nov 2025 14:57:58 +0100 Received: (from gert@localhost) by blue.greenie.muc.de (8.18.1/8.18.1/Submit) id 5AGDvw7B015834 for openvpn-devel@lists.sourceforge.net; Sun, 16 Nov 2025 14:57:58 +0100 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sun, 16 Nov 2025 14:57:52 +0100 Message-ID: <20251116135757.15805-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.49.1 In-Reply-To: References: MIME-Version: 1.0 X-Spam-Score: 1.3 (+) X-Spam-Report: Spam detection software, running on the system "sfi-spamd-2.hosts.colo.sdot.me", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Frank Lichtenheld 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/open [...] Content analysis details: (1.3 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 1.3 RDNS_NONE Delivered to internal network by a host with no rDNS X-Headers-End: 1vKdGc-0006cN-A4 Subject: [Openvpn-devel] [PATCH v8] otime: Fix various conversion warnings X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1848955629824234159?= X-GMAIL-MSGID: =?utf-8?q?1848955629824234159?= From: Frank Lichtenheld 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 --- This change was reviewed on Gerrit and approved by at least one developer. I request to merge it to master. Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1274 This mail reflects revision 8 of this Change. Acked-by according to Gerrit (reflected above): Gert Doering 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 = alloc_buf_gc(64, gc); struct timeval tv; - if (t) - { - tv.tv_sec = t; - tv.tv_usec = usec; - } - else + if (!t) { gettimeofday(&tv, NULL); + t = tv.tv_sec; + usec = tv.tv_usec; } - t = tv.tv_sec; struct tm *tm = 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=%ld", (long)tv.tv_usec); + buf_printf(&out, " us=%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_arena *gc); +const char *time_string(time_t t, tv_usec_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(__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 = now; - tv->tv_usec = now_usec; + tv->tv_sec = (tv_sec_t)now; + tv->tv_usec = (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 unsigned int max_seconds) +tv_subtract(const struct timeval *tv1, const struct timeval *tv2, const int max_seconds) { const int max_usec = max_seconds * 1000000; - const int sec_diff = tv1->tv_sec - tv2->tv_sec; + const tv_sec_t sec_diff = 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 = 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_delta(struct timeval *dest, const struct timeval *t1, const struct timeval *t2) { - int sec = t2->tv_sec - t1->tv_sec; - int usec = t2->tv_usec - t1->tv_usec; + tv_sec_t sec = t2->tv_sec - t1->tv_sec; + tv_usec_t usec = t2->tv_usec - t1->tv_usec; while (usec < 0) { @@ -241,10 +245,6 @@ dest->tv_usec = 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)