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

Xpressive instrument may crash due to overflow #5877

Open
PhysSong opened this issue Jan 9, 2021 · 2 comments
Open

Xpressive instrument may crash due to overflow #5877

PhysSong opened this issue Jan 9, 2021 · 2 comments
Labels
bug development branch This issue affects the development branch(master)

Comments

@PhysSong
Copy link
Member

PhysSong commented Jan 9, 2021

You can reproduce the crash by playing with the preset. If you don't get crashes, try changing the numbers in the O1 tab.
crash3.xpf.zip

The positiveFraction function defined in ExprSynth.h may return a unexpected value if the input value is out of the range of int but still finite. This result in overflows when casting to int and make WaveValueFunction::operator() crash.

@PhysSong PhysSong added bug development branch This issue affects the development branch(master) labels Jan 9, 2021
@gnudles
Copy link
Contributor

gnudles commented Jun 4, 2023

Good point. We shall rewrite it as

inline float positiveFraction(float x)
{
	if (std::isnan(x) || std::isinf(x))
		return 0;
	float integral;
	x = modff(x, &integral);
	if (x<0)
	{
		x+=1;
	}
	return x;
}

Right?
Can you do the patch?

@PhysSong
Copy link
Member Author

PhysSong commented Jun 4, 2023

I think modff should be std::modf for consistency. Otherwise looks good.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug development branch This issue affects the development branch(master)
Projects
None yet
Development

No branches or pull requests

2 participants