diff options
author | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-12-26 19:48:38 +0200 |
---|---|---|
committer | Avi Halachmi (:avih) <avihpit@yahoo.com> | 2021-12-26 20:02:45 +0200 |
commit | 5c5e35c1bcf9ccfa471dc590caf0c25ee158ca03 (patch) | |
tree | a2875e2df825533326d4d02236ebfab472239e59 /player | |
parent | d92cf77be56190dfd7fbac3724f290ceb6ff9437 (diff) | |
download | mpv-5c5e35c1bcf9ccfa471dc590caf0c25ee158ca03.tar.bz2 mpv-5c5e35c1bcf9ccfa471dc590caf0c25ee158ca03.tar.xz |
js: fix event registration (keys, script-message, more)
Commit 63205981 removed some events but left all other event IDs at
their original values, which created "holes" at the events IDs array.
The JS backend for mp.register_event maps a name to an ID by scanning
all IDs and stopping when the name was found or a NULL name was
returned. Lua does the same except that it doesn't stop on NULL name.
Previously it was not possible to have a NULL name before the end of
the array, but now it is possible due to the enumeration holes.
Fix by skipping missing names, like lua does.
Diffstat (limited to 'player')
-rw-r--r-- | player/javascript.c | 6 |
1 files changed, 3 insertions, 3 deletions
diff --git a/player/javascript.c b/player/javascript.c index 50a1550690..d4191c582b 100644 --- a/player/javascript.c +++ b/player/javascript.c @@ -610,9 +610,9 @@ static void script__request_event(js_State *J) const char *event = js_tostring(J, 1); bool enable = js_toboolean(J, 2); - const char *name; - for (int n = 0; n < 256 && (name = mpv_event_name(n)); n++) { - if (strcmp(name, event) == 0) { + for (int n = 0; n < 256; n++) { + const char *name = mpv_event_name(n); + if (name && strcmp(name, event) == 0) { push_status(J, mpv_request_event(jclient(J), n, enable)); return; } |