fix: static analysis fixes (#9918) c71be9b1a2

* fix: static analysis fixes

* Update packages/runtime/src/file.cpp

* chore: checking if glyph coverage broke test

* chore: try a different fix

Co-authored-by: Luigi Rosso <luigi-rosso@users.noreply.github.com>
Co-authored-by: hernan <hernan@rive.app>
This commit is contained in:
luigi-rosso
2025-06-05 21:48:13 +00:00
parent 9fc671c05f
commit e6e5e20faa
8 changed files with 25 additions and 8 deletions

View File

@@ -1 +1 @@
3aa5b93199675c7639d7b47a4b4814c99372ef3e
c71be9b1a22c8f1b7e8eba5b28c12660e111662c

View File

@@ -12,7 +12,16 @@ template <typename T> class TypedChild
public:
TypedChild(Core** child, Core** end) : m_child(child), m_end(end) {}
T* operator*() const { return (*m_child)->template as<T>(); }
T* operator*() const
{
auto child = *m_child;
if (child == nullptr)
{
return nullptr;
}
return child->template as<T>();
}
TypedChild& operator++()
{
m_child++;

View File

@@ -242,7 +242,7 @@ Vec2D ScrollConstraint::positionAtIndex(float index)
uint32_t i = 0;
Vec2D contentGap = gap();
float floorIndex = std::floor(index);
LayoutNodeProvider* lastChild;
LayoutNodeProvider* lastChild = nullptr;
for (auto child : content()->children())
{
auto c = LayoutNodeProvider::from(child);
@@ -261,6 +261,11 @@ Vec2D ScrollConstraint::positionAtIndex(float index)
i += count;
}
}
if (lastChild == nullptr)
{
return Vec2D();
}
auto bounds =
lastChild->layoutBoundsForNode((int)lastChild->numLayoutNodes() - 1);
return Vec2D(-bounds.left(), -bounds.top());

View File

@@ -261,7 +261,7 @@ ImportResult File::read(BinaryReader& reader, const RuntimeHeader& header)
// TODO: @hernan consider moving this to a special importer. It's not that
// simple because Core doesn't have a typeKey, so it should be treated as
// a special case. In any case, it's not that bad having it here for now.
Core* lastBindableObject;
Core* lastBindableObject = nullptr;
while (!reader.reachedEnd())
{
auto object = readRuntimeObject(reader, header);
@@ -332,6 +332,10 @@ ImportResult File::read(BinaryReader& reader, const RuntimeHeader& header)
}
else
{
if (lastBindableObject == object)
{
lastBindableObject = nullptr;
}
fprintf(stderr,
"Failed to import object of type %d\n",
object->coreType());

View File

@@ -132,6 +132,7 @@ void LinearGradient::applyTo(RenderPaint* renderPaint, float opacityModifier)
parent()->as<ShapePaint>()->isFlagged(PathFlags::world);
Vec2D start(startX(), startY());
Vec2D end(endX(), endY());
// Check if we need to update the world space gradient (if there's no
// shape container, presumably it's the artboard and we're already in
// world).
@@ -150,7 +151,7 @@ void LinearGradient::applyTo(RenderPaint* renderPaint, float opacityModifier)
}
else
{
if (m_deformer)
if (m_deformer && m_shapePaintContainer != nullptr)
{
const Mat2D& world = m_shapePaintContainer->worldTransform();
Mat2D inverseWorld;

View File

@@ -87,7 +87,6 @@ void FullyShapedText::shape(Span<Unichar> text,
isEllipsisLineLast = lastLineIndex == ellipsisLine;
int32_t lineIndex = 0;
paragraphIndex = 0;
m_bounds =
AABB(0.0f, minY, measuredWidth, std::max(minY, y - paragraphSpacing));

View File

@@ -189,7 +189,6 @@ void RawText::update()
isEllipsisLineLast = lastLineIndex == ellipsisLine;
int lineIndex = 0;
paragraphIndex = 0;
switch (m_sizing)
{
case TextSizing::autoWidth:

View File

@@ -134,7 +134,7 @@ float TextModifierGroup::glyphCoverage(uint32_t textIndex,
{
c += coverage(textIndex + i);
}
return c /= (float)codePointCount;
return c / (float)codePointCount;
}
void TextModifierGroup::onTextWorldTransformDirty()