]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
dns-domain: use PTR_SUB1() macro 22800/head
authorYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Mar 2022 12:56:19 +0000 (21:56 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Wed, 23 Mar 2022 12:57:59 +0000 (21:57 +0900)
src/shared/dns-domain.c

index 48395fea24e507eb1f8af165e3b9d1bbaaa89849..0ae1de1c5b2817c8ba623d9312171040f1cd056d 100644 (file)
@@ -168,24 +168,18 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
 
         /* Skip current terminal character (and accept domain names ending it ".") */
         if (*terminal == 0)
-                terminal--;
+                terminal = PTR_SUB1(terminal, name);
         if (terminal >= name && *terminal == '.')
-                terminal--;
+                terminal = PTR_SUB1(terminal, name);
 
         /* Point name to the last label, and terminal to the preceding terminal symbol (or make it a NULL pointer) */
-        for (;;) {
-                if (terminal < name) {
-                        /* Reached the first label, so indicate that there are no more */
-                        terminal = NULL;
-                        break;
-                }
-
+        while (terminal) {
                 /* Find the start of the last label */
                 if (*terminal == '.') {
                         const char *y;
                         unsigned slashes = 0;
 
-                        for (y = terminal - 1; y >= name && *y == '\\'; y--)
+                        for (y = PTR_SUB1(terminal, name); y && *y == '\\'; y = PTR_SUB1(y, name))
                                 slashes++;
 
                         if (slashes % 2 == 0) {
@@ -198,7 +192,7 @@ int dns_label_unescape_suffix(const char *name, const char **label_terminal, cha
                         }
                 }
 
-                terminal--;
+                terminal = PTR_SUB1(terminal, name);
         }
 
         r = dns_label_unescape(&name, dest, sz, 0);