Hi Bram,

On Sun, Apr 22, 2018 at 10:28 AM, Bram Moolenaar
<[email protected]> wrote:
>
> Nikolai Pavlov wrote:
>
>> This is another error reported by PVS, though I now have no opinion on
>> what to do with this. Offending code is `qi != save_qi` condition in
>>
>> ```C
>> /* Autocommands may change the list. Save it for later comparison */
>> save_qi = qi;
>> …
>> if (!new_qi && qi != save_qi && qf_find_buf(qi) == NULL)
>> /* autocommands made "qi" invalid */
>> return;
>> ```
>>
>> The problem here is that if you analyze the code between assigning
>> `save_qi` and `qi` you will see that
>>
>> 1. There are no `goto` to the location before assigning `save_qi`,
>> specifically to the start of the function where `qi` is initially assigned.
>> Actually no labels anywhere in function.
>> 2. `qi` is not assigned to.
>> 3. `&qi` is not passed anywhere in the whole function (`qi` is passed, but
>> it would do nothing to mess with `save_qi == qi` condition). And it is a
>> local variable, so it would not be possible to change it otherwise.
>>
>> This means no matter what, autocommands *cannot* “make "qi" invalid” like
>> comment suggests as long as `qi != save_qi` is inside a condition. Also
>> autocommands *may not* change `qi`, only whatever memory `qi` points to.
>> Obviously, code is somehow wrong. But I do not know what is the right
>> variant.
>>
>> // BTW, is it intentional that QuickFixCmdPost run from `:[l]helpgrep`
>> ignores absense of `nested` flag? I can get E218 with `vim -u NORC -i NONE
>> -N --cmd 'au QuickFixCmdPost * :bwipeout! | lhelpgrep b' --cmd 'lhelpgrep
>> a'` (though still not something like double free crash I initially
>> expected).
>
> Yeah, the check won't work. The intention must have been that when an
> autocommand somehow makes the list invalid, we would bail out.
>
> Perhaps we would need to make a list of the valid quickfix lists, like
> we do for windows and buffers. Then we can have a quickfix_valid()
> function to check.
>
> There are other ways, such as using a reference count. There is
> qf_refcount but it's not always used. Might be complicated too.
>

The quickfix list identifier can be used to validate the quickfix list is
not removed by an autocmd. I haven't fully looked into the above
issue yet. Will look into it later today.

Regards,
Yegappan

-- 
-- 
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

--- 
You received this message because you are subscribed to the Google Groups 
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Raspunde prin e-mail lui