Color Class has a bug

Frank Shearar frank.shearar at angband.za.org
Fri Nov 10 08:24:37 UTC 2006


<ncellier at ifrance.com> wrote:

> I did not concentrate enough on Frank Shearar message.
> He got it right.
>
> Color>>formString: implementationrely on the fact that an error is
generated.
>
> '16rYELLOW' asNumber did generate a bug in 3.8, no more in 3.9.
>
> Note that this is half lucky, because in many cases, String>>asNumber is
very permissive.
>   '' asNumber = 0
>   '16r' asNumber = 0
>   '16rX' asNumber ERROR

Yes, and '16rEX' asNumber = 14.

So #fromString: splits 'orange' into 'or' (which is 0, according to
#asNumber), 'an' (or 10') and 'ge' (or 0).

Perhaps the thing to do is to change the condition to

  [aColorHex isColorTriple
    ifTrue:
      [aColorHex _ aColorHex asUppercase.
      ...

where String>>isColorTriple looks like

isColorTriple
  self do: [c: | c isHex ifFalse: [^ false]].
  ^(self size = 6).

and Character>>isHex is defined appropriately.

frank




More information about the Squeak-dev mailing list