]> git.rm.cloudns.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
Fix REGISTRY_CHECK not checking all elements of a huge registry like the Notification...
authorterencehill <piuntn@gmail.com>
Wed, 7 Feb 2024 21:40:06 +0000 (22:40 +0100)
committerterencehill <piuntn@gmail.com>
Wed, 7 Feb 2024 21:40:06 +0000 (22:40 +0100)
Code is optimized to have basically the same performance as before while adding string length checks.

qcsrc/lib/registry.qh

index fdcc730a068527b73b4a1e2291fc910616e9b53f..5d36e1a3936b559d65675562ed1a17c69c7d427a 100644 (file)
@@ -177,8 +177,25 @@ void Registry_send(string id, string hash);
        STATIC_INIT(Registry_check_##id) \
        { \
                /* Note: SHA256 isn't always available, use MD4 instead */ \
-               string s = ""; \
-               FOREACH(id, true, s = strcat(s, ":", it.registered_id)); \
+               string s = "", group = ""; \
+               int str_len = 0, digests_len = 0, group_idx = 0; \
+               FOREACH(id, true, { \
+                       group = strcat(group, ":", it.registered_id); \
+                       if (++group_idx < 50) /* this is to reduce strlen calls */ \
+                               continue; \
+                       int group_len = strlen(group); \
+                       if (str_len + 1 + group_len >= 16383) /* exceeding max string length? */ \
+                       { \
+                               /* keep previous digests and replace current string with its digest */ \
+                               s = strcat(substring(s, 0, digests_len), ":", digest_hex("MD4", s)); \
+                               digests_len = str_len = strlen(s); \
+                       } \
+                       s = strcat(s, group); \
+                       str_len += group_len; \
+                       group = ""; \
+                       group_idx = 0; \
+               }); \
+               s = strcat(s, group); \
                s = substring(s, 1, -1); /* remove initial ":" */ \
                string h = REGISTRY_HASH(id) = strzone(digest_hex("MD4", s)); \
                LOG_DEBUGF(#id ": %s\n[%s]", h, s); \