1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
https://github.com/zlib-ng/minizip-ng/pull/651
From 1be6ea22e127a99786aefd2896e08bab43ad1333 Mon Sep 17 00:00:00 2001
From: Sam James <sam@gentoo.org>
Date: Sun, 2 Oct 2022 01:39:17 +0100
Subject: [PATCH] Switch getrandom() and arc4random_buf() usage order
We need to match the order of inclusions at the top of the file
otherwise we might end up trying to use arc4random_buf() when
available (because HAVE_ARC4RANODM_BUF is set) even though
we hit HAVE_GETRANDOM first above and only included
<sys/random.h> because of it.
Besides, if getrandom() is available, we should really prefer
it anyway.
Fixes an implicit function declaration:
```
minizip-ng-3.0.6/mz_os_posix.c:124:5: error: implicit declaration of function 'arc4random_buf' [-Werror=implicit-function-declaration]
```
--- a/mz_os_posix.c
+++ b/mz_os_posix.c
@@ -117,7 +117,22 @@ void mz_os_utf8_string_delete(uint8_t **string) {
/***************************************************************************/
-#if defined(HAVE_ARC4RANDOM_BUF)
+#if defined(HAVE_GETRANDOM)
+int32_t mz_os_rand(uint8_t *buf, int32_t size) {
+ int32_t left = size;
+ int32_t written = 0;
+
+ while (left > 0) {
+ written = getrandom(buf, left, 0);
+ if (written < 0)
+ return MZ_INTERNAL_ERROR;
+
+ buf += written;
+ left -= written;
+ }
+ return size - left;
+}
+#elif defined(HAVE_ARC4RANDOM_BUF)
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
if (size < 0)
return 0;
@@ -139,21 +154,6 @@ int32_t mz_os_rand(uint8_t *buf, int32_t size) {
}
return size - left;
}
-#elif defined(HAVE_GETRANDOM)
-int32_t mz_os_rand(uint8_t *buf, int32_t size) {
- int32_t left = size;
- int32_t written = 0;
-
- while (left > 0) {
- written = getrandom(buf, left, 0);
- if (written < 0)
- return MZ_INTERNAL_ERROR;
-
- buf += written;
- left -= written;
- }
- return size - left;
-}
#else
int32_t mz_os_rand(uint8_t *buf, int32_t size) {
static unsigned calls = 0;
|