Add missing condition check in for loop Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/4255>