I'm new to pointer analysis and static analysis in general, I hope someone can give me a brief answer and push me in the right direction.
Basically what I want to achieve is to do static analysis of Go source, looking after potential buggy code, e.g. forgetting to Flush() a buffer.
Its maybe trivial to check after an Flush() operation on a buffer variable in a single function. But as in the code under, it´s harder to detect that the buffer actually is closed in another function called.
How can one nicely do static checking to solve this, I can only think of using the Go tools pointer package 1, but it´s not easy to get grasp on the documentation.
package main
import (
"bufio"
"fmt"
"os"
)
func main() {
w := bufio.NewWriter(os.Stdout)
fmt.Fprint(w, "Hello, World")
closeBuffer(w)
}
func closeBuffer(buf *bufio.Writer) {
buf.Flush()
}