@safe leak fix?

dsimcha dsimcha at yahoo.com
Thu Nov 12 08:39:34 PST 2009


== Quote from Don (nospam at nospam.com)'s article
> There are definitely functions which are dangerous if you pass them
> invalid parameters. ie, "use at own risk" -- any function which uses
> them needs to add its own tests. I think something which implies "you
> should think before you use this function" is reasonable.
> I don't care at all what the name is, however. @system would be OK.

Yeah, and sometimes the functions that are unsafe when passed invalid parameters
aren't obvious.  Granted this is an extreme corner case, but I recently debugged
an access violation that was occurring in a well-tested sorting function that I
would have definitely annotated @trusted.  I was sorting on floating point keys,
and it turned out there were NaNs in there and the sort function assumed that
there would be a proper total ordering.  If the pivot element was a NaN, it would
therefore enter an endless loop because there was nothing in the array that was <=
the pivot, until it read past the end of the array.  This was a latent bug for a
long time and only showed up when I ran the program with parameters that generated
NaNs.

Of course the real solution here is to get rid of the #()&# lack of total ordering
for floats.



More information about the Digitalmars-d mailing list