Skip to content

Commit 6dd3158

Browse files
committed
Make l_Wing functions handle invalid handles.
Indexing an invalid wing handle now returns invalid ship handles, getting its length returns 0, and getting its name returns an empty string.
1 parent 004fdae commit 6dd3158

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

code/parse/lua.cpp

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8797,15 +8797,15 @@ ADE_FUNC(isValid, l_Message, NULL, "Checks if the message handle is valid", "boo
87978797
//**********HANDLE: Wing
87988798
ade_obj<int> l_Wing("wing", "Wing handle");
87998799

8800-
ADE_INDEXER(l_Wing, "number Index", "Array of ships in the wing", "ship", "Ship handle, or invalid ship handle if index is invawing handle is invalid")
8800+
ADE_INDEXER(l_Wing, "number Index", "Array of ships in the wing", "ship", "Ship handle, or invalid ship handle if index is invalid or wing handle is invalid")
88018801
{
88028802
int wdx;
88038803
int sdx;
88048804
object_h *ndx=NULL;
88058805
if(!ade_get_args(L, "oi|o", l_Wing.Get(&wdx), &sdx, l_Ship.GetPtr(&ndx)))
88068806
return ade_set_error(L, "o", l_Ship.Set(object_h()));
88078807

8808-
if(sdx < 1 || sdx > Wings[wdx].current_count) {
8808+
if(wdx < 0 || wdx >= Num_wings || sdx < 1 || sdx > Wings[wdx].current_count) {
88098809
return ade_set_error(L, "o", l_Ship.Set(object_h()));
88108810
}
88118811

@@ -8819,11 +8819,11 @@ ADE_INDEXER(l_Wing, "number Index", "Array of ships in the wing", "ship", "Ship
88198819
return ade_set_args(L, "o", l_Ship.Set(object_h(&Objects[Ships[Wings[wdx].ship_index[sdx]].objnum])));
88208820
}
88218821

8822-
ADE_FUNC(__len, l_Wing, NULL, "Gets the number of ships in the wing", "number", "Number of ships in wing")
8822+
ADE_FUNC(__len, l_Wing, NULL, "Gets the number of ships in the wing", "number", "Number of ships in wing, or 0 if invalid handle")
88238823
{
88248824
int wdx;
8825-
if(!ade_get_args(L, "o", l_Wing.Get(&wdx)))
8826-
return ade_set_error(L, "i", NULL);
8825+
if(!ade_get_args(L, "o", l_Wing.Get(&wdx)) || wdx < 0 || wdx >= Num_wings)
8826+
return ade_set_error(L, "i", 0);
88278827

88288828
return ade_set_args(L, "i", Wings[wdx].current_count);
88298829
}
@@ -8832,7 +8832,7 @@ ADE_VIRTVAR(Name, l_Wing, "string", "Name of Wing", "string", "Wing name, or emp
88328832
{
88338833
int wdx;
88348834
char *s = NULL;
8835-
if ( !ade_get_args(L, "o|s", l_Wing.Get(&wdx), &s) )
8835+
if ( !ade_get_args(L, "o|s", l_Wing.Get(&wdx), &s) || wdx < 0 || wdx >= Num_wings )
88368836
return ade_set_error(L, "s", "");
88378837

88388838
if(ADE_SETTING_VAR && s != NULL) {

0 commit comments

Comments
 (0)