mirror of
https://github.com/systemd/systemd.git
synced 2026-08-02 22:20:20 +00:00
Drop the text argument from assert_not_reached()
In general we almost never hit those asserts in production code, so users see them very rarely, if ever. But either way, we just need something that users can pass to the developers. We have quite a few of those asserts, and some have fairly nice messages, but many are like "WTF?" or "???" or "unexpected something". The error that is printed includes the file location, and function name. In almost all functions there's at most one assert, so the function name alone is enough to identify the failure for a developer. So we don't get much extra from the message, and we might just as well drop them. Dropping them makes our code a tiny bit smaller, and most importantly, improves development experience by making it easy to insert such an assert in the code without thinking how to phrase the argument.
This commit is contained in:
@@ -136,7 +136,7 @@ int uname_architecture(void) {
|
||||
if (streq(arch_map[i].machine, u.machine))
|
||||
return cached = arch_map[i].arch;
|
||||
|
||||
assert_not_reached("Couldn't identify architecture. You need to patch systemd.");
|
||||
assert_not_reached();
|
||||
return _ARCHITECTURE_INVALID;
|
||||
}
|
||||
|
||||
|
||||
@@ -401,7 +401,7 @@ static struct hashmap_base_entry* bucket_at_virtual(HashmapBase *h, struct swap_
|
||||
if (idx < _IDX_SWAP_END)
|
||||
return &bucket_at_swap(swap, idx)->p.b;
|
||||
|
||||
assert_not_reached("Invalid index");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
static dib_raw_t* dib_raw_ptr(HashmapBase *h) {
|
||||
@@ -513,7 +513,7 @@ static void* entry_value(HashmapBase *h, struct hashmap_base_entry *e) {
|
||||
return (void*) e->key;
|
||||
|
||||
default:
|
||||
assert_not_reached("Unknown hashmap type");
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1747,7 +1747,7 @@ HashmapBase* _hashmap_copy(HashmapBase *h HASHMAP_DEBUG_PARAMS) {
|
||||
r = set_merge((Set*)copy, (Set*)h);
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("Unknown hashmap type");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (r < 0)
|
||||
|
||||
@@ -794,7 +794,7 @@ int in_addr_prefix_from_string_auto_internal(
|
||||
k = 0;
|
||||
break;
|
||||
default:
|
||||
assert_not_reached("Invalid prefixlen mode");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (ret_family)
|
||||
|
||||
@@ -863,12 +863,11 @@ _noreturn_ void log_assert_failed(
|
||||
}
|
||||
|
||||
_noreturn_ void log_assert_failed_unreachable(
|
||||
const char *text,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func) {
|
||||
log_assert(LOG_CRIT, text, file, line, func,
|
||||
"Code should not be reached '%s' at %s:%u, function %s(). Aborting.");
|
||||
log_assert(LOG_CRIT, "Code should not be reached", file, line, func,
|
||||
"%s at %s:%u, function %s(). Aborting.");
|
||||
abort();
|
||||
}
|
||||
|
||||
|
||||
@@ -174,7 +174,6 @@ _noreturn_ void log_assert_failed(
|
||||
const char *func);
|
||||
|
||||
_noreturn_ void log_assert_failed_unreachable(
|
||||
const char *text,
|
||||
const char *file,
|
||||
int line,
|
||||
const char *func);
|
||||
|
||||
@@ -282,8 +282,8 @@ static inline int __coverity_check_and_return__(int condition) {
|
||||
#define assert(expr) assert_message_se(expr, #expr)
|
||||
#endif
|
||||
|
||||
#define assert_not_reached(t) \
|
||||
log_assert_failed_unreachable(t, PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__)
|
||||
#define assert_not_reached() \
|
||||
log_assert_failed_unreachable(PROJECT_FILE, __LINE__, __PRETTY_FUNCTION__)
|
||||
|
||||
#define assert_return(expr, r) \
|
||||
do { \
|
||||
|
||||
@@ -347,7 +347,7 @@ static int acquire_config_dirs(UnitFileScope scope, char **persistent, char **ru
|
||||
return 0;
|
||||
|
||||
default:
|
||||
assert_not_reached("Hmm, unexpected scope value.");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (!a || !b)
|
||||
@@ -405,7 +405,7 @@ static int acquire_control_dirs(UnitFileScope scope, char **persistent, char **r
|
||||
return -EOPNOTSUPP;
|
||||
|
||||
default:
|
||||
assert_not_reached("Hmm, unexpected scope value.");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
*persistent = TAKE_PTR(a);
|
||||
@@ -657,7 +657,7 @@ int lookup_paths_init(
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached("Hmm, unexpected scope?");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (!add)
|
||||
@@ -807,7 +807,7 @@ char **generator_binary_paths(UnitFileScope scope) {
|
||||
break;
|
||||
|
||||
default:
|
||||
assert_not_reached("Hmm, unexpected scope.");
|
||||
assert_not_reached();
|
||||
}
|
||||
|
||||
if (!add)
|
||||
|
||||
@@ -245,7 +245,7 @@ struct cmsghdr* cmsg_find(struct msghdr *mh, int level, int type, socklen_t leng
|
||||
_len = sizeof(struct sockaddr_vm); \
|
||||
break; \
|
||||
default: \
|
||||
assert_not_reached("invalid socket family"); \
|
||||
assert_not_reached(); \
|
||||
} \
|
||||
_len; \
|
||||
})
|
||||
|
||||
@@ -58,7 +58,7 @@ do { \
|
||||
(void) va_arg(ap, long double); \
|
||||
break; \
|
||||
default: \
|
||||
assert_not_reached("Unknown format string argument."); \
|
||||
assert_not_reached(); \
|
||||
} \
|
||||
} \
|
||||
} while (false)
|
||||
|
||||
Reference in New Issue
Block a user