Re: Bug in class READABLE_STRING_8

Wolfgang Jansen <[email protected]> Fri, 25 Nov 2016 10:37:49 +0100
Newsgroups gmane.comp.lang.eiffel.gobo.devel
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--===============0307429408675887265==
Content-Type: multipart/alternative;
	boundary="------------7F068C47A31265DE0CEFB38A"

This is a multi-part message in MIME format.
--------------7F068C47A31265DE0CEFB38A
Content-Type: text/plain; charset=windows-1252; format=flowed
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by smtpa.mediabeam.com id
	uAP9bnx9011017

On 24/11/16 23:51, Wolfgang Jansen wrote:
>
> Hi Eric,
>
> I found an fatal error in routine READABLE_STRING_8.copy if the=20
> argument is a non-void but empty string. The origin text is as follows:
>
>     copy (other: like Current)
>             -- Reinitialize by copying the characters of `other'.
>             -- (This is also used by `twin'.)
>         local
>             old_area: like area
>         do
>             if other /=3D Current then
>                 old_area :=3D area
>                 standard_copy (other)
>                     -- Note: <=3D is needed as all Eiffel string should=
=20
> have an
>                     -- extra character to insert null character at the=20
> end.
>                 if old_area =3D Void or else old_area =3D other.area or=
=20
> else old_area.count <=3D count then
>                         -- Prevent copying of large `area' if only a=20
> few characters are actually used.
>                     area :=3D area.resized_area (count + 1)
>                 else
>                     old_area.copy_data (area, 0, 0, count)
>                     area :=3D old_area
>                 end
>                 internal_hash_code :=3D 0
>             end
>         ensure then
>             new_result_count: count =3D other.count
>             -- same_characters: For every `i' in 1..`count', `item'=20
> (`i') =3D `other'.`item' (`i')
>         end
>
>
> If the string to copy is empty, i.e. `old_area=3DVoid' then `area' is=20
> void, too,
> after `standard_copy'. Then branch `if old_area=3DVoid or else ...'=20
> leads to instruction `area :=3D area.resized_area (count + 1)' that mus=
t=20
> crash. I propose the following modification (it works fine for me):
>
>
>     copy (other: like Current)
>             -- Reinitialize by copying the characters of `other'.
>             -- (This is also used by `twin'.)
>         local
>             old_area: like area
>         do
>             if other /=3D Current then
>                 old_area :=3D area
>                 standard_copy (other)
>                     -- Note: <=3D is needed as all Eiffel string should=
=20
> have an
>                     -- extra character to insert null character at the=20
> end.
>                 if old_area =3D Void then
>                 elseif old_area =3D other.area or else old_area.count <=
=3D=20
> count then
>                         -- Prevent copying of large `area' if only a=20
> few characters are actually used.
>                     area :=3D area.resized_area (count + 1)
>                 else
>                     old_area.copy_data (area, 0, 0, count)
>                     area :=3D old_area
>                 end
>                 internal_hash_code :=3D 0
>             end
>         ensure then
>             new_result_count: count =3D other.count
>             -- same_characters: For every `i' in 1..`count', `item'=20
> (`i') =3D `other'.`item' (`i')
>         end
>
>
> I do not know whether the bug is already in ISE's distribution of the=20
> class.
>
> Best regards
> Wolfgang
>
> --=20
> Dr. Wolfgang Jansen
> Lauenburger Stra=DFe 40
> D-12169 Berlin
>
> Tel: (+49) 0172 40 86 916
> e-mail:[email protected]
>
>
> -----------------------------------------------------------------------=
-------
>
>
> _______________________________________________
> gobo-eiffel-develop mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop

Sorry, I introduced another bug into the routine, now it fails if the=20
target string was empty.
We need to guard both possibilities: the target is empty or the source=20
is empty. The improved improvement of the critical lines reads as follows=
:

                 if area =3D Void then
                     -- Nothing to copy or modify.
                 elseif old_area =3D Void or else old_area.count <=3D cou=
nt=20
or else old_area =3D area then
                     -- Prevent copying of large `area' if only a few=20
characters are actually used.
                     area :=3D area.resized_area (count + 1)
                 else
                     old_area.copy_data (area, 0, 0, count)
                     area :=3D old_area
                 end

The `if' condition guards the call in the `elseif' branch, the left=20
`elseif' condition guards the following call and the call in the `else'=20
branch. What case ever occurs, the target has at least as many=20
characters as needed, all characters of the source are copied, and=20
`count' is set correctly.

--=20
Dr. Wolfgang Jansen
Lauenburger Stra=DFe 40
D-12169 Berlin

Tel: (+49) 0172 40 86 916
e-mail: [email protected]


--------------7F068C47A31265DE0CEFB38A
Content-Type: text/html; charset=windows-1252
Content-Transfer-Encoding: quoted-printable
X-MIME-Autoconverted: from 8bit to quoted-printable by smtpa.mediabeam.com id
	uAP9bnx9011017

<html>
  <head>
    <meta content=3D"text/html; charset=3Dwindows-1252"
      http-equiv=3D"Content-Type">
  </head>
  <body bgcolor=3D"#FFFFFF" text=3D"#000000">
    <div class=3D"moz-cite-prefix">On 24/11/16 23:51, Wolfgang Jansen
      wrote:<br>
    </div>
    <blockquote
      cite=3D"mid:[email protected]"
      type=3D"cite">
      <meta http-equiv=3D"content-type" content=3D"text/html;
        charset=3Dwindows-1252">
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">Hi Eric, <br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">I found an fatal err=
or
          in routine READABLE_STRING_8.copy if the argument is a
          non-void but empty string. The origin text is as follows:</font=
></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">=A0=A0=A0 copy (othe=
r: like
          Current)<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Reinitialize by copying the ch=
aracters of
          `other'.<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- (This is also used by `twin'.)=
<br>
          =A0=A0=A0 =A0=A0=A0 local<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area: like area<br>
          =A0=A0=A0 =A0=A0=A0 do<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if other /=3D Current then<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area :=3D area<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 standard_copy (other)<b=
r>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Note: &lt;=
=3D is needed as all Eiffel
          string should have an<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- extra char=
acter to insert null
          character at the end.<br>
          <font color=3D"#ff0000">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=
 if old_area =3D Void or
            else old_area =3D other.area or else old_area.count &lt;=3D
            count then<br>
            =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -=
- Prevent copying of large `area'
            if only a few characters are actually used.<br>
            =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D a=
rea.resized_area (count + 1)<br>
          </font>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 else<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area.copy=
_data (area, 0, 0, count)<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D old=
_area<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 end<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 internal_hash_code :=3D=
 0<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 end<br>
          =A0=A0=A0 =A0=A0=A0 ensure then<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 new_result_count: count =3D other=
..count<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- same_characters: For every `i'=
 in 1..`count',
          `item' (`i') =3D `other'.`item' (`i')<br>
          =A0=A0=A0 =A0=A0=A0 end<br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1"><br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">If the string to cop=
