# HG changeset patch # User unc0rr # Date 1520542739 -3600 # Node ID f10f4bf5f84d35c2c8d0d8bdfabfb13a5ee683e0 # Parent 13b6f1621ef236211bd511812ef37d8763d0ed84 This should fix crash with custom bindings diff -r 13b6f1621ef2 -r f10f4bf5f84d hedgewars/uInputHandler.pas --- a/hedgewars/uInputHandler.pas Thu Mar 08 21:46:43 2018 +0100 +++ b/hedgewars/uInputHandler.pas Thu Mar 08 21:58:59 2018 +0100 @@ -671,19 +671,22 @@ if b = 0 then OutError(errmsgUnknownVariable + ' "' + id + '"', false) else - begin +begin // add bind: first check if this cmd is already bound, and remove old bind - code:= High(binds.binds); - repeat - dec(code) - until (code < 0) or (binds.binds[code] = KeyName); - if (code >= 0) then + i:= Low(binds.binds); + while (i <= High(binds.binds)) and (binds.binds[i] <> KeyName) do + inc(i); + + if (i <= High(binds.binds)) then begin - i:= 0; - while (i <= High(binds.indices)) and (binds.indices[i] <> code) do inc(i); - checkFails(i <= High(binds.indices), 'binds registry inconsistency', true); - binds.binds[i]:= ''; - binds.indices[code]:= 0 + code:= Low(binds.indices); + while (code <= High(binds.indices)) and (binds.indices[code] <> i) do + inc(code); + + checkFails(code <= High(binds.indices), 'binds registry inconsistency', true); + + if allOk then + binds.indices[code]:= 0 end else begin inc(binds.lastIndex);