I noticed the following today (I always see something new when
I look at K&R ..) , which doesn't seem to be on any errata
lists I can find.
In section 6.6 a hashing function is defined:
.. hash(s)
.. char *s;
.. {
.. int hashval;
..
.. for (hashval = 0; *s != '\0'; )
.. hashval += *s++;
.. return(hashval % HASHSIZE)
.. }
and later it is used: hashtab[hash(s)].
My observation is that s may contain chars with negative
values, making 'hashval' possibly negative. So the return
value could be negative too (p. 188 says "On all machines
covered by this manual, the remainder [of / or %] has the
same sign as the dividend").
So it causes undefined behaviour when hashtab is looked
up with a negative index.
Did this example make it into K&R2 ?