diff options
author | Hiroshi Ioka <hirochachacha@gmail.com> | 2017-08-29 07:39:57 +0900 |
---|---|---|
committer | Russ Cox <rsc@golang.org> | 2017-10-25 20:23:49 +0000 |
commit | 33ce1682c7bd2d85d0f31c98d923b12c339d8a74 (patch) | |
tree | f777718bee05df7557955b7bfe5b30f735e49e4b | |
parent | f69668e1d0831ab3d3c8a6590e0d5b477ae74c1a (diff) | |
download | go-33ce1682c7bd2d85d0f31c98d923b12c339d8a74.tar.gz go-33ce1682c7bd2d85d0f31c98d923b12c339d8a74.zip |
[release-branch.go1.9] cmd/cgo: avoid using common names for sniffing
Current code uses names like "x" and "s" which can conflict with user's
code easily. Use cryptographic names.
Fixes #21668
Change-Id: Ib6d3d6327aa5b92d95c71503d42e3a79d96c8e16
Reviewed-on: https://go-review.googlesource.com/59710
Reviewed-by: Ian Lance Taylor <iant@golang.org>
Reviewed-on: https://go-review.googlesource.com/59730
Run-TryBot: Ian Lance Taylor <iant@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Reviewed-by: Hiroshi Ioka <hirochachacha@gmail.com>
Reviewed-by: Chris Broadfoot <cbro@golang.org>
Reviewed-on: https://go-review.googlesource.com/70849
Run-TryBot: Russ Cox <rsc@golang.org>
-rw-r--r-- | misc/cgo/test/issue21668.go | 13 | ||||
-rw-r--r-- | src/cmd/cgo/gcc.go | 20 |
2 files changed, 23 insertions, 10 deletions
diff --git a/misc/cgo/test/issue21668.go b/misc/cgo/test/issue21668.go new file mode 100644 index 0000000000..f15b9202ac --- /dev/null +++ b/misc/cgo/test/issue21668.go @@ -0,0 +1,13 @@ +// Copyright 2017 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Fail to guess the kind of the constant "x". +// No runtime test; just make sure it compiles. + +package cgotest + +// const int x = 42; +import "C" + +var issue21668_X = C.x diff --git a/src/cmd/cgo/gcc.go b/src/cmd/cgo/gcc.go index ff8b81354b..c47d1fba8d 100644 --- a/src/cmd/cgo/gcc.go +++ b/src/cmd/cgo/gcc.go @@ -296,15 +296,15 @@ func (p *Package) guessKinds(f *File) []*Name { // For each name, we generate these lines, where xxx is the index in toSniff plus one. // // #line xxx "not-declared" - // void __cgo_f_xxx_1(void) { __typeof__(name) *__cgo_undefined__; } + // void __cgo_f_xxx_1(void) { __typeof__(name) *__cgo_undefined__1; } // #line xxx "not-type" - // void __cgo_f_xxx_2(void) { name *__cgo_undefined__; } + // void __cgo_f_xxx_2(void) { name *__cgo_undefined__2; } // #line xxx "not-int-const" - // void __cgo_f_xxx_3(void) { enum { __cgo_undefined__ = (name)*1 }; } + // void __cgo_f_xxx_3(void) { enum { __cgo_undefined__3 = (name)*1 }; } // #line xxx "not-num-const" - // void __cgo_f_xxx_4(void) { static const double x = (name); } + // void __cgo_f_xxx_4(void) { static const double __cgo_undefined__4 = (name); } // #line xxx "not-str-lit" - // void __cgo_f_xxx_5(void) { static const char x[] = (name); } + // void __cgo_f_xxx_5(void) { static const char __cgo_undefined__5[] = (name); } // #line xxx "not-signed-int-const" // #if 0 < -(name) // #line xxx "not-signed-int-const" @@ -327,15 +327,15 @@ func (p *Package) guessKinds(f *File) []*Name { for i, n := range names { fmt.Fprintf(&b, "#line %d \"not-declared\"\n"+ - "void __cgo_f_%d_1(void) { __typeof__(%s) *__cgo_undefined__; }\n"+ + "void __cgo_f_%d_1(void) { __typeof__(%s) *__cgo_undefined__1; }\n"+ "#line %d \"not-type\"\n"+ - "void __cgo_f_%d_2(void) { %s *__cgo_undefined__; }\n"+ + "void __cgo_f_%d_2(void) { %s *__cgo_undefined__2; }\n"+ "#line %d \"not-int-const\"\n"+ - "void __cgo_f_%d_3(void) { enum { __cgo_undefined__ = (%s)*1 }; }\n"+ + "void __cgo_f_%d_3(void) { enum { __cgo_undefined__3 = (%s)*1 }; }\n"+ "#line %d \"not-num-const\"\n"+ - "void __cgo_f_%d_4(void) { static const double x = (%s); }\n"+ + "void __cgo_f_%d_4(void) { static const double __cgo_undefined__4 = (%s); }\n"+ "#line %d \"not-str-lit\"\n"+ - "void __cgo_f_%d_5(void) { static const char s[] = (%s); }\n"+ + "void __cgo_f_%d_5(void) { static const char __cgo_undefined__5[] = (%s); }\n"+ "#line %d \"not-signed-int-const\"\n"+ "#if 0 < (%s)\n"+ "#line %d \"not-signed-int-const\"\n"+ |