If s1_codex fails but s2_codex succeeds, we don't want to leak the
memory allocated to hold s2_codex. Ideally, we want to bail out before
computing s2_codex at all.
Actually, this patch does a bit more than that; it factors out the act
of computing a match rating codex and switches over to using
stack-allocated buffers where possible. This simplifies the memory
handling, shortens the code, and probably provides an insignificant
speedup.
If one of the characters had a value of 128 or above, this would be
treated as a signed char and would result in an array lookup with a
negative index. The somewhat contrived test case given here --
comparing a space with a non-breaking space -- reproduces the
segmentation fault prior to the fix.
This also makes a Clang warning go away. Thanks, compiler! :-)
If the second memory allocation fails, then we need to free the first.
While we're at it, the zeroing of allocated memory can be replaced by
a call to calloc().