Add nullptr check in sdb_aforeach macros