Skip to content

Commit e89be38

Browse files
authored
Merge pull request #1471 from b4n/luawarnings
geanylua: Fix a few warnings and potential crashes
2 parents d41be8b + 463562d commit e89be38

3 files changed

Lines changed: 27 additions & 8 deletions

File tree

geanylua/glspi_dlg.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ static gint glspi_message(lua_State* L)
211211
case 2:
212212
if (!lua_isstring(L, 2)) { return FAIL_STRING_ARG(2); }
213213
arg2=lua_tostring(L, 2);
214+
/* Fallthrough */
214215
default:
215216
if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); }
216217
arg1=lua_tostring(L, 1);
@@ -280,6 +281,7 @@ static gint glspi_input(lua_State* L)
280281
if (!lua_isstring(L, 2)) { return FAIL_STRING_ARG(2); }
281282
arg2=lua_tostring(L, 2);
282283
}
284+
/* Fallthrough */
283285
default:
284286
if (!lua_isnil(L, 1)) {
285287
if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); }

geanylua/glspi_doc.c

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ static gint glspi_newfile(lua_State* L)
4343
} else {
4444
ft=filetypes_lookup_by_name(tmp);
4545
}
46+
/* Fallthrough */
4647
default:
4748
if (!lua_isstring(L, 1)) { return FAIL_STRING_ARG(1); }
4849
fn=lua_tostring(L, 1);
@@ -102,7 +103,7 @@ static gint glspi_activate(lua_State* L)
102103
}
103104
} else if (lua_idx > 0) {
104105
/* Positive number refers to the geany->documents_array index */
105-
gint doc_idx = lua_idx - 1;
106+
guint doc_idx = (guint) (lua_idx - 1);
106107
if ((doc_idx < geany->documents_array->len) && documents[doc_idx]->is_valid) {
107108
tab_idx = document_get_notebook_page(documents[doc_idx]);
108109
}
@@ -208,11 +209,16 @@ static gint glspi_save(lua_State* L)
208209
} else {
209210
if (lua_isnumber(L,1)) {
210211
gint idx=(gint)lua_tonumber(L,1)-1;
211-
status=document_save_file(documents[idx], TRUE);
212+
GeanyDocument *doc = document_index(idx);
213+
if (DOC_VALID(doc)) {
214+
status=document_save_file(doc, TRUE);
215+
}
212216
} else {
213217
if (lua_isstring(L,1)) {
214218
gint idx=filename_to_doc_idx(lua_tostring(L,1));
215-
status=document_save_file(documents[idx], TRUE);
219+
if (idx >= 0) {
220+
status=document_save_file(documents[idx], TRUE);
221+
}
216222
} else { return FAIL_STR_OR_NUM_ARG(1); }
217223
}
218224
}
@@ -241,7 +247,10 @@ static gint glspi_open(lua_State* L)
241247
}
242248
}
243249
if (!fn) {
244-
status=document_reload_force(documents[idx],NULL) ? idx : -1;
250+
GeanyDocument*doc=document_index(idx);
251+
if (DOC_VALID(doc)) {
252+
status=document_reload_force(doc,NULL) ? idx : -1;
253+
}
245254
} else {
246255
guint len=geany->documents_array->len;
247256
GeanyDocument*doc=document_open_file(fn,FALSE,NULL,NULL);
@@ -268,12 +277,17 @@ static gint glspi_close(lua_State* L)
268277
status=document_close(document_get_current());
269278
} else {
270279
if (lua_isnumber(L,1)) {
271-
guint idx=(guint)lua_tonumber(L,1)-1;
272-
status=document_close(documents[idx]);
280+
gint idx=(gint)lua_tonumber(L,1)-1;
281+
GeanyDocument *doc = document_index(idx);
282+
if (DOC_VALID(doc)) {
283+
status=document_close(doc);
284+
}
273285
} else {
274286
if (lua_isstring(L,1)) {
275-
guint idx=(guint)filename_to_doc_idx(lua_tostring(L,1));
276-
status=document_close(documents[idx]);
287+
gint idx=filename_to_doc_idx(lua_tostring(L,1));
288+
if (idx >= 0) {
289+
status=document_close(documents[idx]);
290+
}
277291
} else { return FAIL_STR_OR_NUM_ARG(1); }
278292
}
279293
}

geanylua/glspi_sci.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,16 +392,19 @@ static gint glspi_navigate(lua_State* L)
392392
case 4:
393393
if (!lua_isboolean(L,4)) { return FAIL_BOOL_ARG(4); }
394394
rect=lua_toboolean(L,4);
395+
/* Fallthrough */
395396
case 3:
396397
if (!lua_isboolean(L,3)) { return FAIL_BOOL_ARG(3); }
397398
sel=lua_toboolean(L,3);
399+
/* Fallthrough */
398400
case 2:
399401
if (!lua_isnumber(L,2)) { return FAIL_NUMERIC_ARG(2); }
400402
count=lua_tonumber(L,2);
401403
if (count<0) {
402404
fwd=FALSE;
403405
count=0-count;
404406
}
407+
/* Fallthrough */
405408
case 1:
406409
if (!lua_isstring(L,1)) { return FAIL_STRING_ARG(1); }
407410
strcmd=lua_tostring(L,1);

0 commit comments

Comments
 (0)