Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
MB-37956: makeCollectionID/makeScopeID should use gsl::narrow<>
We currently use narrow_cast<> to cast a ManifestUid to a ScopeID or CollectionID. But this doesn't throw if the value can't be fitted into narrower value. So we should use gsl::narrow<> which will throw if the value can't be fitted into the narrow value. gsl::narrow will cast to ScopeIDType and CollectionIDType first as this gives us the benefit of also throwing if the conversion can't be done. Then creating a ScopeID and CollectionID object (We perform the gsl::narrow<> to the underlying type first so that we don't need to implement extra operators that gsl::narrow requires). Any narrowing exceptions throw will be caught and re-thrown as an std::invalid_argument() exception. This issue was found as gsl::narrow_cast<> is marked noexcept in gsl-lite 0.38.1. Which caused us to crash due to ScopeID and CollectionID throwing in the constructor. Change-Id: Ie220f3d80c851d1b78d39916898f2c5e8aef7e87 Reviewed-on: http://review.couchbase.org/c/kv_engine/+/154775 Reviewed-by: Dave Rigby <daver@couchbase.com> Tested-by: Build Bot <build@couchbase.com>
- Loading branch information