by inetknght · 1y ago · 0 comments
- int new_value = *(int *)oidp->oid_arg1;
+ int new_value = *(uint16_t *)oidp->oid_arg1;
Why not just have `uint16_t new_value = ...`?Ahh, because `new_value` is being given to `sysctl_handle_int(..., &new_value, ...);` which of course expects an `int`. So then it begs the question: if the value is really a `uint16_t`, then why is it being handled through a plain `int`? It smells like there could easily be tons of other memory-safety and/or type confusion problems endemic to the sysctl API.
I don't think it begs the question, but it does raise one!
The phrase can be confusing because of its overloaded definitions, so it's best to avoid it. But if you understood what someone meant when they used it, then... you understood it's meaning.
Remember to treat the study of language descriptively rather than prescriptively!
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