PR# 19636 STRING_32.hash_code may have negative values

Problem Report Summary
Submitter: gobobe
Category: EiffelBase
Priority: Medium
Date: 2020/04/15
Class: Bug
Severity: Non-critical
Number: 19636
Release: 20.03.10.3992
Confidential: No
Status: Analyzed
Responsible:
Environment: win
Synopsis: STRING_32.hash_code may have negative values

Description
When using invalid Unicode characters in STRING_32, the hash code may be negative. For example:

		local
			s: STRING_32
		do
			create s.make (1)
			s.append_character ({NATURAL_32}.max_value.to_character_32)
			print (s.hash_code)

prints -1. But the postcondition of `hash_code`says:

		good_hash_value: Result >= 0

In the Gobo libraries, the following pattern is used:

		Result := some_value_which_may_be_nagetive
		if Result < 0 then
			Result := -(Result + 1)
		end

--
Eric Bezault
To Reproduce

										
Problem Report Interactions