From 5ecd641ac8453f79b5095c4246b83e979cad7e78 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Wed, 14 May 2025 22:03:29 +0200 Subject: [PATCH 1/3] src/boot: assume that intmax_t is the biggest integer Same as in 81d7934882ae13c64d9b08d365a0baa011cb2fbb, intmax_t by definition is the widest int. Strictly speaking, the check whether sizeof(intmax_t) == sizeof(long long) in the code below is redundant, but I think it's nicer to keep it for symmetry with the other cases. Requested in https://github.com/systemd/systemd/pull/37442#pullrequestreview-2840906908. --- src/boot/efi-string.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/boot/efi-string.c b/src/boot/efi-string.c index 4b9c3181c0..59cb0fa9f5 100644 --- a/src/boot/efi-string.c +++ b/src/boot/efi-string.c @@ -755,7 +755,7 @@ static bool handle_format_specifier(FormatContext *ctx, SpecifierContext *sp) { * otherwise warn about fetching smaller types. */ assert_cc(sizeof(int) == 4); assert_cc(sizeof(wchar_t) <= sizeof(int)); - assert_cc(sizeof(intmax_t) <= sizeof(long long)); + assert_cc(sizeof(long long) == sizeof(intmax_t)); assert(ctx); assert(sp); From 5b5545f112126157be3ffd89a70803507456ee71 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Thu, 15 May 2025 13:55:11 +0200 Subject: [PATCH 2/3] basic/terminal-util: drop 'U' suffix C automatically casts a signed int to unsigned in binary operation with an unsigned int. Thus that suffix is not useful. Also surrounding code doesn't use it. --- src/basic/terminal-util.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/basic/terminal-util.h b/src/basic/terminal-util.h index d008d0456c..fa771230ff 100644 --- a/src/basic/terminal-util.h +++ b/src/basic/terminal-util.h @@ -165,7 +165,7 @@ int pty_open_peer(int fd, int mode); static inline bool osc_char_is_valid(char c) { /* Checks whether the specified character is safe to be included inside an ANSI OSC sequence, as per * ECMA-48 5th edition, section 8.3.89 */ - return (unsigned char) c >= 32U && (unsigned char) c < 127; + return (unsigned char) c >= 32 && (unsigned char) c < 127; } static inline bool vtnr_is_valid(unsigned n) { From f4bdf373c5538b2a28fc033060aa609115297a81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Zbigniew=20J=C4=99drzejewski-Szmek?= Date: Fri, 16 May 2025 15:24:12 +0200 Subject: [PATCH 3/3] basic/terminal-util: simplify output param handling Those static functions were written to support optional output params, but they are only ever called with the output param set, and it doesn't make sense to ever call them without the output param. Since those are internal functions, drop this unused complexity. --- src/basic/terminal-util.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/src/basic/terminal-util.c b/src/basic/terminal-util.c index 7c900c267d..b8e51e5ea4 100644 --- a/src/basic/terminal-util.c +++ b/src/basic/terminal-util.c @@ -1970,7 +1970,8 @@ static int scan_background_color_response( size_t *ret_processed) { assert(context); - assert(buf || size == 0); + assert(buf); + assert(ret_processed); for (size_t i = 0; i < size; i++) { char c = buf[i]; @@ -2044,9 +2045,7 @@ static int scan_background_color_response( case BACKGROUND_BLUE: if (c == '\x07') { if (context->blue_bits > 0) { - if (ret_processed) - *ret_processed = i + 1; - + *ret_processed = i + 1; return 1; /* success! */ } @@ -2066,9 +2065,7 @@ static int scan_background_color_response( case BACKGROUND_STRING_TERMINATOR: if (c == '\\') { - if (ret_processed) - *ret_processed = i + 1; - + *ret_processed = i + 1; return 1; /* success! */ } @@ -2085,9 +2082,7 @@ static int scan_background_color_response( } } - if (ret_processed) - *ret_processed = size; - + *ret_processed = size; return 0; /* all good, but not enough data yet */ } @@ -2214,7 +2209,8 @@ static int scan_cursor_position_response( size_t *ret_processed) { assert(context); - assert(buf || size == 0); + assert(buf); + assert(ret_processed); for (size_t i = 0; i < size; i++) { char c = buf[i]; @@ -2247,9 +2243,7 @@ static int scan_cursor_position_response( case CURSOR_COLUMN: if (c == 'R') { if (context->column > 0) { - if (ret_processed) - *ret_processed = i + 1; - + *ret_processed = i + 1; return 1; /* success! */ } @@ -2272,9 +2266,7 @@ static int scan_cursor_position_response( context->row = context->column = 0; } - if (ret_processed) - *ret_processed = size; - + *ret_processed = size; return 0; /* all good, but not enough data yet */ }