From a1bd184e50c7cf1f18e69259bdbd028c5fcd4821 Mon Sep 17 00:00:00 2001 From: Mikkel Krautz Date: Sun, 28 Nov 2010 03:18:44 +0100 Subject: [PATCH] Add checks for buggy goprotobuf. --- grumble.go | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/grumble.go b/grumble.go index 9f19225..99723cb 100644 --- a/grumble.go +++ b/grumble.go @@ -8,6 +8,9 @@ import ( "flag" "fmt" "os" + "log" + "mumbleproto" + "goprotobuf.googlecode.com/hg/proto" ) var help *bool = flag.Bool("help", false, "Show this help") @@ -19,6 +22,19 @@ func usage() { flag.PrintDefaults() } +// Check that we're using a version of goprotobuf that is able to +// correctly encode empty byte slices. +func checkProtoLib() { + us := &mumbleproto.UserState{} + us.Texture = []byte{} + d, _ := proto.Marshal(us) + nus := &mumbleproto.UserState{} + proto.Unmarshal(d, nus) + if nus.Texture == nil { + log.Exitf("Unpatched version of goprotobuf. Grumble is refusing to run.") + } +} + func main() { flag.Parse() if *help == true { @@ -26,6 +42,8 @@ func main() { return } + checkProtoLib() + // Create our default server m, err := NewServer(*host, *port) if err != nil {