a2m.cpp: Fix crashes and hangs in decode()
a2m.cpp: Fix crashes and hangs in decode()

Fix transposed digits in MAXDISTANCE. The correct value is
21839, not 21389. (That was hard to spot!) This typo could
cause k to wrap around to a value near 64k, way out of bounds
to access buf.

Also stop decoding when input or output buffers are exhausted
instead of wrapping around to the beginning to avoid possibly
endless hangs in such cases.

This commit fixes crashes and hangs for the following fuzzing
samples:
  i-110_005.a2m, i-110_009.a2m, i-110_038.a2m, i-110_041.a2m,
  i-110_042.a2m, i-110_045.a2m, i-110_073.a2m, i-110_107.a2m,
  i-110_124.a2m, i-110_126.a2m, i-110_138.a2m, i-110_157.a2m,
  i-110_159.a2m, i-110_168.a2m.

The following fuzzing samples now load successfully, but crash
or hang during playback:
  i-110_006.a2m, i-110_007.a2m, i-110_010.a2m, i-110_011.a2m,
  i-110_075.a2m, i-110_076.a2m, i-110_077.a2m, i-110_078.a2m,
  i-110_091.a2m.

Bug: https://github.com/adplug/adplug/issues/110

adplug/adplug,adplug/adplug