]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
basic/{time,format}-util: warn when format result is unused
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Tue, 6 Jul 2021 13:16:15 +0000 (15:16 +0200)
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>
Fri, 9 Jul 2021 09:11:25 +0000 (11:11 +0200)
Now that anonymous buffers are used in almost all cases, code which
does not use the return value is usually broken.

src/basic/format-util.h
src/basic/macro.h
src/basic/time-util.h

index 92bb131a91b86b1624a81309aa9f92d5abea0bc1..579f2318975781d46a412c5f238edaf0b1088d49 100644 (file)
@@ -74,8 +74,9 @@ typedef enum {
 
 #define FORMAT_BYTES_MAX 16U
 
-char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag);
+char *format_bytes_full(char *buf, size_t l, uint64_t t, FormatBytesFlag flag) _warn_unused_result_;
 
+_warn_unused_result_
 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);
 }
index 6507728a517ab99b836ae09012bc532be6ec6f3a..a8476184c2d8dce06e641a4a696cde2d60003e6d 100644 (file)
@@ -30,6 +30,7 @@
 #define _weakref_(x) __attribute__((__weakref__(#x)))
 #define _alignas_(x) __attribute__((__aligned__(__alignof(x))))
 #define _alignptr_ __attribute__((__aligned__(sizeof(void*))))
+#define _warn_unused_result_ __attribute__((__warn_unused_result__))
 #if __GNUC__ >= 7
 #define _fallthrough_ __attribute__((__fallthrough__))
 #else
index a3f9f44797fc4db4e87c12baf42debc916151a83..2cb0ca2040d1108e6e1afb4edca4f8f142aec2c0 100644 (file)
@@ -117,10 +117,11 @@ struct timespec* timespec_store_nsec(struct timespec *ts, nsec_t n);
 usec_t timeval_load(const struct timeval *tv) _pure_;
 struct timeval* timeval_store(struct timeval *tv, usec_t u);
 
-char* format_timestamp_style(char *buf, size_t l, usec_t t, TimestampStyle style);
-char* format_timestamp_relative(char *buf, size_t l, usec_t t);
-char* format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy);
+char* format_timestamp_style(char *buf, size_t l, usec_t t, TimestampStyle style) _warn_unused_result_;
+char* format_timestamp_relative(char *buf, size_t l, usec_t t) _warn_unused_result_;
+char* format_timespan(char *buf, size_t l, usec_t t, usec_t accuracy) _warn_unused_result_;
 
+_warn_unused_result_
 static inline char* format_timestamp(char *buf, size_t l, usec_t t) {
         return format_timestamp_style(buf, l, t, TIMESTAMP_PRETTY);
 }