]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Move adjust_power_of_2() to integer.h
authorSteffan Karger <steffan.karger@fox-it.com>
Wed, 21 Jun 2017 21:10:43 +0000 (23:10 +0200)
committerGert Doering <gert@greenie.muc.de>
Tue, 27 Jun 2017 18:36:38 +0000 (20:36 +0200)
misc.c is a mess of incoherent functions, and is therefore included by
virtually all our source files.  That makes testing harder than it should
be.  As a first step of cleaning up misc.c, move adjust_power_of_2() to
integer.h, which is a more suitable place for a function like this.

This allows us to remove the duplicate implementation from test_argv.c.

Signed-off-by: Steffan Karger <steffan.karger@fox-it.com>
Acked-by: Antonio Quartulli <antonio@openvpn.net>
Message-Id: <20170621211043.6490-1-steffan@karger.me>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg14940.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
(cherry picked from commit 9fc0e963c757ffec3cc9fbf797fb7609f409c370)

src/openvpn/argv.c
src/openvpn/integer.h
src/openvpn/list.c
src/openvpn/mbuf.c
src/openvpn/misc.c
src/openvpn/misc.h
tests/unit_tests/openvpn/test_argv.c

index a71d261ca033b4ce928ab483d56cb89114fc4a55..95bdfeac4b5a37833d742a9a8691f1199416116a 100644 (file)
@@ -36,6 +36,7 @@
 #include "syshead.h"
 
 #include "argv.h"
+#include "integer.h"
 #include "options.h"
 
 static void
index 240781b7ba8be7598caf7255861c76cd1196ba01..9bb00a385168b464cf675ef8992ad0a4f535f1f1 100644 (file)
@@ -118,6 +118,24 @@ modulo_add(int x, int y, int mod)
     return sum;
 }
 
+/*
+ * Return the next largest power of 2
+ * or u if u is a power of 2.
+ */
+static inline size_t
+adjust_power_of_2(size_t u)
+{
+    size_t ret = 1;
+
+    while (ret < u)
+    {
+        ret <<= 1;
+        ASSERT(ret > 0);
+    }
+
+    return ret;
+}
+
 static inline int
 index_verify(int index, int size, const char *file, int line)
 {
index edca6f796e001d6285d70b127e3585c450e7063b..91765d2026468f4efb7e54428a75d6173657e9f8 100644 (file)
@@ -31,6 +31,7 @@
 
 #if P2MP_SERVER
 
+#include "integer.h"
 #include "list.h"
 #include "misc.h"
 
index fafbce0138f8c22b78f8595778c2e10ae3ed4ec4..f969a2b5b304b76c424defefd9a5ada9da51a774 100644 (file)
@@ -33,6 +33,7 @@
 
 #include "buffer.h"
 #include "error.h"
+#include "integer.h"
 #include "misc.h"
 #include "mbuf.h"
 
index fbd9938540e7fb51365cb7505315ad4593bec2aa..965869a7cf16cc53a165de68ba2f6fb0c3016ae1 100644 (file)
@@ -1645,24 +1645,6 @@ openvpn_sleep(const int n)
     sleep(n);
 }
 
-/*
- * Return the next largest power of 2
- * or u if u is a power of 2.
- */
-size_t
-adjust_power_of_2(size_t u)
-{
-    size_t ret = 1;
-
-    while (ret < u)
-    {
-        ret <<= 1;
-        ASSERT(ret > 0);
-    }
-
-    return ret;
-}
-
 /*
  * Remove security-sensitive strings from control message
  * so that they will not be output to log file.
index ce965492e91d0db304ec1568b5885c8d6e6d6816..3116ec424eaa6055f36ee01c3254391175d97f43 100644 (file)
@@ -327,8 +327,6 @@ extern const char *iproute_path;
 #define SSEC_PW_ENV    3 /* allow calling of built-in programs and user-defined scripts that may receive a password as an environmental variable */
 extern int script_security; /* GLOBAL */
 
-/* return the next largest power of 2 */
-size_t adjust_power_of_2(size_t u);
 
 #define COMPAT_FLAG_QUERY         0       /** compat_flags operator: Query for a flag */
 #define COMPAT_FLAG_SET           (1<<0)  /** compat_flags operator: Set a compat flag */
index 8c90eb9c32f757b22282c69eda86381a3d63e94d..4a3ba559bafac2409ad413f182daa5266b5bb76b 100644 (file)
 #include "argv.h"
 #include "buffer.h"
 
-/*
- * This is defined here to prevent #include'ing misc.h
- * which makes things difficult beyond any recognition
- */
-size_t
-adjust_power_of_2(size_t u)
-{
-    size_t ret = 1;
-
-    while (ret < u)
-    {
-        ret <<= 1;
-        assert(ret > 0);
-    }
-
-    return ret;
-}
-
 /* Defines for use in the tests and the mock parse_line() */
 #define PATH1       "/s p a c e"
 #define PATH2       "/foo bar/baz"