Forum: GHDL Bug in std.textio.read (string)

Posted by Thomas Sailer (Guest)
on 2009-05-26 17:30
(Received via mailing list)
in:
procedure read (l: inout line; value: out string; good: out boolean)

When l is (a pointer to) string(1 to 1) (eg. after write(l, a
character)), and then I am trying to read a string of one character from
l, I get a runtime error.

The reason is that because l'left < l'right is false (l'ascending cannot
be used, since ascending does not exist in VHDL-87), value := l (1
downto 1) further down, which fails, because the array direction is to
(and not downto).

The attached patch seems to fix this.

Tom
Posted by Tristan Gingold (Guest)
on 2009-05-28 21:13
(Received via mailing list)
On Tue, May 26, 2009 at 05:22:41PM +0200, Thomas Sailer wrote:
> (and not downto). 
Hi,

thank you for the report.  This looks like a bug.  I will re-read the 
code
as I'd like to avoid an additional 'if'.

Tristan.
Posted by Thomas Sailer (Guest)
on 2009-05-28 22:27
(Received via mailing list)
On Thu, 2009-05-28 at 21:11 +0200, Tristan Gingold wrote:

> thank you for the report.  This looks like a bug.  I will re-read the code
> as I'd like to avoid an additional 'if'.

'ascending would avoid the additional if, but I have no idea how to
avoid that for VHDL-87.

Tom
Posted by Tristan Gingold (Guest)
on 2009-06-08 03:59
(Received via mailing list)
On Tue, May 26, 2009 at 05:22:41PM +0200, Thomas Sailer wrote:
> (and not downto). 
Hi Thomas,

thank you for this bug report and the analysis.  As you said, we can't 
avoid
the test.  I have put the test at the same level as the other one (see
patch below).

Nice catch!

Tristan.


Index: textio_body.vhdl
===================================================================
--- textio_body.vhdl  (revision 2000)
+++ textio_body.vhdl  (working copy)
@@ -1304,10 +1304,18 @@
     if len = 0 then
       return;
     end if;
-    if l'left < l'right then
+    if l'left = l'right then
+      --  String of 1 character.  We don't know the direction and 
therefore
+      --  can't use the code below which does a slice.
+      value := l.all;
+      deallocate (l);
+      l := new string'("");
+    elsif l'left < l'right then
+      --  Ascending.
       value := l (l'left to l'left + len - 1);
       trim (l, l'left + len);
     else
+      --  Descending.
       value := l (l'left downto l'left - len + 1);
       trim (l, l'left - len);
     end if;
This topic is locked and can not be replied to.