Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segmentation fault when handle array in nested procedure #40

Closed
Oleg-N-Cher opened this issue Aug 17, 2016 · 2 comments
Closed

Segmentation fault when handle array in nested procedure #40

Oleg-N-Cher opened this issue Aug 17, 2016 · 2 comments

Comments

@Oleg-N-Cher
Copy link

Arthur has found this bug. It present in Ofront, Ofront+ and voc. Yet I do not have a solution. Maybe you look, Dave?

MODULE SpeedTest;
IMPORT Out := Console;

(* VAR m: ARRAY 50 OF INTEGER; - If array is declared here - all is ok *)

PROCEDURE F3(n: INTEGER): INTEGER;
VAR i: INTEGER;
    m: ARRAY 50 OF INTEGER; (* Segmentation fault when handle m[45] *)

  PROCEDURE f(n: INTEGER): INTEGER;
  BEGIN
    Out.Ln; Out.String('DEBUG: f('); Out.Int(n, 0); Out.String(') = ...'); Out.Ln;
    Out.Int(m[n], 0); Out.Ln;
    IF m[n] = -1 THEN m[n] := f(n - 1) + f(n - 2) END;
    RETURN m[n]
  END f;

BEGIN
  FOR i := 3 TO LEN(m) - 1 DO m[i] := -1 END;
  m[1] := 1; m[2] := 1;
  RETURN f(n)
END F3;

BEGIN
  Out.String('START.'); Out.Ln;
  Out.String('F3(45) = '); Out.Int(F3(45), 0); Out.Ln
END SpeedTest.
@Oleg-N-Cher Oleg-N-Cher changed the title Segmentation fault when handle array in local procedure Segmentation fault when handle array in nested procedure Aug 17, 2016
@dcwbrown
Copy link
Contributor

An inner procedure accessing the local variable of an outer procedure.

That's different address calculation from either global or local
variables.

Was it working in OFront before you integrated my changes?

On 2016-08-17 23:13, Oleg N. Cher wrote:

Arthur has found this bug. It present in Ofront, Ofront+ and voc. Yet I do not have a solution. Maybe you look, Dave?

MODULE SpeedTest;
IMPORT Out := Console;

(* VAR m: ARRAY 50 OF INTEGER; - If array is declared here - all is ok *)

PROCEDURE F3(n: INTEGER): INTEGER;
VAR i: INTEGER;
m: ARRAY 50 OF INTEGER; (* Segmentation fault when handle m[45] *)

PROCEDURE f(n: INTEGER): INTEGER;
BEGIN
Out.Ln; Out.String('DEBUG: f('); Out.Int(n, 0); Out.String(') = ...'); Out.Ln;
Out.Int(m[n], 0); Out.Ln;
IF m[n] = -1 THEN m[n] := f(n - 1) + f(n - 2) END;
RETURN m[n]
END f;

BEGIN
FOR i := 3 TO LEN(m) - 1 DO m[i] := -1 END;
m[1] := 1; m[2] := 1;
RETURN f(n)
END F3;

BEGIN
Out.String('START.'); Out.Ln;
Out.String('F3(45) = '); Out.Int(F3(45), 0); Out.Ln
END SpeedTest.

You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub [1], or mute the thread [2].

Links:

[1] #40
[2]
https://github.com/notifications/unsubscribe-auth/ADChoHFD8vaPtpr62ne_Maa8Owg3cVuLks5qg4d8gaJpZM4Jm8V1

@Oleg-N-Cher
Copy link
Author

Dave, it's not your bug and not mine. It exists in original Ofront v1.3

I suppose it went unnoticed because of the fact that Josef and other Ofront users use nested procedures (as type-bound procedures) very little.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants