Several bug fixes discovered in valgrind runs

Two simple bugs: overlapping input and output fribidi strings; and, referencing a 4-byte field with an unsigned long pointer (would break on big-endian 64-bit).