Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by kccqzy on Thursday January 23, 2025 @09:03PM
(#42809897)
Well there's the so-called usual arithmetic conversions that will basically convert every uint16_t to an unsigned int. The C and C++ languages do a silent conversion on your back anyways so you might as well make it explicit.
[ Parent
| on HN ]
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by loeg on Thursday January 23, 2025 @11:37PM
(#42810579)
Usually promotions are to signed int, not unsigned. (With some exceptions. But every uint16_t value can fit in int.)
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by Filligree on Friday January 24, 2025 @07:22AM
(#42812428)
Unless int is 16-bit. Code like this is potentially UB; you should use int32_t as the target.
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by kevin_thibedeau on Friday January 24, 2025 @09:16AM
(#42813211)
You should use long, and don't ever assume it's exactly 32-bits. The fixed size types are often an overused crutch that hampers future portability.
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by loeg on Friday January 24, 2025 @12:41PM
(#42815479)
There are no mainstream 16-bit int platforms. It's fine to know what you target.
The promotions that are really surprising are from uint64_t bitfields to int (because it's based on value representability).
struct {
uint64_t a : 33,
b : 15;
} s;
// s.b gets "promoted" to int, s.a does not
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by inetknght on Thursday January 23, 2025 @09:10PM
(#42809920)
A well-configured C++ compiler will error-out on such a silent conversion.
Re:Susctl CVE-2024-54507: A particularly 'sus' sysctl in the...
by kccqzy on Thursday January 23, 2025 @09:23PM
(#42809969)
The C++ compiler is required to perform this silent conversion according to the standard: https://en.cppreference.com/w/cpp/language/implicit_conversi...