[m-dev.] small bug fix to string.m
Fergus Henderson
fjh at cs.mu.oz.au
Fri May 16 02:18:56 AEST 1997
Christopher Rodd SPEIRS, you wrote:
>
> Fergus, could you please review this ...
> When looking at string__index, the comments stated that:
> % `Char' is the (`Index' + 1)-th character of `String'.
> % Fails if `Index' is out of range (negative, or greater than or
> % equal to the length of `String').
> but the code did not check if index was negative.
Nope, it did.
> :- pragma(c_code, string__index(Str::in, Index::in, Ch::out), "
> - if ((Word) Index >= strlen(Str)) {
> + if ((Word) Index >= strlen(Str) || (Word) Index < 0) {
`Word' is an unsigned type. The test `(Word) Index < 0' can
never succeed.
A better change would be to change the code to cast to `(Unsigned)'
rather than to `(Word)'. That would make the code a little bit
clearer. You might also want to add a comment.
--
Fergus Henderson <fjh at cs.mu.oz.au> | "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh> | of excellence is a lethal habit"
PGP: finger fjh at 128.250.37.3 | -- the last words of T. S. Garp.
More information about the developers
mailing list