Skip to content
This repository has been archived by the owner on May 24, 2024. It is now read-only.

HexChat crashes when a long array is passed to a hook_server callback function #7

Open
danonline opened this issue Apr 16, 2016 · 3 comments

Comments

@danonline
Copy link

I have the following code to display incoming Twitch whispers:

function whisperIn_cb(words) {
    // words example: [':[email protected]', 'WHISPER', 'danpcg', ':test', 'message']
    // should print "pcgdan > danpcg: test message"
    var nick = words[0].replace(/^:(.+)!.+$/, '$1');
    var msg = words.slice(3);
    msg[0] = msg[0].slice(1); // remove leading ":" (':test')

    print(nick + ' > ' + words[2] + ': ' + msg.join(' '));

    return EAT_ALL;
}

hook_server('WHISPER', whisperIn_cb);

It works fine unless the whispered message has more than 27 words. If the message has 28 words or more, the length of the array words is over 30, which probably causes the crash. The code in whisperIn_cb() is not important, as HexChat still crashes if the function is empty.

I have noticed, that if you pass an array that has over 30 elements to a hook_command callback function (e.g. a long outgoing whisper message), the array gets truncated to the length of 30. Is it possible to have arrays that are longer than 30 words? If not, can they at least be truncated for hook_server callback functions, to prevent the crash?

P.S. I have written the same function using the Python interface and it works without any issues (tested with a 100-word whisper).

@TingPing
Copy link
Owner

I have noticed, that if you pass an array that has over 30 elements to a hook_command callback function (e.g. a long outgoing whisper message), the array gets truncated to the length of 30. Is it possible to have arrays that are longer than 30 words?

No this is a limitation within HexChat.

@TingPing
Copy link
Owner

Just a guess here but can you test changing this line:

for (int i = 0; word[i][0]; i++)

To:

    for (int i = 0; word[i] && word[i][0]; i++)

@danonline
Copy link
Author

No this is a limitation within HexChat.

It seems to work with the Python interface, so I thought the issue was because of the JS interface.

Just a guess here but can you test changing this line [...]

Sorry, I've never made anything with C++ before. I tried, but couldn't get Visual Studio to compile. (I'm still using the old javascript-0.3_x64.dll which is provided with the 0.3 release.)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants