Skip to content

Commit

Permalink
Update null and zero division checks to avoid undefined behavior.
Browse files Browse the repository at this point in the history
  • Loading branch information
sammycage committed Sep 23, 2024
1 parent 03e47cc commit 6e138c0
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 11 deletions.
6 changes: 0 additions & 6 deletions source/graphics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -606,8 +606,6 @@ void Canvas::strokePath(const Path& path, const StrokeData& strokeData, const Tr

void Canvas::fillText(const std::u32string_view& text, const Font& font, const Point& origin, const Transform& transform)
{
if(text.empty() || font.isNull())
return;
plutovg_canvas_reset_matrix(m_canvas);
plutovg_canvas_translate(m_canvas, -m_x, -m_y);
plutovg_canvas_transform(m_canvas, &transform.matrix());
Expand Down Expand Up @@ -653,10 +651,6 @@ void Canvas::clipRect(const Rect& rect, FillRule clipRule, const Transform& tran

void Canvas::drawImage(const Bitmap& image, const Rect& dstRect, const Rect& srcRect, const Transform& transform)
{
if(dstRect.isEmpty() || srcRect.isEmpty()) {
return;
}

auto xScale = dstRect.w / srcRect.w;
auto yScale = dstRect.h / srcRect.h;
plutovg_matrix_t matrix = {xScale, 0, 0, yScale, -srcRect.x * xScale, -srcRect.y * yScale};
Expand Down
6 changes: 3 additions & 3 deletions source/svgelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -812,12 +812,12 @@ Rect SVGImageElement::strokeBoundingBox() const

void SVGImageElement::render(SVGRenderState& state) const
{
if(isDisplayNone() || isVisibilityHidden())
return;
if(!m_image.width() || !m_image.height())
if(m_image.isNull() || isDisplayNone() || isVisibilityHidden())
return;
Rect dstRect(fillBoundingBox());
Rect srcRect(0, 0, m_image.width(), m_image.height());
if(dstRect.isEmpty() || srcRect.isEmpty())
return;
m_preserveAspectRatio.transformRect(dstRect, srcRect);

SVGBlendInfo blendInfo(this);
Expand Down
2 changes: 1 addition & 1 deletion source/svggeometryelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ void SVGGeometryElement::updateMarkerPositions(SVGMarkerPositionList& positions,

void SVGGeometryElement::render(SVGRenderState& state) const
{
if(isVisibilityHidden() || isDisplayNone())
if(m_path.isNull() || isVisibilityHidden() || isDisplayNone())
return;
SVGBlendInfo blendInfo(this);
SVGRenderState newState(this, state, localTransform());
Expand Down
2 changes: 1 addition & 1 deletion source/svgtextelement.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ void SVGTextElement::layout(SVGLayoutState& state)

void SVGTextElement::render(SVGRenderState& state) const
{
if(isVisibilityHidden() || isDisplayNone())
if(m_text.empty() || isVisibilityHidden() || isDisplayNone())
return;
SVGBlendInfo blendInfo(this);
SVGRenderState newState(this, state, localTransform());
Expand Down

0 comments on commit 6e138c0

Please sign in to comment.