Skip to content

Fix crash when passing filenames on command-line - #20

Open
adriaandegroot wants to merge 1 commit into
copperspice:masterfrom
adriaandegroot:work/adridg/fix-crash
Open

adriaandegroot wants to merge 1 commit into
copperspice:masterfrom
adriaandegroot:work/adridg/fix-crash

Conversation

@adriaandegroot

Copy link
Copy Markdown
Contributor

Consider running diamond file.txt. If previously there
was an untitled tab open and nothing else, we arrive
here with 2 tabs, cnt==2. The first for-loop finds
an untitled tab at index k==0 and decrements cnt,
then the for-loop increments k and the for-loop terminates
(because 1 < 1 is false). We have cnt==1 but an empty
list m_openedFiles. This crashes with an out-of-bounds access
in the second for-loop, because cnt doesn't match the length
of the list anymore.

As a fix:

  • do not modify cnt in the first for-loop, always check
    all of the current tabs,
  • re-calculate the cnt based on the files that are actually
    opened, before the second loop.

Consider running `diamond file.txt`. If previously there
was an untitled tab open and nothing else, we arrive
here with 2 tabs, `cnt==2`. The first for-loop finds
an untitled tab at index `k==0` and decrements `cnt`,
then the for-loop increments `k` and the for-loop terminates
(because `1 < 1` is false). We have `cnt==1` but an **empty**
list `m_openedFiles`. This crashes with an out-of-bounds access
in the second for-loop, because `cnt` doesn't match the length
of the list anymore.

As a fix:
- do not modify `cnt` in the first for-loop, always check
  all of the current tabs,
- re-calculate the `cnt` based on the files that are actually
  opened, before the second loop.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant