prevent infinite loop and memcpy of negative amounts