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 (core dumped) #37

Closed
jupvfranco opened this issue Sep 19, 2014 · 1 comment
Closed

Segmentation fault (core dumped) #37

jupvfranco opened this issue Sep 19, 2014 · 1 comment

Comments

@jupvfranco
Copy link

I have a program with

  • a Worker with 1 method init(), which does not do anything,
  • a Master, which prints all the elements of a list.
  • This list is a List of Nodes, where each node has a Number (the element printed)

If the size of the list is <= 245 then the elements are printed correctly. With a size > 245 I get a segmentation fault and, as you can see in the file output.txt, some of the numbers printed are not in the list.

I have a method invocation worker.init(); in the main. if I remove it, then I have the expected result.
There is also a similar list with some numbers that I do not use. But if I remove the lines 13-16 (they add a number to this list) there is no seg fault.

You can find the code (SegFault.enc) and result (output.txt) here:
https://www.dropbox.com/sh/jhocug46ugv3hse/AADnyHApsKUJvYMTo1E74SZ1a?dl=0

Any idea why this is happening?

Thanks,
Juliana

@kikofernandez
Copy link
Contributor

This has been fixed in the new implementation. I have refactored the code to make it work.

class Main 

  def main() : void {
    let i = 2
    limit = 246-- seg fault with 246
    list1 = new List()
    list2 = new List()
    in {
      -- if we remove the following code (let n2 ... {}) 
      --then we do not get a seg faul
      let n2 = new Number(2) in {
          list1.add(n2);
      };

      while i <= limit {
    let n = new Number(i)
            m = new Number(i+2)
        in {
            list1.add(n);
        list2.add(m);
    };
        i = i + 4;
      };

       let worker = new Worker()
       master = new Master(list2)
       in {
      -- if we remove the following method invocation, we do not get seg fault
       master.work(); 
       ()
    }
    }
  }


class Worker 
  def init(): void {
    ()
  }

class Master 

  my_list: List

  def init(list: List): void {
    this.my_list = list;
  }

  def work(): void {

    let cur = this.my_list.head 
    in { 
    while cur != null { 
      print cur.number.n;
          cur = cur.tail;
    };

    };    
  }



-----------------------------
-- passive code
-----------------------------

-- a list is a class of numbers
passive class List {
  head: Node

  def init() : void {
    this.head = null;
  }

  -- add a number to the tail of the list
  def add(n: Number) : void {
    if this.head == null then {
      this.head = new Node(n, null);
    } else  
      this.head.add(n);
  }
}

passive class Node {
  number: Number
  tail: Node

  def init(new_number: Number, new_tail: Node) : void {
      this.number = new_number;
      this.tail = new_tail;
  }

  def add(n: Number) : void {
    if this.tail == null then {
      this.tail = new Node(n, null);
    } else
      this.tail.add(n);
  }
}

passive class Number {
  n: int

  def init(nn: int) : void {
    this.n = nn;
  }
}

The output that I get prints up to 248.

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