mirror of https://github.com/golang/go.git
cmd/cgo: error, not panic, if not enough arguments to function
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>
This commit is contained in:
parent
8a34cf7ee0
commit
5a049aa4a6
|
|
@ -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
|
||||||
|
}
|
||||||
|
|
@ -40,6 +40,7 @@ check issue8442.go
|
||||||
check issue11097a.go
|
check issue11097a.go
|
||||||
check issue11097b.go
|
check issue11097b.go
|
||||||
expect issue13129.go C.ushort
|
expect issue13129.go C.ushort
|
||||||
|
check issue13423.go
|
||||||
|
|
||||||
if ! go run ptr.go; then
|
if ! go run ptr.go; then
|
||||||
exit 1
|
exit 1
|
||||||
|
|
|
||||||
|
|
@ -598,6 +598,12 @@ func (p *Package) rewriteCalls(f *File) {
|
||||||
// each pointer argument x with _cgoCheckPointer(x).(T).
|
// each pointer argument x with _cgoCheckPointer(x).(T).
|
||||||
func (p *Package) rewriteCall(f *File, call *ast.CallExpr, name *Name) {
|
func (p *Package) rewriteCall(f *File, call *ast.CallExpr, name *Name) {
|
||||||
for i, param := range name.FuncType.Params {
|
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
|
// An untyped nil does not need a pointer check, and
|
||||||
// when _cgoCheckPointer returns the untyped nil the
|
// when _cgoCheckPointer returns the untyped nil the
|
||||||
// type assertion we are going to insert will fail.
|
// 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
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
if len(call.Args) <= i {
|
|
||||||
// Avoid a crash; this will be caught when the
|
|
||||||
// generated file is compiled.
|
|
||||||
return
|
|
||||||
}
|
|
||||||
|
|
||||||
c := &ast.CallExpr{
|
c := &ast.CallExpr{
|
||||||
Fun: ast.NewIdent("_cgoCheckPointer"),
|
Fun: ast.NewIdent("_cgoCheckPointer"),
|
||||||
Args: []ast.Expr{
|
Args: []ast.Expr{
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue