]> Cypherpunks repositories - gostls13.git/commitdiff
cmd/cgo: error, not panic, if not enough arguments to function
authorIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2015 20:07:57 +0000 (12:07 -0800)
committerIan Lance Taylor <iant@golang.org>
Wed, 2 Dec 2015 21:02:28 +0000 (21:02 +0000)
Fixes #13423.

Change-Id: I41bb45790cca36c57a107796f0eca61287acb2a9
Reviewed-on: https://go-review.googlesource.com/17332
Run-TryBot: Ian Lance Taylor <iant@golang.org>
Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>

misc/cgo/errors/issue13423.go [new file with mode: 0644]
misc/cgo/errors/test.bash
src/cmd/cgo/gcc.go

diff --git a/misc/cgo/errors/issue13423.go b/misc/cgo/errors/issue13423.go
new file mode 100644 (file)
index 0000000..6b2ad58
--- /dev/null
@@ -0,0 +1,12 @@
+// Copyright 2015 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.
+
+package main
+
+// #include <stdio.h>
+import "C"
+
+func main() {
+       _ = C.fopen() // ERROR HERE
+}
index d15c9e113d33ad57a75ade13c0cbb2cb5d3c3641..1744eee077cd388499dcc03f326450c9dc8dabfc 100755 (executable)
@@ -40,6 +40,7 @@ check issue8442.go
 check issue11097a.go
 check issue11097b.go
 expect issue13129.go C.ushort
+check issue13423.go
 
 if ! go run ptr.go; then
        exit 1
index 2b222d6d271c34a8bf14989ab15a28f4e79147cf..a3baecdf8bac52a42297af79915ad550f88aadd1 100644 (file)
@@ -598,6 +598,12 @@ func (p *Package) rewriteCalls(f *File) {
 // each pointer argument x with _cgoCheckPointer(x).(T).
 func (p *Package) rewriteCall(f *File, call *ast.CallExpr, name *Name) {
        for i, param := range name.FuncType.Params {
+               if len(call.Args) <= i {
+                       // Avoid a crash; this will be caught when the
+                       // generated file is compiled.
+                       return
+               }
+
                // An untyped nil does not need a pointer check, and
                // when _cgoCheckPointer returns the untyped nil the
                // type assertion we are going to insert will fail.
@@ -611,12 +617,6 @@ func (p *Package) rewriteCall(f *File, call *ast.CallExpr, name *Name) {
                        continue
                }
 
-               if len(call.Args) <= i {
-                       // Avoid a crash; this will be caught when the
-                       // generated file is compiled.
-                       return
-               }
-
                c := &ast.CallExpr{
                        Fun: ast.NewIdent("_cgoCheckPointer"),
                        Args: []ast.Expr{