-
-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix stack corruption when function returns pointer to its argument
- Loading branch information
Showing
3 changed files
with
46 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
entity func25 is | ||
end entity; | ||
|
||
architecture test of func25 is | ||
|
||
function change_bounds (s : string; l, r : positive) return string is | ||
alias ss : string(l to r) is s; | ||
begin | ||
return ss; | ||
end function; | ||
|
||
impure function get_string (c : character) return string is | ||
variable s : string(1 to 15); | ||
begin | ||
s := "hello, world! " & c; | ||
return change_bounds(s, 101, 115); -- Returns a pointer to S | ||
end function; | ||
|
||
function get_left (s : string) return positive is | ||
begin | ||
return s'left; | ||
end function; | ||
|
||
signal c : character := 'x'; | ||
|
||
begin | ||
|
||
p1: process is | ||
begin | ||
wait for 1 ns; | ||
report get_string(c); | ||
assert get_string(c) = "hello, world! x"; | ||
assert get_left(get_string(c)) = 101; | ||
wait; | ||
end process; | ||
|
||
end architecture; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -851,3 +851,4 @@ driver18 normal,2008 | |
vhpi9 normal,vhpi | ||
issue730 normal,2008 | ||
driver19 normal,2008 | ||
func25 normal |