-
-
Notifications
You must be signed in to change notification settings - Fork 198
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
Port bugfix for incorrect heap deallocation on conditional operator #627
Port bugfix for incorrect heap deallocation on conditional operator #627
Conversation
…ported from compuphase upstream)
I tried a little. It works well for general use like: server_print("1. %s", test1 ? fmt("Something") : ""); // Nothing
server_print("2. %s", test2 ? fmt("Something") : ""); // "Something"
server_print("3. %s", test1 ? "" : fmt("Something")); // "Something"
server_print("4. %s", test2 ? "" : fmt("Something")); // Nothing
server_print("5. %s", test1 ? "Hello" : "World"); // Hello
server_print("6. %s", test2 ? "Hello" : "World"); // World
server_print("7. %s", test2 ? (test2 ? "Egg" : "Something") : "Something else"); // Egg
server_print("8. %s", test2 ? (test1 ? "Egg" : "Something") : "Something else"); // Something
server_print("9. %s", test1 ? (test2 ? "Egg" : "Something") : "Something else"); // Something else However, it asserts (line1085, server_print("11. %s", test2 ? (test2 ? fmt("Egg") : "Something") : "Something else"); // Egg
server_print("12. %s", test2 ? (test1 ? fmt("Egg") : "Something") : "Something else"); // Something Note that without the assert, the first works fine, but the second throwns a runtime error. server_print("10. %s", test2 ? (test2 ? fmt("Egg") : fmt("Something")) : fmt("Something else")); // Egg |
Well, no assert and no runtime error. Looks like your patch works better. Maybe this PR is not complete. |
@Arkshine can you try to test it on SP compiler and somehow on upstream compiler? I think only binaries will be enough, I can analyze them in Disassembler. |
Tested it on the upstream compiler and it is also bugged: http://tpcg.io/7OMWqr. UPD: Fixed. |
I tried it, but I see no difference. Still throw an assert, and even without, still see runtime error. |
@Arkshine did you compile it yourself? Or downloaded from the first post? |
8731225
to
c88e58d
Compare
Fixed the wrong order of heaplist nodes and the incorrect calculation of the max. heap usage.
c88e58d
to
114bb00
Compare
@Arkshine sorry, I tested it only on 1.8.1. Now it should work. |
Well, still the same. I have even tried to copy-paste manually hier13() from the PR. |
I see, actually it works, but not with a function retourning an array. server_print("11. %s", test2 ? (test2 ? fmt2("Egg") : "Something") : "Something else"); // Egg
fmt2()
{
new array[256] = "hey";
return array;
} |
Without assertion, it seems to work fine. |
@Arkshine unfortunately it generates bad assembly, try: server_print("42. %s", true ? "Something" : fmt2()); |
It is bugged in SourcePawn too: #include <sourcemod>
#pragma semicolon 1
//#pragma newdecls required
public Plugin myinfo = {
name = "",
author = "",
description = "",
version = "0.0.0",
url = ""
};
public void OnPluginStart()
{
PrintToServer(true ? "Hello, World!" : fmt2());
}
fmt2() {
new arr[256];
return arr;
} There is no heap "free": 0xB68 PROC ; OnPluginStart
0xB6C BREAK
0xB70 BREAK
0xB74 CONST.pri 0x1
0xB7C JZER jump_0000
0xB84 CONST.pri 0x8DC
0xB8C JUMP jump_0001
0xB94 HEAP 0x400 ; target:jump_0000
0xB9C PUSH.alt
0xBA0 PUSH.C 0x0
0xBA8 CALL .3028.fmt2
0xBB0 POP.pri
0xBB4 SM_TRACKER.PUSH.C 0x400
0xBBC PUSH.pri ; target:jump_0001
0xBC0 SYSREQ.N PrintToServer (1 args)
0xBCC ZERO.pri
0xBD0 RETN |
@Arkshine try it. I can add more conditions for the reparsing if necessary. For example we can add a new usage flag I think we can first merge this into the upstream (for review from the compuphase) and then merge it into amxmodx. |
…ed before definition (inside definition (recursion) is a "before definition" situation too)
0596134
to
2aa56fc
Compare
Looks like it doesn't throw an assert anymore. At runtime, it looks fine as well. |
@WPMGPRoSToTeMa Do you think it's needed to add more conditions for the reparsing? |
@Arkshine I think it isn't worth to add them. |
Alright, let's merge in master first and see if people have issues. We are not going to have an answer any time soon from Compuphase. |
Fixes #621.
There are another changes in
hier13
, but I've ported only fix.I'm a bit worry that this fix doesn't save
ALT
register, maybe it is guaranteed thatALT
isn't used across condition and branch body?@rtxa test it please.
Related to #623.