New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Avoid using unit IDs that are no longer valid #6616
Conversation
Just trying to understand the issue - this is a nasty bug. Is it because I checked that these are the only two uses of Regarding the existing comment 'Should it use underlying ID instead?' - I'm not sure what it means by that. If it's referring to the ID string instead of the ID from the unit object, maybe that comment should be deleted as well? |
I mentioned this on the issue as well, but I would personally prefer to instead alter the
That appears to be the situation, yes. |
Oh, I overlooked that as I'm only just now starting to understand the issue. wesnoth/src/recall_list_manager.cpp Lines 57 to 62 in 650f704
So just remove the & from the parameter (with explanatory comment)?
Edit: Oh wait, I see your comment from the issue report that you removed it from wesnoth/src/scripting/game_lua_kernel.cpp Lines 2502 to 2504 in 650f704
What about here, where it looks like the intention was to use v->id() as the search parameter. If the function is changed to accept string as value, would it make the cloning and reassigning between u and v redundant?
Edit: The reason I went with steve's solution was because the reporter seemed to say that one worked for them. Since none of us appear to be using musl-based distribution, we must rely on them for testing. |
I'm wondering if that would still be undefined behavior - the copy in the callee is fine, but is the one in the caller still meant to be valid? |
I believe removing it from either place should have the same effect. If you remove it from the parameter, I'd also remove
This is true – ideally we'd have them confirm that whatever fix we choose still works (perhaps ping the two of them here once we've settled on something).
It was already cloning the unit so I assume there is a reason to do so beyond the issue of the ID.
I'm not quite sure what you mean? |
I made a request to test your option in the original issue report, I assume there hasn't been time to test yet as there's been no response thus far.
That's my point - it isn't clear to me what the reason for cloning the unit is, other than possibly to avoid the pass-by-reference issue we're now aware of. But I suppose it is indeed better to leave things as they are lest we break something else. Perhaps I'll leave a comment if we end up choosing the option to change the |
Well, it's in |
Oh okay, when you explain it like that it makes more sense. I don't know if there's an established convention with Still no word from the original reporter - maybe we'll have to miss the 1.16.3 tag if they don't respond in time? |
I'll update the PR either later today or tomorrow. |
Resolves wesnoth#6603 (crash with musl implementation of libc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I learnt a bit of detail about lambdas - this syntax makes a single copy of unit_id
when the lambda is created.
(The delay in reviewing was because I was worried it would make a copy each time the lambda is called, and thus still potentially access the invalid value.)
Patch originally from @stevecotton. Aiming to merge before 1.16.3 is tagged (supposedly scheduled for 17th April 2022).
Resolves #6603 (crash with musl implementation of libc)