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

Long numbers in list variable index are not working as expected #4729

Closed
1 task done
ghost opened this issue Apr 15, 2022 · 1 comment
Closed
1 task done

Long numbers in list variable index are not working as expected #4729

ghost opened this issue Apr 15, 2022 · 1 comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).

Comments

@ghost
Copy link

ghost commented Apr 15, 2022

Skript/Server Version

[Skript] Skript's aliases can be found here: https://github.com/SkriptLang/skript-aliases
[Skript] Skript's documentation can be found here: https://skriptlang.github.io/Skript
[Skript] Server Version: git-Paper-794 (MC: 1.16.5)
[Skript] Skript Version: 2.6.1
[Skript] Installed Skript Addons: None
[Skript] Installed dependencies: None

Bug Description

Two list variables in the form {var::%{index1}%::*} and {var::%{index2}%::*} are treated the same if {index1} and {index2} are large numbers. This occurs around 20 characters of digits, but I suspect that it is not a problem with the index string length being too large as the variables are distinct when the indexes are not numbers.

Expected Behavior

The variables {var::%{index1}%::*} and {var::%{index2}%::*} should always be different when {_index1} and {_index2} are not the same. In the tests, changing {var::%{index2}%::*} should not change {var::%{index1}%::*}

Steps to Reproduce

  1. Load the following script:
on load:
	set {digits::*} to "0123456789" split at ""
	set {letters::*} to "abcdefghijklmnopqrstuvwxyz" split at ""
	remove "" from {digits::*}
	remove "" from {letters::*}

function random_str(chars_addr: string, len: number) :: string:
	loop {_len} times:
		add random element of {%{_chars_addr}%::*} to {_str::*}
	return concat {_str::*}

function check(index1: string, index2: string) :: boolean:
	{_index1} != {_index2}
	delete {var::*}
	set {var::%{_index1}%::*} to 1
	set {var::%{_index2}%::*} to 2
	# {var::%{_index1}%::*} must not change because {_index1} != {_index2}
	return true if {var::%{_index1}%::*} = 1 else false

function test(chars_addr: string, len: number):
	set {_index1} to random_str({_chars_addr}, {_len})
	do while {_index2} = {_index1}:
		set {_index2} to random_str({_chars_addr}, {_len})
	set {_msg} to "works" if check({_index1}, {_index2}) = true else "broken!"
	broadcast "%{_chars_addr}%, %{_len}%: %{_msg}% (%{_index1}%; %{_index2}%)"

function test_all(chars_addr: string, len: numbers):
	loop {_len::*}:
		test({_chars_addr}, loop-value)
  1. Use the test functions:
test_all("digits", (numbers from 1 to 30))
test_all("letter", (numbers from 1 to 30))
  1. The "digits" test should fail at 20+ characters.

Errors or Screenshots

Output:
image
image

Other

No response

Agreement

  • I have read the guidelines above and affirm I am following them with this report.
@TPGamesNL TPGamesNL added bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation). labels Apr 15, 2022
@TPGamesNL
Copy link
Member

Caused by long parsing, which allows max ~19 digits (log_10(2^63-1)=18.96):

long n1 = Utils.parseLong("" + s1.substring(i, i2));
long n2 = Utils.parseLong("" + s2.substring(j, j2));

try {
return Long.parseLong(s);
} catch (final NumberFormatException e) {
return s.startsWith("-") ? Long.MIN_VALUE : Long.MAX_VALUE;
}

Utils.parseLong will return Long.MAX_VALUE for both numbers, therefore Skript will think them as equal.

Can be fixed by making variableNameComparator not rely on number parsing, instead doing the comparison by comparing things such as sign, length and digits

@TPGamesNL TPGamesNL self-assigned this Apr 20, 2022
@TPGamesNL TPGamesNL added the PR available Issues which have a yet-to-be merged PR resolving it label Apr 21, 2022
@TheLimeGlass TheLimeGlass added completed The issue has been fully resolved and the change will be in the next Skript update. and removed PR available Issues which have a yet-to-be merged PR resolving it labels Oct 20, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug An issue that needs to be fixed. Alternatively, a PR fixing an issue. completed The issue has been fully resolved and the change will be in the next Skript update. priority: medium Issues that are detrimental to user experience (prohibitive bugs or lack of useful implementation).
Projects
None yet
Development

No branches or pull requests

2 participants