incorporate Spencer's fix so that this code works when using
the standard memchr()