Fix end-of-string error

There was no space at the end of a string, so the search for a space
returned NULL. The math to get the length took the pointer at the end
of the word (NULL) and subtracted the pointer at the start of the word.
This resulted in a negative length being reported.

A quick hack to fix this is to make the min() function work with unsigned
ints only.