hexchat-javascript
hexchat-javascript copied to clipboard
HexChat crashes when a long array is passed to a hook_server callback function
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).
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.
Just a guess here but can you test changing this line: https://github.com/TingPing/hexchat-javascript/blob/7d20a1b9e9d447ef6c195ce6e0b0e1ba2a980c66/javascript.cpp#L164
To:
for (int i = 0; word[i] && word[i][0]; i++)
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.)