[Openvpn-devel,1/2] Replace custom min macro and use more C99 style in man_remote_entry_get

Message ID 20221227140249.3524943-1-arne@rfc2549.org
State Accepted
Headers show
Series [Openvpn-devel,1/2] Replace custom min macro and use more C99 style in man_remote_entry_get | expand

Commit Message

Arne Schwabe Dec. 27, 2022, 2:02 p.m. UTC
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
---
 src/openvpn/manage.c | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

Comments

Gert Doering Dec. 27, 2022, 5:24 p.m. UTC | #1
Acked-by: Gert Doering <gert@greenie.muc.de>

Thanks.

Have not done much testing beyond "push to github and enjoy the green"
(but this is very nice indeed).  Well, except for the clang-asan red, 
which I did not notice before... but there is 2/2 for that :-)

Your patch has been applied to the master branch.

commit 841524153fbdcd377065e221e91ef163d83b9cc9 (master)
commit f5919a42e4a6772c4116d19cd09132bedb6d77f5 (release/2.6)
Author: Arne Schwabe
Date:   Tue Dec 27 15:02:44 2022 +0100

     Replace custom min macro and use more C99 style in man_remote_entry_get

     Signed-off-by: Arne Schwabe <arne@rfc2549.org>
     Acked-by: Gert Doering <gert@greenie.muc.de>
     Message-Id: <20221227140249.3524943-1-arne@rfc2549.org>
     URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25830.html
     Signed-off-by: Gert Doering <gert@greenie.muc.de>


--
kind regards,

Gert Doering

Patch

diff --git a/src/openvpn/manage.c b/src/openvpn/manage.c
index be9a38952..7e326702f 100644
--- a/src/openvpn/manage.c
+++ b/src/openvpn/manage.c
@@ -865,8 +865,6 @@  man_remote_entry_count(struct management *man)
     }
 }
 
-#define min(a, b) ((a) < (b) ? (a) : (b))
-
 static void
 man_remote_entry_get(struct management *man, const char *p1, const char *p2)
 {
@@ -875,12 +873,10 @@  man_remote_entry_get(struct management *man, const char *p1, const char *p2)
     if (man->persist.callback.remote_entry_get
         && man->persist.callback.remote_entry_count)
     {
-        bool res;
-        unsigned int from, to;
         unsigned int count = (*man->persist.callback.remote_entry_count)(man->persist.callback.arg);
 
-        from = (unsigned int) atoi(p1);
-        to = p2 ? (unsigned int) atoi(p2) : from + 1;
+        unsigned int from = (unsigned int) atoi(p1);
+        unsigned int to = p2 ? (unsigned int) atoi(p2) : from + 1;
 
         if (!strcmp(p1, "all"))
         {
@@ -888,10 +884,10 @@  man_remote_entry_get(struct management *man, const char *p1, const char *p2)
             to = count;
         }
 
-        for (unsigned int i = from; i < min(to, count); i++)
+        for (unsigned int i = from; i < min_uint(to, count); i++)
         {
             char *remote = NULL;
-            res = (*man->persist.callback.remote_entry_get)(man->persist.callback.arg, i, &remote);
+            bool res = (*man->persist.callback.remote_entry_get)(man->persist.callback.arg, i, &remote);
             if (res && remote)
             {
                 msg(M_CLIENT, "%u,%s", i, remote);