Skip to content

runtime.Caller crashes on large inputs #176

@rsc

Description

@rsc
From the documentation I thought that runtime.Caller(frame) will
return false when it is not possible to obtain information - instead
it causes program to crash past call stack top :

package main

import (
       "fmt";
       "runtime";
       "strings"
)

func main() {
       foo()
}

func foo() {
       bar()
}

func bar() {
       for i := 0; ; i++ {
               _, file, line, ok := runtime.Caller(i);
               if ok {
                       path := strings.Split(file, "/", 0);
                       fmt.Printf("%s : %d\n", path[len(path)-1], line);
               } else {
                       break;
               }
       }
}

results in

stacktrace.go : 19
stacktrace.go : 14
stacktrace.go : 10
asm.s : 81
proc.c : 135
Bus error

Also, Caller() doc says 'The argument is the number of stack frames to
ascend, with 1 identifying the the caller of Caller', while in fact,
it looks like 0 is the caller of Caller.

http://groups.google.com/group/golang-nuts/t/8626dabf2b80d453

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions