Rexx is famous for its Math handling and this is a Math bug.
It may break someone's old code but that code is technically already broken. [#NETREXX-145] HashCode() math using char[] with length > 14 all cells = max char Description if using max char if using max char Pass hash * 7 (((int) (chars [i])) * 2)) ((int) (chars [(chars.length - i) - 1] )) hash exception 0 0 131072 65536 196608 1 1376256 131072 65536 1572864 2 11010048 131072 65536 11206656 3 78446592 131072 65536 78643200 4 550502400 131072 65536 550699008 5 3854893056 131072 65536 3855089664 Overflow 6 26985627648 131072 65536 26985824256 Overflow int.max 2147483647 The fix is already in two branchs. https://sourceforge.net/p/netrexx/code/ci/6ca99c887037559988181db9c77ce5256e768645/ https://sourceforge.net/p/netrexx/code/ci/2e668699db737ac733fc2742fcd700af839da5d4/ _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Hello Jason, I do find your mail quite interesting, but don't understand what has been the original problem/bug :-( Time and Energy to explain, please ? Thomas Schneider. ==================================================================================== Am 29.07.2018 um 15:42 schrieb Jason
Martin:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
In reply to this post by Jason Martin
-- OLD FUNCTION in Rexx.nrx NetRexx 3.06 and lower A sample as best I can remember problem, René commited the fix.-- -- 01 /** Return a hashcode for the value. -- 02 */ -- 03 method hashCode returns int -- 04 if chars=null then chars=layout() -- 05 if chars.length<14 then over=(chars.length+1)%2 -- 06 else over=7 -- 07 /* Hash the first and last OVER characters */ -- 08 hash=0 -- 09 loop i=0 to over-1 -- 10 hash=hash*7+int(chars[i])*2+int(chars[chars.length-i-1]) -- 11 end i -- 12 return hash -- MAX_LEGAL_JAVA_CHAR = Rexx char(Integer.MAX_VALUE) TRIGGER_ELSE_IN_LINE_06_ABOVE = MAX_LEGAL_JAVA_CHAR.copies(15) say TRIGGER_ELSE_IN_LINE_06_ABOVE.hashCode() --Program overflow.nrx --===== Exec: overflow ===== --1215608709 _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Sorry bad example.
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Jason Martin
MAX_LEGAL_JAVA_CHAR = Rexx char(Integer.MAX_VALUE)
TRIGGER_ELSE_IN_LINE_06_ABOVE = MAX_LEGAL_JAVA_CHAR.copies(15) -- Maybe not bad example but let us look at line 10 above -- Any char in the 15 copies will have a value of 65535 -- So int(chars[i]) will always be 65535 -- So int(chars[chars.length-i-1]) will always be 65535 hash=0 loop i=0 to 6 hash=hash*7+65535*2+65535 say "loop # :" i say "hash math :" hash -- say "TRY THIS hash math :" hash.toint() end say "IS YOUR HASH ONE OF THE #'s ABOVE? :" TRIGGER_ELSE_IN_LINE_06_ABOVE.hashCode() _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
In reply to this post by Jason Martin
Hello Jason, I don't yet understand *fully*, but *thanks for the answer* :-) Thomas Schneider. ================================================================== Am 31.07.2018 um 05:57 schrieb Jason
Martin:
_______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/
Thomas Schneider, Vienna, Austria (Europe) :-)
www.thsitc.com www.db-123.com |
In reply to this post by Jason Martin
-- I can think a little better today.
-- Copy all this and save and nrc -exec saved -- Then uncomment -- say "UNCOMMENT to see OVERFLOW :" hash.toint() -- Run again. MAX_LEGAL_JAVA_CHAR = Rexx char(Character.MAX_VALUE) say "int value of MAX_LEGAL_JAVA_CHAR : " MAX_LEGAL_JAVA_CHAR.c2d() -- Maybe not bad example but let us look at the MATH -- "hash=hash*7+int(chars[i])*2+int(chars[chars.length-i-1])" A_REXX_WITH_15_JAVA_MAX_CHARS = MAX_LEGAL_JAVA_CHAR.copies(15) -- Any of the 15 chars have a int value of 65535 -- So int(chars[i]) will always be 65535 -- So int(chars[chars.length-i-1]) will always be 65535 -- BEGIN SIMPLE LOOP MATH hash=0 loop i=0 to 6 hash=hash*7+65535*2+65535 say "loop # :" i say "hash math :" hash -- say "UNCOMMENT to see OVERFLOW :" hash.toint() end -- END SIMPLE LOOP MATH say "WAS THE HASH RETURNED, ONE FROM THE LOOP MATH ABOVE? :" A_REXX_WITH_15_JAVA_MAX_CHARS.hashCode() _______________________________________________ Ibm-netrexx mailing list [hidden email] Online Archive : http://ibm-netrexx.215625.n3.nabble.com/ |
Free forum by Nabble | Edit this page |