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>
... | ... |
@@ -118,6 +118,24 @@ modulo_add(int x, int y, int mod) |
118 | 118 |
return sum; |
119 | 119 |
} |
120 | 120 |
|
121 |
+/* |
|
122 |
+ * Return the next largest power of 2 |
|
123 |
+ * or u if u is a power of 2. |
|
124 |
+ */ |
|
125 |
+static inline size_t |
|
126 |
+adjust_power_of_2(size_t u) |
|
127 |
+{ |
|
128 |
+ size_t ret = 1; |
|
129 |
+ |
|
130 |
+ while (ret < u) |
|
131 |
+ { |
|
132 |
+ ret <<= 1; |
|
133 |
+ ASSERT(ret > 0); |
|
134 |
+ } |
|
135 |
+ |
|
136 |
+ return ret; |
|
137 |
+} |
|
138 |
+ |
|
121 | 139 |
static inline int |
122 | 140 |
index_verify(int index, int size, const char *file, int line) |
123 | 141 |
{ |
... | ... |
@@ -1646,24 +1646,6 @@ openvpn_sleep(const int n) |
1646 | 1646 |
} |
1647 | 1647 |
|
1648 | 1648 |
/* |
1649 |
- * Return the next largest power of 2 |
|
1650 |
- * or u if u is a power of 2. |
|
1651 |
- */ |
|
1652 |
-size_t |
|
1653 |
-adjust_power_of_2(size_t u) |
|
1654 |
-{ |
|
1655 |
- size_t ret = 1; |
|
1656 |
- |
|
1657 |
- while (ret < u) |
|
1658 |
- { |
|
1659 |
- ret <<= 1; |
|
1660 |
- ASSERT(ret > 0); |
|
1661 |
- } |
|
1662 |
- |
|
1663 |
- return ret; |
|
1664 |
-} |
|
1665 |
- |
|
1666 |
-/* |
|
1667 | 1649 |
* Remove security-sensitive strings from control message |
1668 | 1650 |
* so that they will not be output to log file. |
1669 | 1651 |
*/ |
... | ... |
@@ -327,8 +327,6 @@ extern const char *iproute_path; |
327 | 327 |
#define SSEC_PW_ENV 3 /* allow calling of built-in programs and user-defined scripts that may receive a password as an environmental variable */ |
328 | 328 |
extern int script_security; /* GLOBAL */ |
329 | 329 |
|
330 |
-/* return the next largest power of 2 */ |
|
331 |
-size_t adjust_power_of_2(size_t u); |
|
332 | 330 |
|
333 | 331 |
#define COMPAT_FLAG_QUERY 0 /** compat_flags operator: Query for a flag */ |
334 | 332 |
#define COMPAT_FLAG_SET (1<<0) /** compat_flags operator: Set a compat flag */ |
... | ... |
@@ -13,24 +13,6 @@ |
13 | 13 |
#include "argv.h" |
14 | 14 |
#include "buffer.h" |
15 | 15 |
|
16 |
-/* |
|
17 |
- * This is defined here to prevent #include'ing misc.h |
|
18 |
- * which makes things difficult beyond any recognition |
|
19 |
- */ |
|
20 |
-size_t |
|
21 |
-adjust_power_of_2(size_t u) |
|
22 |
-{ |
|
23 |
- size_t ret = 1; |
|
24 |
- |
|
25 |
- while (ret < u) |
|
26 |
- { |
|
27 |
- ret <<= 1; |
|
28 |
- assert(ret > 0); |
|
29 |
- } |
|
30 |
- |
|
31 |
- return ret; |
|
32 |
-} |
|
33 |
- |
|
34 | 16 |
/* Defines for use in the tests and the mock parse_line() */ |
35 | 17 |
#define PATH1 "/s p a c e" |
36 | 18 |
#define PATH2 "/foo bar/baz" |