Re: NOWHERE, NOBODY, NOTHING tests...

From: Peter Ajamian (peter@pajamian.dhs.org)
Date: 03/05/01


"Daniel A. Koepke" wrote:
>
> On Mon, 5 Mar 2001, Peter Ajamian wrote:
>
> > Most places where these values are tested do so to avoid crashing the
> > MUD by indexing an array with a negative value.
>
> The point is that someone might not be using arrays or might not be
> indexing them with real numbers.  Thus, we should not assume that these
> are going to be used for indexing arrays.  Or, really, how they're going
> to be used.

Excuse me?  Unless you're looking at a different CircleMUD source than I
am (and I'm looking at the the latest CVS revision as of about, oh, 30
seconds ago) There are several places where NOWHERE, NOBODY, or NOTHING
is checked in the _stock_ source right before indexing an array with the
variable that it's checked against.  How can you possibly say that
someone might not be using them?  The facts are that they are used as
tests before indexing an array, and that it is possible for the
variables they're tested against to have a negative value and still
bypass the test.

>  The macros you suggested will just hide the faulty
> assumption, rather than replacing it.

Look at the very last macro I suggested, if the variable tested is
NOWHERE it returns TRUE (indicating that it IS_NOWHERE), if the variable
is >= 0 it returns FALSE, otherwise (the variable is < 0 and != NOWHERE)
it logs a SYSERR and then returns TRUE, the idea being that by doing so
it will prevent a crash (from the code trying to index an array with the
variable) and it will also alert the implementor to the situation with
the SYSLOG (which I would hardly call hiding the faulty assumption).

Note also that the argument that someone may in the future make usage of
other negative numbers does not hold up because it is easy to change the
macros to accomodate that, nor does the argument that you may switch to
an unsigned type for the same reason.

>  We don't honestly want '< 0'
> anywhere.  The mud should use the appropriate NOWHERE/NOTHING/NOBODY
> constant rather than any negative number.

And with that you run a sore risk of giving a false sense of security
with the test while still having the possibility of indexing an array
with the negative number.

Also note that setting up a macro for
IS_NOWHERE()/IS_NOTHING()/IS_NOBODY() will accomplish the same thing
with the same ease of portability and allow testing for conditions that
a simple == NOWHERE/NOTHING/NOBODY can't possibly allow for.

> Anyway, I think the technical arguments on this are sparse and won't hold
> up to much scrutiny.

Depends who's doing the scrutinizing.

>  It's a judgement call.

Well, in the past I have seen similar issues lean towards protecting the
newbie coder from themselves (case-in-point, having a dummy_mob variable
instead of simply setting it to NULL).  Are you now saying that you will
change that position?

>  But without any compelling
> reason to change it from my perspective, I, at least, will uphold the
> status quo and leave it be.

*Shrug*, Suit yourself.

Regards, Peter

--
   +---------------------------------------------------------------+
   | FAQ: http://qsilver.queensu.ca/~fletchra/Circle/list-faq.html |
   | Archives: http://post.queensu.ca/listserv/wwwarch/circle.html |
   +---------------------------------------------------------------+



This archive was generated by hypermail 2b30 : 12/04/01 PST