From 295e632e817df5372f8ca3283166c0b9b203dfad Mon Sep 17 00:00:00 2001 From: Zdenek Kabelac Date: Thu, 4 Apr 2024 18:41:42 +0200 Subject: [PATCH] util: add _dm_strncpy Add internal inline function wrapper for dm_strncpy(). Use it for calls where we test the result. Avoids emitting warnings in Coverity for unchecked usage. --- lib/misc/util.h | 7 +++++++ libdm/dm-tools/util.h | 7 +++++++ 2 files changed, 14 insertions(+) diff --git a/lib/misc/util.h b/lib/misc/util.h index 35514eee0..963e43074 100644 --- a/lib/misc/util.h +++ b/lib/misc/util.h @@ -35,6 +35,13 @@ #define uninitialized_var(x) x = x #endif +/* Use wrapper for checked results */ +static inline __attribute__((warn_unused_result)) + int _dm_strncpy(char *dest, const char *src, size_t n) +{ + return dm_strncpy(dest, src, n); +} + /* * GCC 3.4 adds a __builtin_clz, which uses the count leading zeros (clz) * instruction on arches that have one. Provide a fallback using shifts diff --git a/libdm/dm-tools/util.h b/libdm/dm-tools/util.h index 3925a7438..fc60f0437 100644 --- a/libdm/dm-tools/util.h +++ b/libdm/dm-tools/util.h @@ -17,6 +17,13 @@ #include +/* Use wrapper for checked results */ +static inline __attribute__((warn_unused_result)) + int _dm_strncpy(char *dest, const char *src, size_t n) +{ + return dm_strncpy(dest, src, n); +} + #define min(a, b) ({ typeof(a) _a = (a); \ typeof(b) _b = (b); \ (void) (&_a == &_b); \