N
Nick Keighley
Bug: an instance of program behaviour that is not in the user's
reasonable expectation.
I think it's a bad idea to encourage users to expect defined
behaviour when a functions reasonable pre-condictions are
violated. reverse() operates on strings. NULL is not a string.
reverse(NULL) shouldn't have definend behaviour. This only
encourages people to rely on the behaviour.
There is no defined behaviour so I don't think
anyone should write code that relies on strlen(NULL)
doing anything in particular.
but may not on a system without memory protection
yes. But on a non-memory protected system it may be expensive
to detect.
and it could then return the length of the string it finds
at address zero.
yes. And I think reverse(NULL) is equally odd
reasonable expectation.
I think it's a bad idea to encourage users to expect defined
behaviour when a functions reasonable pre-condictions are
violated. reverse() operates on strings. NULL is not a string.
reverse(NULL) shouldn't have definend behaviour. This only
encourages people to rely on the behaviour.
There is no defined behaviour so I don't think
anyone should write code that relies on strlen(NULL)
doing anything in particular.
Depends on what you mean by "bug".
Anything strlen(NULL) does is consistent with the standard's
requirements. But as a quality-of-implementation issue, it *should*
either be written for maximum efficiency for non-NULL arguments (which
typically means that strlen(NULL) will trap),
but may not on a system without memory protection
or it should explicitly
check for NULL and abort (or possibly use some other system-specific
error reporting mechanism).
If I call strlen(NULL), that's a bug in my program.
yes
If the
implementation deliberately goes out of its way to hide that from me,
it's not being user-friendly, it's being programmer-hostile.
yes. But on a non-memory protected system it may be expensive
to detect.
and it could then return the length of the string it finds
at address zero.
In theory, you're right. In practice, returning 0 is unhelpful.
yes. And I think reverse(NULL) is equally odd