Repository navigation
Conversation
|
I'm not sure if it is a proper fix. |
|
Example of failing code: #include <mlib/m-list.h>
#include <mlib/m-string.h>
M_LIST_DUALF_DEF(m_string_list, m_string_t)
#define M_OPL_m_string_list_t() M_LIST_OPLIST(m_string_list, M_OPL_m_string_t())
int main() {
m_string_list_t args;
m_string_list_init(args);
m_string_set(*m_string_list_push_back_new(args), "/usr/bin/chromium");
m_string_set(*m_string_list_push_back_new(args), "%U");
for
M_EACH(arg, args, M_OPL_m_string_list_t()) {
if(m_string_start_with_str_p(*arg, "%")) {
m_string_list_remove(args, local_iterator_14);
}
}
return 0;
}which crashes with: I realized now writing the example code that maybe this might not be as necessary upstream: I am using a modified version of M_EACH() in my app with the iterator name more accessible (in the above example, it would be |
|
local_iterator_ isn't meant to be used by end users; and the fix you propose is also flawed as when you remove an item you advance your iterator by 2 instead of 1 (IT_REMOVE already advances the iterator to the next item). |
|
Ah I see, thanks for the heads up |
currently, using M_EACH() with a container such as M_LIST and using _remove() on the last item will lead to a failed assert, as the iterator can no longer progress.
this makes it so it will check if the iterator already reached the end during this iteration before trying to step it.