check if origin->segments is NULL, Avoid crashes

check if origin->segments is NULL, Avoid crashes