Add range checks when DEBUG_MEMORY