-
-
Notifications
You must be signed in to change notification settings - Fork 206
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
Fix ancient register_menuid bug, using strstr instead of strcmp #394
base: master
Are you sure you want to change the base?
Conversation
If you registered a menu whose title was a superset of an already registered menu, it wouldn't register a new handler but use the handler of the subset title menu
Can you give a little explanation on expected vs actual results? This looks like a possible breaking change to me. |
Check the test plugin ExpectedIf /testmenu is typed, it should call ActualIf /testmenu is typed, it calls Note that with this bug, the actual result is order dependent too. If I were to register the menus in this order register_menu("Test menu advanced", 1, "test_menu_advanced");
register_menu("Test menu", 1, "test_menu"); It would work as expected. This won't be breaking because although the test plugin does change behavior, no actual plugin would be like this since it would be a non-working plugin. For all currently working plugins there is no behavior change. This fix simply allows you to have title names that were not possible before. |
@Nextra after reading documentation of strstr, the bug makes sense, strstr finds the first instance of substr in str and returns a pointer to where it is in str, NULL if substr isn't found. This forces AMXX plugins to think about regristration order of menus where 1 handler name is part of another where strcmp returns 0 if both strings are equal. |
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.
This is going to break the hooking of existing game menus if the full string is not used.
Yeah but I would guess there isn't even a single plugin out there that doesn't use the full string since this "possibility" isn't documented anywhere (besides the fact that why would you even do that). |
You need to be careful with such statements. I'd say that hooking game menus is exactly the reason why |
@Arkshine what is the purpose of using part of the string (but not full) for menu hooking? |
I don't know. It's difficult to evaluate how abused that behavior is. Changing this is likely to not end well. Actually I tried to search randomly and I've found right away a script which uses We could keep |
I guess this would be a good compromise. For internal menus I've been bitten by this bug many times already throughout the last 5 or 10 years. Never bothered to investigate the actual bug until now because of laziness (I knew that they got routed wrongly, and that changing the name to something different somehow fixed it). I'm surprised this "bug" or "feature" isn't more known considering how likely it is to name two menus in such a way. |
To be honest this issue is not really a "bug' and is quite minor. I'm not sure it's worth to mess the ugly core code just for that because of legacy breakage. Both solutions are acceptable, but just documenting the behavior is probably the way to go, I think. |
Maybe add a new optional parameter to |
Another option would be to add the special case of missing |
Ignacio you're moving on very thin ice with these claims. We can't change this behavior based on guesses and anecdotal evidence. The current core code is abused by plugins, and we won't be able to tell to what extent. We should absolutely keep doing what we're doing in this case. This leaves adding a new native or additional parameters, and by that point we might want to reconsider the magnitude of this issue. |
If you registered a menu whose title was a superset of an already
registered menu, it wouldn't register a new handler but use the
handler of the subset title menu
Test plugin
(By the way amxmodx won't compile with the latest AMTL)