added memcpy error check