Skip to content

Commit 547c35e

Browse files
committed
Avoid crash because of GonvimResize arguments
Check arguments passed to GonvimResize to avoid crashes because of wrong type (e.g. int64 instead of string) or incorrectly formed (e.g. "" instead of "30x40").
1 parent f9153cb commit 547c35e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

editor/editor.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,11 +1103,18 @@ func (e *Editor) setWindowSizeFromOpts() {
11031103
func (e *Editor) setWindowSize(s string) (int, int) {
11041104
var width, height int
11051105
var err error
1106-
width, err = strconv.Atoi(strings.SplitN(s, "x", 2)[0])
1106+
1107+
parsed_s := strings.SplitN(s, "x", 2)
1108+
if len(parsed_s) != 2 {
1109+
// TODO: Error message to user?
1110+
return 40, 30
1111+
}
1112+
1113+
width, err = strconv.Atoi(parsed_s[0])
11071114
if err != nil || width < 40 {
11081115
width = 40
11091116
}
1110-
height, err = strconv.Atoi(strings.SplitN(s, "x", 2)[1])
1117+
height, err = strconv.Atoi(parsed_s[1])
11111118
if err != nil || height < 30 {
11121119
height = 30
11131120
}

editor/workspace.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1825,8 +1825,11 @@ func (ws *Workspace) handleGui(updates []interface{}) {
18251825
go setupGoneovimClipBoard(ws.nvim)
18261826
case "gonvim_uienter":
18271827
case "gonvim_resize":
1828-
width, height := editor.setWindowSize(updates[1].(string))
1829-
editor.window.Resize2(width, height)
1828+
arg, ok := updates[1].(string)
1829+
if ok {
1830+
width, height := editor.setWindowSize(arg)
1831+
editor.window.Resize2(width, height)
1832+
}
18301833
case "gonvim_fullscreen":
18311834
arg := 1
18321835
if len(updates) == 2 {

0 commit comments

Comments
 (0)