Fix Linux kernel coding style error
authorDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sat, 17 Jul 2021 07:58:10 +0000 (09:58 +0200)
committerDimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
Sun, 18 Jul 2021 23:02:34 +0000 (01:02 +0200)
Macros starting with if should be enclosed by a do - while loop
to avoid possible if/else logic defects

Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com>
openconnect-internal.h

index 56cfbc7fca54a4675e7fc75d3d8da18eed1e25c6..71188cff04829e05f5e7bca918f2a75e09045781 100644 (file)
@@ -1571,29 +1571,35 @@ static inline int strprefix_match(const char *str, int len, const char *match)
 }
 
 #define STRDUP(res, arg) \
-       if (res != arg) {                                       \
-               free(res);                                      \
-               if (arg) {                                      \
-                       res = strdup(arg);                      \
-                       if (res == NULL) return -ENOMEM;        \
-               } else res = NULL;                              \
+       do {                                                            \
+               if (res != arg) {                                       \
+                       free(res);                                      \
+                       if (arg) {                                      \
+                               res = strdup(arg);                      \
+                               if (res == NULL) return -ENOMEM;        \
+                       } else res = NULL;                              \
+               }                                                       \
        } while(0)
 
 #define UTF8CHECK(arg) \
-       if ((arg) && buf_append_utf16le(NULL, (arg))) { \
-               vpn_progress(vpninfo, PRG_ERR,                          \
-                            _("ERROR: %s() called with invalid UTF-8 for '%s' argument\n"),\
-                            __func__, #arg);                           \
-               return -EILSEQ;                                         \
-       }
+       do {                                                            \
+               if ((arg) && buf_append_utf16le(NULL, (arg))) {         \
+                       vpn_progress(vpninfo, PRG_ERR,                  \
+                                    _("ERROR: %s() called with invalid UTF-8 for '%s' argument\n"),\
+                                    __func__, #arg);                   \
+                       return -EILSEQ;                                 \
+               }                                                       \
+       } while(0)
 
 #define UTF8CHECK_VOID(arg) \
-       if ((arg) && buf_append_utf16le(NULL, (arg))) { \
-               vpn_progress(vpninfo, PRG_ERR,                          \
-                            _("ERROR: %s() called with invalid UTF-8 for '%s' argument\n"),\
-                            __func__, #arg);                           \
-               return;                                                 \
-       }
+       do {                                                            \
+               if ((arg) && buf_append_utf16le(NULL, (arg))) {         \
+                       vpn_progress(vpninfo, PRG_ERR,                  \
+                                    _("ERROR: %s() called with invalid UTF-8 for '%s' argument\n"),\
+                                    __func__, #arg);                   \
+                       return;                                         \
+               }                                                       \
+       } while(0)
 
 /* Let's stop open-coding big-endian and little-endian loads/stores.
  *