core: fix integer truncation checks
Use explicit bounds checks for size_t and long conversions
so compilers cannot optimize away round-trip cast checks.
Follow-up for 78238fd7c9.
This commit is contained in:
committed by
Yu Watanabe
parent
f969973b90
commit
31ef154f15
@@ -159,11 +159,11 @@ const sd_bus_vtable bus_socket_vtable[] = {
|
||||
};
|
||||
|
||||
static bool check_size_t_truncation(uint64_t t) {
|
||||
return (size_t) t == t;
|
||||
return t <= SIZE_MAX;
|
||||
}
|
||||
|
||||
static bool check_long_truncation(int64_t t) {
|
||||
return (int64_t) (long) t == t;
|
||||
return t <= LONG_MAX && t >= LONG_MIN;
|
||||
}
|
||||
|
||||
static const char* socket_protocol_to_string(int32_t i) {
|
||||
|
||||
@@ -992,7 +992,7 @@ int config_parse_iec_size(
|
||||
assert(rvalue);
|
||||
|
||||
r = parse_size(rvalue, 1024, &v);
|
||||
if (r >= 0 && (uint64_t) (size_t) v != v)
|
||||
if (r >= 0 && v > SIZE_MAX)
|
||||
r = -ERANGE;
|
||||
if (r < 0)
|
||||
return log_syntax_parse_error(unit, filename, line, r, lvalue, rvalue);
|
||||
|
||||
Reference in New Issue
Block a user