Merge pull request #25829 from poettering/empty-to-null-const-fix
string-util: don't add `const` to return pointer of empty_to_null() if input didn't have it
This commit is contained in:
+12
-3
@@ -53,9 +53,13 @@ static inline const char* enable_disable(bool b) {
|
||||
return b ? "enable" : "disable";
|
||||
}
|
||||
|
||||
static inline const char *empty_to_null(const char *p) {
|
||||
return isempty(p) ? NULL : p;
|
||||
}
|
||||
/* This macro's return pointer will have the "const" qualifier set or unset the same way as the input
|
||||
* pointer. */
|
||||
#define empty_to_null(p) \
|
||||
({ \
|
||||
const char *_p = (p); \
|
||||
(typeof(p)) (isempty(_p) ? NULL : _p); \
|
||||
})
|
||||
|
||||
static inline const char *empty_to_na(const char *p) {
|
||||
return isempty(p) ? "n/a" : p;
|
||||
@@ -74,6 +78,11 @@ static inline bool empty_or_dash(const char *str) {
|
||||
static inline const char *empty_or_dash_to_null(const char *p) {
|
||||
return empty_or_dash(p) ? NULL : p;
|
||||
}
|
||||
#define empty_or_dash_to_null(p) \
|
||||
({ \
|
||||
const char *_p = (p); \
|
||||
(typeof(p)) (empty_or_dash(_p) ? NULL : _p); \
|
||||
})
|
||||
|
||||
char *first_word(const char *s, const char *word) _pure_;
|
||||
|
||||
|
||||
+1
-1
@@ -563,7 +563,7 @@ static int verb_decrypt(int argc, char **argv, void *userdata) {
|
||||
if (r < 0)
|
||||
return log_error_errno(r, "Failed to read encrypted credential data: %m");
|
||||
|
||||
output_path = (argc < 3 || isempty(argv[2]) || streq(argv[2], "-")) ? NULL : argv[2];
|
||||
output_path = (argc < 3 || empty_or_dash(argv[2])) ? NULL : argv[2];
|
||||
|
||||
if (arg_name_any)
|
||||
name = NULL;
|
||||
|
||||
Reference in New Issue
Block a user