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