various: use CONST_MAX for array allocation

IIUC, with MAX() we get a VLA and the size is "decided" at runtime,
even though the result is always the same, but with CONST_MAX() we
get a normal stack variable.
This commit is contained in:
Zbigniew Jędrzejewski-Szmek 2022-06-04 21:07:27 +02:00
parent a5b28b7721
commit 89eb3d7c95
2 changed files with 3 additions and 3 deletions

View file

@ -339,7 +339,7 @@ static int output_timestamp_monotonic(FILE *f, sd_journal *j, const char *monoto
}
static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, OutputFlags flags, const char *realtime) {
char buf[MAX(FORMAT_TIMESTAMP_MAX, 64U)];
char buf[CONST_MAX(FORMAT_TIMESTAMP_MAX, 64U)];
uint64_t x;
int r;

View file

@ -314,7 +314,7 @@ TEST(usec_sub_signed) {
TEST(format_timestamp) {
for (unsigned i = 0; i < 100; i++) {
char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)];
char buf[CONST_MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)];
usec_t x, y;
x = random_u64_range(2147483600 * USEC_PER_SEC) + 1;
@ -374,7 +374,7 @@ TEST(FORMAT_TIMESTAMP) {
}
TEST(format_timestamp_relative) {
char buf[MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)];
char buf[CONST_MAX(FORMAT_TIMESTAMP_MAX, FORMAT_TIMESPAN_MAX)];
usec_t x;
/* Only testing timestamps in the past so we don't need to add some delta to account for time passing