Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix undefined behavior caused by a domain error on an sqrt call. #123

Merged
merged 1 commit into from
Mar 16, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion 3rdparty/plutovg/plutovg-blend.c
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

#include <limits.h>
#include <math.h>
#include <float.h>

#define COLOR_TABLE_SIZE 1024
typedef struct {
Expand Down Expand Up @@ -243,6 +244,7 @@ static void fetch_radial_gradient(uint32_t* buffer, const radial_gradient_values
while(buffer < end)
{
uint32_t result = 0;
det = fabs(det) < DBL_EPSILON ? 0.0 : det;
if(det >= 0)
{
double w = sqrt(det) - b;
Expand All @@ -261,7 +263,11 @@ static void fetch_radial_gradient(uint32_t* buffer, const radial_gradient_values
{
while(buffer < end)
{
*buffer++ = gradient_pixel(gradient, sqrt(det) - b);
det = fabs(det) < DBL_EPSILON ? 0.0 : det;
uint32_t result = 0;
if (det >= 0)
result = gradient_pixel(gradient, sqrt(det) - b);
*buffer++ = result;
det += delta_det;
delta_det += delta_delta_det;
b += delta_b;
Expand Down