1 |
commit: ff143361fe3b5eb7befefea5ab45440a6b8716db |
2 |
Author: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sun Nov 17 14:22:11 2019 +0000 |
4 |
Commit: Fabian Groffen <grobian <AT> gentoo <DOT> org> |
5 |
CommitDate: Sun Nov 17 14:22:11 2019 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage-utils.git/commit/?id=ff143361 |
7 |
|
8 |
main: ensure READ/WRITE_BE_INT32 operate on the expected bytes |
9 |
|
10 |
we want to work on unsigned bytes such that we don't get sudden |
11 |
unintended operations due to negative value handling |
12 |
|
13 |
Signed-off-by: Fabian Groffen <grobian <AT> gentoo.org> |
14 |
|
15 |
main.h | 13 ++++++++----- |
16 |
1 file changed, 8 insertions(+), 5 deletions(-) |
17 |
|
18 |
diff --git a/main.h b/main.h |
19 |
index ad1467b..03c3bd2 100644 |
20 |
--- a/main.h |
21 |
+++ b/main.h |
22 |
@@ -56,13 +56,16 @@ extern const char *argv0; |
23 |
#endif |
24 |
|
25 |
#define READ_BE_INT32(P) \ |
26 |
- (((P)[0] << 24) | ((P)[1] << 16) | ((P)[2] << 8 ) | (P)[3]) |
27 |
+ ((((unsigned char *)(P))[0] << 24) | \ |
28 |
+ (((unsigned char *)(P))[1] << 16) | \ |
29 |
+ (((unsigned char *)(P))[2] << 8 ) | \ |
30 |
+ (((unsigned char *)(P))[3])) |
31 |
#define WRITE_BE_INT32(P,I) \ |
32 |
{ \ |
33 |
- (P)[0] = (I & 0xff000000) >> 24; \ |
34 |
- (P)[1] = (I & 0x00ff0000) >> 16; \ |
35 |
- (P)[2] = (I & 0x0000ff00) >> 8; \ |
36 |
- (P)[3] = (I & 0x000000ff); \ |
37 |
+ ((unsigned char *)(P))[0] = (I & 0xff000000) >> 24; \ |
38 |
+ ((unsigned char *)(P))[1] = (I & 0x00ff0000) >> 16; \ |
39 |
+ ((unsigned char *)(P))[2] = (I & 0x0000ff00) >> 8; \ |
40 |
+ ((unsigned char *)(P))[3] = (I & 0x000000ff); \ |
41 |
} |
42 |
|
43 |
/* Easy enough to glue to older versions */ |