Skip to content

Commit 4403b04

Browse files
committed
fix exposed panic
1 parent 9e1e975 commit 4403b04

File tree

3 files changed

+73
-53
lines changed

3 files changed

+73
-53
lines changed

_state.go

+9-5
Original file line numberDiff line numberDiff line change
@@ -936,18 +936,22 @@ func (ls *LState) initCallFrame(cf *callFrame) { // +inline-start
936936
proto := cf.Fn.Proto
937937
nargs := cf.NArgs
938938
np := int(proto.NumParameters)
939-
newSize := cf.LocalBase + np
940-
// +inline-call ls.reg.checkSize newSize
941-
for i := nargs; i < np; i++ {
942-
ls.reg.array[cf.LocalBase+i] = LNil
939+
if nargs < np {
940+
// default any missing arguments to nil
941+
newSize := cf.LocalBase + np
942+
// +inline-call ls.reg.checkSize newSize
943+
for i := nargs; i < np; i++ {
944+
ls.reg.array[cf.LocalBase+i] = LNil
945+
}
943946
nargs = np
947+
ls.reg.top = newSize
944948
}
945949

946950
if (proto.IsVarArg & VarArgIsVarArg) == 0 {
947951
if nargs < int(proto.NumUsedRegisters) {
948952
nargs = int(proto.NumUsedRegisters)
949953
}
950-
newSize = cf.LocalBase + nargs
954+
newSize := cf.LocalBase + nargs
951955
// +inline-call ls.reg.checkSize newSize
952956
for i := np; i < nargs; i++ {
953957
ls.reg.array[cf.LocalBase+i] = LNil

state.go

+32-24
Original file line numberDiff line numberDiff line change
@@ -982,26 +982,30 @@ func (ls *LState) initCallFrame(cf *callFrame) { // +inline-start
982982
proto := cf.Fn.Proto
983983
nargs := cf.NArgs
984984
np := int(proto.NumParameters)
985-
newSize := cf.LocalBase + np
986-
// this section is inlined by go-inline
987-
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
988-
{
989-
rg := ls.reg
990-
requiredSize := newSize
991-
if requiredSize > cap(rg.array) {
992-
rg.resize(requiredSize)
985+
if nargs < np {
986+
// default any missing arguments to nil
987+
newSize := cf.LocalBase + np
988+
// this section is inlined by go-inline
989+
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
990+
{
991+
rg := ls.reg
992+
requiredSize := newSize
993+
if requiredSize > cap(rg.array) {
994+
rg.resize(requiredSize)
995+
}
996+
}
997+
for i := nargs; i < np; i++ {
998+
ls.reg.array[cf.LocalBase+i] = LNil
993999
}
994-
}
995-
for i := nargs; i < np; i++ {
996-
ls.reg.array[cf.LocalBase+i] = LNil
9971000
nargs = np
1001+
ls.reg.top = newSize
9981002
}
9991003

10001004
if (proto.IsVarArg & VarArgIsVarArg) == 0 {
10011005
if nargs < int(proto.NumUsedRegisters) {
10021006
nargs = int(proto.NumUsedRegisters)
10031007
}
1004-
newSize = cf.LocalBase + nargs
1008+
newSize := cf.LocalBase + nargs
10051009
// this section is inlined by go-inline
10061010
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
10071011
{
@@ -1090,26 +1094,30 @@ func (ls *LState) pushCallFrame(cf callFrame, fn LValue, meta bool) { // +inline
10901094
proto := cf.Fn.Proto
10911095
nargs := cf.NArgs
10921096
np := int(proto.NumParameters)
1093-
newSize := cf.LocalBase + np
1094-
// this section is inlined by go-inline
1095-
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
1096-
{
1097-
rg := ls.reg
1098-
requiredSize := newSize
1099-
if requiredSize > cap(rg.array) {
1100-
rg.resize(requiredSize)
1097+
if nargs < np {
1098+
// default any missing arguments to nil
1099+
newSize := cf.LocalBase + np
1100+
// this section is inlined by go-inline
1101+
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
1102+
{
1103+
rg := ls.reg
1104+
requiredSize := newSize
1105+
if requiredSize > cap(rg.array) {
1106+
rg.resize(requiredSize)
1107+
}
1108+
}
1109+
for i := nargs; i < np; i++ {
1110+
ls.reg.array[cf.LocalBase+i] = LNil
11011111
}
1102-
}
1103-
for i := nargs; i < np; i++ {
1104-
ls.reg.array[cf.LocalBase+i] = LNil
11051112
nargs = np
1113+
ls.reg.top = newSize
11061114
}
11071115

11081116
if (proto.IsVarArg & VarArgIsVarArg) == 0 {
11091117
if nargs < int(proto.NumUsedRegisters) {
11101118
nargs = int(proto.NumUsedRegisters)
11111119
}
1112-
newSize = cf.LocalBase + nargs
1120+
newSize := cf.LocalBase + nargs
11131121
// this section is inlined by go-inline
11141122
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
11151123
{

vm.go

+32-24
Original file line numberDiff line numberDiff line change
@@ -728,26 +728,30 @@ func init() {
728728
proto := cf.Fn.Proto
729729
nargs := cf.NArgs
730730
np := int(proto.NumParameters)
731-
newSize := cf.LocalBase + np
732-
// this section is inlined by go-inline
733-
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
734-
{
735-
rg := ls.reg
736-
requiredSize := newSize
737-
if requiredSize > cap(rg.array) {
738-
rg.resize(requiredSize)
731+
if nargs < np {
732+
// default any missing arguments to nil
733+
newSize := cf.LocalBase + np
734+
// this section is inlined by go-inline
735+
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
736+
{
737+
rg := ls.reg
738+
requiredSize := newSize
739+
if requiredSize > cap(rg.array) {
740+
rg.resize(requiredSize)
741+
}
742+
}
743+
for i := nargs; i < np; i++ {
744+
ls.reg.array[cf.LocalBase+i] = LNil
739745
}
740-
}
741-
for i := nargs; i < np; i++ {
742-
ls.reg.array[cf.LocalBase+i] = LNil
743746
nargs = np
747+
ls.reg.top = newSize
744748
}
745749

746750
if (proto.IsVarArg & VarArgIsVarArg) == 0 {
747751
if nargs < int(proto.NumUsedRegisters) {
748752
nargs = int(proto.NumUsedRegisters)
749753
}
750-
newSize = cf.LocalBase + nargs
754+
newSize := cf.LocalBase + nargs
751755
// this section is inlined by go-inline
752756
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
753757
{
@@ -906,26 +910,30 @@ func init() {
906910
proto := cf.Fn.Proto
907911
nargs := cf.NArgs
908912
np := int(proto.NumParameters)
909-
newSize := cf.LocalBase + np
910-
// this section is inlined by go-inline
911-
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
912-
{
913-
rg := ls.reg
914-
requiredSize := newSize
915-
if requiredSize > cap(rg.array) {
916-
rg.resize(requiredSize)
913+
if nargs < np {
914+
// default any missing arguments to nil
915+
newSize := cf.LocalBase + np
916+
// this section is inlined by go-inline
917+
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
918+
{
919+
rg := ls.reg
920+
requiredSize := newSize
921+
if requiredSize > cap(rg.array) {
922+
rg.resize(requiredSize)
923+
}
924+
}
925+
for i := nargs; i < np; i++ {
926+
ls.reg.array[cf.LocalBase+i] = LNil
917927
}
918-
}
919-
for i := nargs; i < np; i++ {
920-
ls.reg.array[cf.LocalBase+i] = LNil
921928
nargs = np
929+
ls.reg.top = newSize
922930
}
923931

924932
if (proto.IsVarArg & VarArgIsVarArg) == 0 {
925933
if nargs < int(proto.NumUsedRegisters) {
926934
nargs = int(proto.NumUsedRegisters)
927935
}
928-
newSize = cf.LocalBase + nargs
936+
newSize := cf.LocalBase + nargs
929937
// this section is inlined by go-inline
930938
// source function is 'func (rg *registry) checkSize(requiredSize int) ' in '_state.go'
931939
{

0 commit comments

Comments
 (0)