Skip to content

Calling toChar(0 / 0) causes e2 to crash. #3307

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

Open
nick100lay opened this issue Apr 21, 2025 · 0 comments
Open

Calling toChar(0 / 0) causes e2 to crash. #3307

nick100lay opened this issue Apr 21, 2025 · 0 comments

Comments

@nick100lay
Copy link

Describe the bug
Bug in lua/entities/gmod_wire_expression2/core/string.lua 122: e2function string toChar(number n).

Calling this with the NaN value causes a lua error, and e2 crashes.

To Reproduce
Steps to reproduce the behavior:

  1. Type the code toChar(0 / 0) in the e2 editor.
  2. Put the chip.
  3. It will show an error hint and crash.

Expected behavior
Possible fix:

e2function string toChar(number n)
	if n ~= n or n < 0 or n > 255 then -- Check on NaN and the byte range.
		return self:throw("Invalid argument (" .. n .. ") (must be between 0 and 255)", "")
	end
	return string_char(n)
end

Also, the check above should be added in 139: e2function string toUnicodeChar(number byte) and, maybe, in other places.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant