fix overflow when a history entry ends with '^'