[comp.sys.ibm.pc] Bug in TC 2.0 strrchr

poirier@ra.cs.unc.edu (Dan Poirier) (01/26/89)

Last night I discovered what I consider a bug in Turbo-C's strrchr()
function.  It searches a string back to front for a character.  In the
large model, if the string happens to begin at an offset of 0, the
search does not terminate properly due to pointer wrap-around (e.g.,
the pointer wraps from 0000 to FFFF and the termination test does
not work).

I know the manuals warn about this kind of problem in user-written code,
but it seems to me that Turbo-C's libraries should handle it properly,
and not fail just because a string variable happened to fall at a
particular offset.  Am I wrong?  Is there something I could/should have
done to avoid this kind of problem?

Thanks for any advice.
_dan

P.S. Turbo Debugger was quite helpful in tracking this down, even though
I had not used it before.
--------------------------------------------------------
Dan Poirier        UNC Chapel Hill    poirier@cs.unc.edu
Disclaimer: I saw it on the radio.
--------------------------------------------------------