[Openvpn-devel,v1] Remove local get_random in test_misc.c

Message ID 20260805134719.164126-1-frank@lichtenheld.com
State New
Headers
Series [Openvpn-devel,v1] Remove local get_random in test_misc.c |

Commit Message

Frank Lichtenheld Aug. 5, 2026, 1:47 p.m. UTC
  From: Arne Schwabe <arne@rfc2549.org>

The get_random in test_misc.c conflicts
with the get_random function that OpenVPN defines in crypto.h
Also adjust the implementation in mock_get_random.c to match the
prototype in crypto.h

Change-Id: I3db70001be7f39cf84d562517647f1a305962b42
Signed-off-by: Arne Schwabe <arne@rfc2549.org>
Acked-by: Frank Lichtenheld <frank@lichtenheld.com>
Gerrit URL: https://gerrit.openvpn.net/c/openvpn/+/1834
---

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/+/1834
This mail reflects revision 1 of this Change.

Acked-by according to Gerrit (reflected above):
Frank Lichtenheld <frank@lichtenheld.com>
  

Patch

diff --git a/tests/unit_tests/openvpn/mock_get_random.c b/tests/unit_tests/openvpn/mock_get_random.c
index 0840e31..5cb768b 100644
--- a/tests/unit_tests/openvpn/mock_get_random.c
+++ b/tests/unit_tests/openvpn/mock_get_random.c
@@ -28,7 +28,7 @@ 
 #include <stdint.h>
 #include <cmocka.h>
 
-unsigned long
+int64_t
 get_random(void)
 {
     /* rand() is not very random, but it's C99 and this is just for testing */
diff --git a/tests/unit_tests/openvpn/test_misc.c b/tests/unit_tests/openvpn/test_misc.c
index 501286c..8da7abe 100644
--- a/tests/unit_tests/openvpn/test_misc.c
+++ b/tests/unit_tests/openvpn/test_misc.c
@@ -38,6 +38,7 @@ 
 #include "test_common.h"
 #include "list.h"
 #include "mock_msg.h"
+#include "crypto.h"
 #ifdef _WIN32
 #include "win32-util.h"
 #endif
@@ -141,13 +142,6 @@ 
     return strcmp((const char *)key1, (const char *)key2) == 0;
 }
 
-static uint32_t
-get_random(void)
-{
-    /* rand() is not very random, but it's C99 and this is just for testing */
-    return (uint32_t)rand();
-}
-
 static struct hash_element *
 hash_lookup_by_value(struct hash *hash, void *value)
 {
@@ -263,7 +257,7 @@ 
         {
             struct hash_iterator hi;
             struct hash_element *he;
-            inc = (get_random() % 3) + 1;
+            inc = ((uint32_t)get_random() % 3) + 1;
             hash_iterator_init_range(hash, &hi, base, base + inc);
 
             while ((he = hash_iterator_next(&hi)))