y
          is empty, i.e. `old_area=3DVoid' then `area' is void, too, <br>
          after `standard_copy'. Then branch `if old_area=3DVoid or else
          ...' leads to instruction `area :=3D area.resized_area (count +
          1)' that must crash. I propose the following modification (it
          works fine for me):<br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1"><br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">=A0=A0=A0 copy (othe=
r: like
          Current)<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Reinitialize by copying the ch=
aracters of
          `other'.<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- (This is also used by `twin'.)=
<br>
          =A0=A0=A0 =A0=A0=A0 local<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area: like area<br>
          =A0=A0=A0 =A0=A0=A0 do<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if other /=3D Current then<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area :=3D area<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 standard_copy (other)<b=
r>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Note: &lt;=
=3D is needed as all Eiffel
          string should have an<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- extra char=
acter to insert null
          character at the end.<br>
          <font color=3D"#ff0000">=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0=
 if old_area =3D Void then<br>
            =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 elseif old_area =3D o=
ther.area or else
            old_area.count &lt;=3D count then<br>
            =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -=
- Prevent copying of large `area'
            if only a few characters are actually used.<br>
            =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D a=
rea.resized_area (count + 1)<br>
          </font>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 else<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area.copy=
_data (area, 0, 0, count)<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D old=
_area<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 end<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 internal_hash_code :=3D=
 0<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 end<br>
          =A0=A0=A0 =A0=A0=A0 ensure then<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 new_result_count: count =3D other=
..count<br>
          =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- same_characters: For every `i'=
 in 1..`count',
          `item' (`i') =3D `other'.`item' (`i')<br>
          =A0=A0=A0 =A0=A0=A0 end<br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1"><br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">I do not know whethe=
