4 ms·
But the bug is not in that function, if a function accepts size_t, then that value can never be <0. If someone were to pass (size_t)-1 to it, it would still be
by wereHamster 6y ago
But the bug is not in that function, if a function accepts size_t, then that value can never be <0. If someone were to pass (size_t)-1 to it, it would still be positive. The issue is in the caller of the function, which must convert a negative value of a signed type into size_t, and that is the actual bug in this situation. Perhaps those conversions should trigger at least a compiler warning.
Asserting things which are given from the types is a waste. Or do you think we should assert that a value of type bool is really either true or false and fail the program otherwise?
- deleted 6y ago[deleted]