]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
util: make size macros unsigned
authorLennart Poettering <lennart@poettering.net>
Thu, 15 Oct 2020 15:33:04 +0000 (17:33 +0200)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 20 Oct 2020 06:51:48 +0000 (15:51 +0900)
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: https://github.com/systemd/systemd/pull/17345#issuecomment-709402332
src/basic/format-util.h
src/basic/time-util.h
src/cgtop/cgtop.c
src/shared/logs-show.c

index c47fa76ea8ff2e709d1b8d92b92fe0aed0609cf8..db37c16140c82865fd1e00b622699c8675db0d67 100644 (file)
@@ -72,11 +72,14 @@ typedef enum {
         FORMAT_BYTES_TRAILING_B  = 1 << 2,
 } FormatBytesFlag;
 
-#define FORMAT_BYTES_MAX 16
+#define FORMAT_BYTES_MAX 16U
+
 char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag);
+
 static inline char *format_bytes(char *buf, size_t l, uint64_t t) {
         return format_bytes_full(buf, l, t, FORMAT_BYTES_USE_IEC | FORMAT_BYTES_BELOW_POINT | FORMAT_BYTES_TRAILING_B);
 }
+
 static inline char *format_bytes_cgroup_protection(char *buf, size_t l, uint64_t t) {
         if (t == CGROUP_LIMIT_MAX) {
                 (void) snprintf(buf, l, "%s", "infinity");
index cecd5efa604ae07970265e91a02332880646c5aa..6feda5e1559e60f92d137270e14508fbf13b84da 100644 (file)
@@ -63,10 +63,10 @@ typedef enum TimestampStyle {
 
 /* We assume a maximum timezone length of 6. TZNAME_MAX is not defined on Linux, but glibc internally initializes this
  * to 6. Let's rely on that. */
-#define FORMAT_TIMESTAMP_MAX (3+1+10+1+8+1+6+1+6+1)
-#define FORMAT_TIMESTAMP_WIDTH 28 /* when outputting, assume this width */
-#define FORMAT_TIMESTAMP_RELATIVE_MAX 256
-#define FORMAT_TIMESPAN_MAX 64
+#define FORMAT_TIMESTAMP_MAX (3U+1U+10U+1U+8U+1U+6U+1U+6U+1U)
+#define FORMAT_TIMESTAMP_WIDTH 28U /* when outputting, assume this width */
+#define FORMAT_TIMESTAMP_RELATIVE_MAX 256U
+#define FORMAT_TIMESPAN_MAX 64U
 
 #define TIME_T_MAX (time_t)((UINTMAX_C(1) << ((sizeof(time_t) << 3) - 1)) - 1)
 
index 042d83c495ca9e40162fb62b3dfe5767031b352d..0b6c2f88ed1f63265b4b56aedd08473069309da0 100644 (file)
@@ -586,7 +586,7 @@ static void display(Hashmap *a) {
         Group **array;
         signed path_columns;
         unsigned rows, n = 0, j, maxtcpu = 0, maxtpath = 3; /* 3 for ellipsize() to work properly */
-        char buffer[MAX3(21, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
+        char buffer[MAX3(21U, FORMAT_BYTES_MAX, FORMAT_TIMESPAN_MAX)];
 
         assert(a);
 
index 4f25c643d23e6c1eab946b52aa8cb96f13de71a8..f7d3e01b49384cbd57f507f5d8e580e90b333e65 100644 (file)
@@ -347,7 +347,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, 64)];
+        char buf[MAX(FORMAT_TIMESTAMP_MAX, 64U)];
         struct tm *(*gettime_r)(const time_t *, struct tm *);
         struct tm tm;
         uint64_t x;