r
          the bug is already in ISE's distribution of the class. <br>
        </font></p>
      <font size=3D"-1"> </font>
      <p><font face=3D"DejaVu Sans Mono" size=3D"-1">Best regards<br>
          Wolfgang</font><br>
      </p>
      <pre class=3D"moz-signature" cols=3D"72">--=20
Dr. Wolfgang Jansen
Lauenburger Stra=DFe 40
D-12169 Berlin

Tel: (+49) 0172 40 86 916
e-mail: <a moz-do-not-send=3D"true" class=3D"moz-txt-link-abbreviated" hr=
ef=3D"mailto:[email protected]">[email protected]</a></pre>
      <br>
      <fieldset class=3D"mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap=3D"">----------------------------------------------------=
--------------------------
</pre>
      <br>
      <fieldset class=3D"mimeAttachmentHeader"></fieldset>
      <br>
      <pre wrap=3D"">_______________________________________________
gobo-eiffel-develop mailing list
<a class=3D"moz-txt-link-abbreviated" href=3D"mailto:gobo-eiffel-develop@=
lists.sourceforge.net">[email protected]</a>
<a class=3D"moz-txt-link-freetext" href=3D"https://lists.sourceforge.net/=
lists/listinfo/gobo-eiffel-develop">https://lists.sourceforge.net/lists/l=
istinfo/gobo-eiffel-develop</a>
</pre>
    </blockquote>
    <br>
    <p>Sorry, I introduced another bug into the routine, now it fails if
      the target string was empty. <br>
      We need to guard both possibilities: the target is empty or the
      source is empty. The improved improvement of the critical lines
      reads as follows: <br>
    </p>
    <p>=A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 if area =3D Void then<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Nothing to cop=
y or modify.<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 elseif old_area =3D Void or=
 else old_area.count
      &lt;=3D count or else old_area =3D area then<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 -- Prevent copyin=
g of large `area' if only a
      few characters are actually used.<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D area.re=
sized_area (count + 1)<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 else<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 old_area.copy_dat=
a (area, 0, 0, count)<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 area :=3D old_are=
a<br>
      =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 =A0=A0=A0 end<br>
      <br>
    </p>
    <p>The `if' condition guards the call in the `elseif' branch, the
      left `elseif' condition guards the following call and the call in
      the `else' branch. What case ever occurs, the target has at least
      as many characters as needed, all characters of the source are
      copied, and `count' is set correctly. <br>
    </p>
    <pre class=3D"moz-signature" cols=3D"72">--=20
Dr. Wolfgang Jansen
Lauenburger Stra=DFe 40
D-12169 Berlin

Tel: (+49) 0172 40 86 916
e-mail: <a class=3D"moz-txt-link-abbreviated" href=3D"mailto:wo.jansen@ka=
belmail.de">[email protected]</a></pre>
  </body>
</html>

--------------7F068C47A31265DE0CEFB38A--



--===============0307429408675887265==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

------------------------------------------------------------------------------

--===============0307429408675887265==
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
gobo-eiffel-develop mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/gobo-eiffel-develop

--===============0307429408675887265==--