logging: avoid null pointer dereference in loop

An execution path could reach a loop that dereferences a pointer in
conditions where the pointer is null.  Add a check to the loop
condition.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
1 file changed