From 72cff0bab6733ab39bd06e12fa5c98a5d8338dc6 Mon Sep 17 00:00:00 2001 From: Wesley Kerfoot Date: Sun, 28 Jun 2020 10:24:30 -0400 Subject: [PATCH] fix out of bounds error condition --- src/nimwin.nim | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/nimwin.nim b/src/nimwin.nim index 1d18184..ddd4779 100644 --- a/src/nimwin.nim +++ b/src/nimwin.nim @@ -96,8 +96,11 @@ proc getPropertyValue(display : PDisplay, window : TWindow, property : TAtom) : if typeName == "STRING": var propStrValue = newString(propValue.len) - copyMem(addr(propStrValue[0]), propValue, propValue.len) - result = some(WinProp(name: atomName, kind: pkString, strProp: propStrValue)) + if propStrValue.len > 0: + copyMem(addr(propStrValue[0]), propValue, propValue.len) + result = some(WinProp(name: atomName, kind: pkString, strProp: propStrValue)) + else: + result = none(WinProp) elif typeName == "CARDINAL": result = some( WinProp( @@ -272,7 +275,6 @@ proc handleProcess(p : Process) = discard p.waitForExit processChan.send(p.processID) - proc calculateStruts(display : PDisplay) : tuple[top: uint, bottom: uint]= for win in getChildren(display): for prop in win.props: @@ -397,7 +399,7 @@ when isMainModule: discard XMoveResizeWindow(display, ev.xKey.subWindow, 0, struts.top.cint, - screenWidth.cuint, screenHeight.cuint - struts.bottom.cuint - borderWidth) + screenWidth.cuint, screenHeight.cuint - struts.bottom.cuint - borderWidth.cuint) elif (ev.theType == ButtonPress) and (ev.xButton.subWindow != None):