Make LIST_FOR_EACH[_SAFE] variable take logically correct value upon loop termination. Also, add regression tests for linked list routines, to ensure that this change does not break code. Also, add new macro LIST_FOR_EACH_REVERSE.
The previous definition had a syntax error that prevented it from working.