X Tutup
Skip to content

Commit 67bd562

Browse files
poetteringyuwata
authored andcommitted
util: make size macros unsigned
By making them unsigned comparing them with other sizes is less likely to trigger compiler warnings regarding signed/unsigned comparisons. After all sizes (i.e. size_t) are generally assumed to be unsigned, so these should be too. Prompted-by: systemd#17345 (comment)
1 parent 0ce8a9d commit 67bd562

File tree

4 files changed

+10
-7
lines changed

4 files changed

+10
-7
lines changed

src/basic/format-util.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,14 @@ typedef enum {
7272
FORMAT_BYTES_TRAILING_B = 1 << 2,
7373
} FormatBytesFlag;
7474

75-
#define FORMAT_BYTES_MAX 16
75+
#define FORMAT_BYTES_MAX 16U
76+
7677
char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag);
78+
7779
static inline char *format_bytes(char *buf, size_t l, uint64_t t) {
7880
return format_bytes_full(buf, l, t, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | FORMAT_BYTES_TRAILING_B);
7981
}
82+
8083
static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) {
8184
if (t == CGROUP_LIMIT_MAX) {
8285
(void) snprintf(buf, l, "%s", "infinity");

src/basic/time-util.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,10 +63,10 @@ typedef enum TimestampStyle {
6363

6464
/* We assume a maximum timezone length of 6. TZNAME_MAX is not defined on Linux, but glibc internally initializes this
6565
* to 6. Let's rely on that. */
66-
#define FORMAT_TIMESTAMP_MAX (3+1+10+1+8+1+6+1+6+1)
67-
#define FORMAT_TIMESTAMP_WIDTH 28 /* when outputting, assume this width */
68-
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
69-
#define FORMAT_TIMESPAN_MAX 64
66+
#define FORMAT_TIMESTAMP_MAX (3U+1U+10U+1U+8U+1U+6U+1U+6U+1U)
67+
#define FORMAT_TIMESTAMP_WIDTH 28U /* when outputting, assume this width */
68+
#define FORMAT_TIMESTAMP_RELATIVE_MAX 256U
69+
#define FORMAT_TIMESPAN_MAX 64U
7070

7171
#define TIME_T_MAX (time_t)((UINTMAX_C(1) << ((sizeof(time_t) << 3) - 1)) - 1)
7272

src/cgtop/cgtop.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -586,7 +586,7 @@ static void display(Hashmap *a) {
586586
Group **array;
587587
signed path_columns;
588588
unsigned rows, n = 0, j, maxtcpu = 0, maxtpath = 3; /* 3 for ellipsize() to work properly */
589-
char buffer[MAX3(21, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
589+
char buffer[MAX3(21U, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
590590

591591
assert(a);
592592

src/shared/logs-show.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ static int output_timestamp_monotonic(FILE *f, sd_journal *j, const char *monoto
347347
}
348348

349349
static int output_timestamp_realtime(FILE *f, sd_journal *j, OutputMode mode, OutputFlags flags, const char *realtime) {
350-
char buf[MAX(FORMAT_TIMESTAMP_MAX, 64)];
350+
char buf[MAX(FORMAT_TIMESTAMP_MAX, 64U)];
351351
struct tm *(*gettime_r)(const time_t *, struct tm *);
352352
struct tm tm;
353353
uint64_t x;

0 commit comments

Comments
 (0)
X Tutup