Skip to content

Commit 33ce168

Browse files
hirochachacharsc
authored andcommitted
[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 <[email protected]> Reviewed-on: https://go-review.googlesource.com/59730 Run-TryBot: Ian Lance Taylor <[email protected]> TryBot-Result: Gobot Gobot <[email protected]> Reviewed-by: Hiroshi Ioka <[email protected]> Reviewed-by: Chris Broadfoot <[email protected]> Reviewed-on: https://go-review.googlesource.com/70849 Run-TryBot: Russ Cox <[email protected]>
1 parent f69668e commit 33ce168

File tree

2 files changed

+23
-10
lines changed

2 files changed

+23
-10
lines changed

misc/cgo/test/issue21668.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// Copyright 2017 The Go Authors. All rights reserved.
2+
// Use of this source code is governed by a BSD-style
3+
// license that can be found in the LICENSE file.
4+
5+
// Fail to guess the kind of the constant "x".
6+
// No runtime test; just make sure it compiles.
7+
8+
package cgotest
9+
10+
// const int x = 42;
11+
import "C"
12+
13+
var issue21668_X = C.x

src/cmd/cgo/gcc.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -296,15 +296,15 @@ func (p *Package) guessKinds(f *File) []*Name {
296296
// For each name, we generate these lines, where xxx is the index in toSniff plus one.
297297
//
298298
// #line xxx "not-declared"
299-
// void __cgo_f_xxx_1(void) { __typeof__(name) *__cgo_undefined__; }
299+
// void __cgo_f_xxx_1(void) { __typeof__(name) *__cgo_undefined__1; }
300300
// #line xxx "not-type"
301-
// void __cgo_f_xxx_2(void) { name *__cgo_undefined__; }
301+
// void __cgo_f_xxx_2(void) { name *__cgo_undefined__2; }
302302
// #line xxx "not-int-const"
303-
// void __cgo_f_xxx_3(void) { enum { __cgo_undefined__ = (name)*1 }; }
303+
// void __cgo_f_xxx_3(void) { enum { __cgo_undefined__3 = (name)*1 }; }
304304
// #line xxx "not-num-const"
305-
// void __cgo_f_xxx_4(void) { static const double x = (name); }
305+
// void __cgo_f_xxx_4(void) { static const double __cgo_undefined__4 = (name); }
306306
// #line xxx "not-str-lit"
307-
// void __cgo_f_xxx_5(void) { static const char x[] = (name); }
307+
// void __cgo_f_xxx_5(void) { static const char __cgo_undefined__5[] = (name); }
308308
// #line xxx "not-signed-int-const"
309309
// #if 0 < -(name)
310310
// #line xxx "not-signed-int-const"
@@ -327,15 +327,15 @@ func (p *Package) guessKinds(f *File) []*Name {
327327

328328
for i, n := range names {
329329
fmt.Fprintf(&b, "#line %d \"not-declared\"\n"+
330-
"void __cgo_f_%d_1(void) { __typeof__(%s) *__cgo_undefined__; }\n"+
330+
"void __cgo_f_%d_1(void) { __typeof__(%s) *__cgo_undefined__1; }\n"+
331331
"#line %d \"not-type\"\n"+
332-
"void __cgo_f_%d_2(void) { %s *__cgo_undefined__; }\n"+
332+
"void __cgo_f_%d_2(void) { %s *__cgo_undefined__2; }\n"+
333333
"#line %d \"not-int-const\"\n"+
334-
"void __cgo_f_%d_3(void) { enum { __cgo_undefined__ = (%s)*1 }; }\n"+
334+
"void __cgo_f_%d_3(void) { enum { __cgo_undefined__3 = (%s)*1 }; }\n"+
335335
"#line %d \"not-num-const\"\n"+
336-
"void __cgo_f_%d_4(void) { static const double x = (%s); }\n"+
336+
"void __cgo_f_%d_4(void) { static const double __cgo_undefined__4 = (%s); }\n"+
337337
"#line %d \"not-str-lit\"\n"+
338-
"void __cgo_f_%d_5(void) { static const char s[] = (%s); }\n"+
338+
"void __cgo_f_%d_5(void) { static const char __cgo_undefined__5[] = (%s); }\n"+
339339
"#line %d \"not-signed-int-const\"\n"+
340340
"#if 0 < (%s)\n"+
341341
"#line %d \"not-signed-int-const\"\n"+

0 commit comments

Comments
 (0)