Assert when creating nullptr spans with a nonzero length.
According to https://en.cppreference.com/w/cpp/container/span/span (2), it is undefined behavior if [first, first + count) is not a valid range, so it is standards-conforming to assert on this span. This caught one case in GlyphRun where we were creating an invalid span (which was apparently harmless in practice). Change-Id: Ia0661b3bd13c2c5773492960eea11b1a294072d5 Reviewed-on: https://skia-review.googlesource.com/c/skia/+/550499 Auto-Submit: John Stiles <johnstiles@google.com> Commit-Queue: Brian Osman <brianosman@google.com> Reviewed-by: Herb Derby <herb@google.com> Reviewed-by: Brian Osman <brianosman@google.com>
This commit is contained in:
parent
9be648ad64
commit
40e3b3c605
@ -26,6 +26,7 @@ class SkSpan {
|
||||
public:
|
||||
constexpr SkSpan() : fPtr{nullptr}, fSize{0} {}
|
||||
constexpr SkSpan(T* ptr, size_t size) : fPtr{ptr}, fSize{size} {
|
||||
SkASSERT(ptr || size == 0); // disallow nullptr + a nonzero size
|
||||
SkASSERT(size < kMaxSize);
|
||||
}
|
||||
template <typename U, typename = typename std::enable_if<std::is_same<const U, T>::value>::type>
|
||||
|
@ -263,12 +263,13 @@ const SkGlyphRunList& SkGlyphRunBuilder::blobToGlyphRunList(
|
||||
}
|
||||
}
|
||||
|
||||
const uint32_t* clusters = it.clusters();
|
||||
this->makeGlyphRun(
|
||||
font,
|
||||
glyphIDs,
|
||||
positions,
|
||||
SkSpan<const char>(it.text(), it.textSize()),
|
||||
SkSpan<const uint32_t>(it.clusters(), runSize),
|
||||
SkSpan<const uint32_t>(clusters, clusters ? runSize : 0),
|
||||
scaledRotations);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user