[exim-cvs] cppcheck sliencing

Αρχική Σελίδα
Delete this message
Reply to this message
Συντάκτης: Exim Git Commits Mailing List
Ημερομηνία:  
Προς: exim-cvs
Αντικείμενο: [exim-cvs] cppcheck sliencing
Gitweb: https://git.exim.org/exim.git/commitdiff/d439520cf2ccd61b0a2190bb331b1dded18547b8
Commit:     d439520cf2ccd61b0a2190bb331b1dded18547b8
Parent:     1ed24e36e279c922d3366f6c3144570cc5f54d7a
Author:     Jeremy Harris <jgh146exb@???>
AuthorDate: Tue Dec 20 14:38:26 2022 +0000
Committer:  Jeremy Harris <jgh146exb@???>
CommitDate: Tue Dec 20 14:38:26 2022 +0000


    cppcheck sliencing
---
 src/src/acl.c      |   1 +
 src/src/deliver.c  |  33 +++---------
 src/src/exim.c     |   7 ++-
 src/src/hash.c     |   4 +-
 src/src/host.c     |  13 ++---
 src/src/macros.h   |  11 ++++
 src/src/os.c       |  28 +++++-----
 src/src/retry.c    |  13 +++--
 src/src/smtp_in.c  | 146 ++++++++++++++++++++++++++++-------------------------
 src/src/spool_in.c |   8 +--
 src/src/string.c   |   4 +-
 11 files changed, 129 insertions(+), 139 deletions(-)


diff --git a/src/src/acl.c b/src/src/acl.c
index 74b59b0fe..5ab674776 100644
--- a/src/src/acl.c
+++ b/src/src/acl.c
@@ -2550,6 +2550,7 @@ else switch(mode)
     anchor = NULL; /* silence an "unused" complaint */
     log_write(0, LOG_MAIN|LOG_PANIC_DIE,
       "internal ACL error: unknown ratelimit mode %d", mode);
+    /*NOTREACHED*/
     break;
   }


diff --git a/src/src/deliver.c b/src/src/deliver.c
index c4fce4602..c5e00eaef 100644
--- a/src/src/deliver.c
+++ b/src/src/deliver.c
@@ -342,13 +342,7 @@ if (Ustrstr(filename, US"/../"))
 for (int i = 2; i > 0; i--)
   {
   int fd = Uopen(filename,
-#ifdef O_CLOEXEC
-    O_CLOEXEC |
-#endif
-#ifdef O_NOFOLLOW
-    O_NOFOLLOW |
-#endif
-        O_WRONLY|O_APPEND|O_CREAT, mode);
+        EXIM_CLOEXEC | EXIM_NOFOLLOW | O_WRONLY|O_APPEND|O_CREAT, mode);
   if (fd >= 0)
     {
     /* Set the close-on-exec flag and change the owner to the exim uid/gid (this
@@ -4705,17 +4699,13 @@ all pipes, so I do not see a reason to use non-blocking IO here
     {
     uschar * fname = spool_fname(US"input", message_subdir, message_id, US"-D");


-    if ((deliver_datafile = Uopen(fname,
-#ifdef O_CLOEXEC
-                    O_CLOEXEC |
-#endif
-                    O_RDWR | O_APPEND, 0)) < 0)
+    if (  (deliver_datafile = Uopen(fname, EXIM_CLOEXEC | O_RDWR | O_APPEND, 0))
+    < 0)
       log_write(0, LOG_MAIN|LOG_PANIC_DIE, "Failed to reopen %s for remote "
         "parallel delivery: %s", fname, strerror(errno));
     }


-    /* Set the close-on-exec flag */
-#ifndef O_CLOEXEC
+#ifndef O_CLOEXEC            /* Set the close-on-exec flag */
     (void)fcntl(deliver_datafile, F_SETFD, fcntl(deliver_datafile, F_GETFD) |
       FD_CLOEXEC);
 #endif
@@ -5749,14 +5739,8 @@ Otherwise it might be needed again. */
   uschar * fname = spool_fname(US"input", message_subdir, id, US"-J");
   FILE * jread;


-  if (  (journal_fd = Uopen(fname, O_RDWR|O_APPEND
-#ifdef O_CLOEXEC
-                    | O_CLOEXEC
-#endif
-#ifdef O_NOFOLLOW
-                    | O_NOFOLLOW
-#endif
-    , SPOOL_MODE)) >= 0
+  if (  (journal_fd = Uopen(fname,
+          O_RDWR|O_APPEND | EXIM_CLOEXEC | EXIM_NOFOLLOW, SPOOL_MODE)) >= 0
      && lseek(journal_fd, 0, SEEK_SET) == 0
      && (jread = fdopen(journal_fd, "rb"))
      )
@@ -7154,10 +7138,7 @@ if (addr_local || addr_remote)
     uschar * fname = spool_fname(US"input", message_subdir, id, US"-J");


     if ((journal_fd = Uopen(fname,
-#ifdef O_CLOEXEC
-            O_CLOEXEC |
-#endif
-            O_WRONLY|O_APPEND|O_CREAT|O_EXCL, SPOOL_MODE)) < 0)
+          EXIM_CLOEXEC | O_WRONLY|O_APPEND|O_CREAT|O_EXCL, SPOOL_MODE)) < 0)
       {
       log_write(0, LOG_MAIN|LOG_PANIC, "Couldn't open journal file %s: %s",
     fname, strerror(errno));
diff --git a/src/src/exim.c b/src/src/exim.c
index 35f4ae4f7..dc082f392 100644
--- a/src/src/exim.c
+++ b/src/src/exim.c
@@ -841,6 +841,7 @@ exim_fail(const char * fmt, ...)
 va_list ap;
 va_start(ap, fmt);
 vfprintf(stderr, fmt, ap);
+va_end(ap);
 exit(EXIT_FAILURE);
 }


@@ -1224,13 +1225,11 @@ DEBUG(D_any)
 #if defined(__clang__)
   g = string_fmt_append(g, "Compiler: CLang [%s]\n", __clang_version__);
 #elif defined(__GNUC__)
-  g = string_fmt_append(g, "Compiler: GCC [%s]\n",
 # ifdef __VERSION__
-      __VERSION__
+  g = string_fmt_append(g, "Compiler: GCC [%s]\n", __VERSION__);
 # else
-      "? unknown version ?"
+  g = string_fmt_append(g, "Compiler: GCC [%s]\n", "? unknown version ?";
 # endif
-      );
 #else
   g = string_cat(g, US"Compiler: <unknown>\n");
 #endif
diff --git a/src/src/hash.c b/src/src/hash.c
index 10af1b43d..95860fc50 100644
--- a/src/src/hash.c
+++ b/src/src/hash.c
@@ -408,7 +408,7 @@ Returns:    nothing
 */


static void
-native_sha1_end(sha1 *base, const uschar *text, int length, uschar *digest)
+native_sha1_end(sha1 * base, const uschar * text, int length, uschar * digest)
{
uschar work[64];

@@ -426,7 +426,7 @@ out to 64, process it, and then set up the final chunk as 56 bytes of
padding. If it has less than 56 bytes, we pad it out to 56 bytes as the
final chunk. */

-memcpy(work, text, length);
+if (length) memcpy(work, text, length);
work[length] = 0x80;

 if (length > 55)
diff --git a/src/src/host.c b/src/src/host.c
index ecdc6d681..8d53eb3de 100644
--- a/src/src/host.c
+++ b/src/src/host.c
@@ -912,7 +912,7 @@ Returns:     the number of ints used
 */


int
-host_aton(const uschar *address, int *bin)
+host_aton(const uschar * address, int * bin)
{
int x[4];
int v4offset = 0;
@@ -924,13 +924,10 @@ supported. */

if (Ustrchr(address, ':') != NULL)
{
- const uschar *p = address;
- const uschar *component[8];
+ const uschar * p = address;
+ const uschar * component[8];
BOOL ipv4_ends = FALSE;
- int ci = 0;
- int nulloffset = 0;
- int v6count = 8;
- int i;
+ int ci = 0, nulloffset = 0, v6count = 8, i;

/* If the address starts with a colon, it will start with two colons.
Just lose the first one, which will leave a null first component. */
@@ -942,7 +939,7 @@ if (Ustrchr(address, ':') != NULL)
overlooked; to guard against that happening again, check here and crash if
there are too many components. */

-  while (*p != 0 && *p != '%')
+  while (*p && *p != '%')
     {
     int len = Ustrcspn(p, ":%");
     if (len == 0) nulloffset = ci;
diff --git a/src/src/macros.h b/src/src/macros.h
index 243c1e5a0..a631877a1 100644
--- a/src/src/macros.h
+++ b/src/src/macros.h
@@ -1125,4 +1125,15 @@ typedef unsigned mcs_flags;
 #define MCS_AT_SPECIAL        BIT(2)    /* recognize @, @[], etc. */
 #define MCS_CACHEABLE        BIT(3)    /* no dynamic expansions used for pattern */


+/* Flags for open() */
+#ifdef O_CLOEXEC
+# define EXIM_CLOEXEC O_CLOEXEC
+#else
+# define EXIM_CLOEXEC 0
+#endif
+#ifdef O_NOFOLLOW
+# define EXIM_NOFOLLOW O_NOFOLLOW
+#else
+# define EXIM_NOFOLLOW 0
+#endif
/* End of macros.h */
diff --git a/src/src/os.c b/src/src/os.c
index fc29f1766..87a336935 100644
--- a/src/src/os.c
+++ b/src/src/os.c
@@ -11,6 +11,8 @@
# include <signal.h>
# include <stdio.h>
# include <time.h>
+#else
+# define DEBUG(x) if (debug_selector & (x))
#endif

#ifndef CS
@@ -50,9 +52,9 @@ sigemptyset(&(act.sa_mask));
act.sa_flags = SA_RESTART;
sigaction(sig, &act, NULL);

-#ifdef STAND_ALONE
+# ifdef STAND_ALONE
printf("Used SA_RESTART\n");
-#endif
+# endif

/* SunOS4 and Ultrix default to non-interruptable signals, with SV_INTERRUPT
for making them interruptable. This seems to be a dying fashion. */
@@ -60,9 +62,9 @@ for making them interruptable. This seems to be a dying fashion. */
#elif defined SV_INTERRUPT
signal(sig, handler);

-#ifdef STAND_ALONE
+# ifdef STAND_ALONE
printf("Used default signal()\n");
-#endif
+# endif


/* If neither SA_RESTART nor SV_INTERRUPT is available we don't know how to
@@ -71,9 +73,9 @@ set up a restarting signal, so simply suppress the facility. */
#else
signal(sig, SIG_IGN);

-#ifdef STAND_ALONE
+# ifdef STAND_ALONE
printf("Used SIG_IGN\n");
-#endif
+# endif

#endif
}
@@ -361,9 +363,9 @@ here as there is the -hal variant, and other systems might follow this road one
day. */

#if !defined(OS_LOAD_AVERAGE) && defined(HAVE_KSTAT)
-#define OS_LOAD_AVERAGE
+# define OS_LOAD_AVERAGE

-#include <kstat.h>
+# include <kstat.h>

int
os_getloadavg(void)
@@ -397,7 +399,7 @@ return avg;
#if !defined(OS_LOAD_AVERAGE) && defined(HAVE_DEV_KMEM)
#define OS_LOAD_AVERAGE

-#include <nlist.h>
+# include <nlist.h>

 static int  avg_kd = -1;
 static long avg_offset;
@@ -481,7 +483,7 @@ Returns:      a chain of ip_address_items, each pointing to a textual


#ifdef HAVE_GETIFADDRS

-#include <ifaddrs.h>
+# include <ifaddrs.h>

ip_address_item *
os_common_find_running_interfaces(void)
@@ -630,13 +632,13 @@ what we want to know. */

 if ((vs = socket(FAMILY, SOCK_DGRAM, 0)) < 0)
   {
-  #if HAVE_IPV6
+#if HAVE_IPV6
   DEBUG(D_interface)
     debug_printf("Unable to create IPv6 socket to find interface addresses:\n  "
       "error %d %s\nTrying for an IPv4 socket\n", errno, strerror(errno));
   vs = socket(AF_INET, SOCK_DGRAM, 0);
   if (vs < 0)
-  #endif
+#endif
   log_write(0, LOG_PANIC_DIE, "Unable to create IPv4 socket to find interface "
     "addresses: %d %s", errno, strerror(errno));
   }
@@ -816,7 +818,7 @@ programmer creates their own structs. */


#if !defined(OS_GET_DNS_RESOLVER_RES) && !defined(COMPILE_UTILITY)

-#include <resolv.h>
+# include <resolv.h>

 /* confirmed that res_state is typedef'd as a struct* on BSD and Linux, will
 find out how unportable it is on other OSes, but most resolver implementations
diff --git a/src/src/retry.c b/src/src/retry.c
index a34bf80ca..1897c782f 100644
--- a/src/src/retry.c
+++ b/src/src/retry.c
@@ -518,8 +518,8 @@ Returns:        nothing
 */


void
-retry_update(address_item **addr_defer, address_item **addr_failed,
- address_item **addr_succeed)
+retry_update(address_item ** addr_defer, address_item ** addr_failed,
+ address_item ** addr_succeed)
{
open_db dbblock;
open_db *dbm_file = NULL;
@@ -533,11 +533,10 @@ to the failed chain if they have timed out. */

 for (int i = 0; i < 3; i++)
   {
-  address_item *endaddr, *addr;
-  address_item *last_first = NULL;
-  address_item **paddr = i==0 ? addr_succeed :
-    i==1 ? addr_failed : addr_defer;
-  address_item **saved_paddr = NULL;
+  address_item * endaddr, *addr;
+  address_item * last_first = NULL;
+  address_item ** paddr = i==0 ? addr_succeed : i==1 ? addr_failed : addr_defer;
+  address_item ** saved_paddr = NULL;


   DEBUG(D_retry) debug_printf("%s addresses:\n",
     i == 0 ? "Succeeded" : i == 1 ? "Failed" : "Deferred");
diff --git a/src/src/smtp_in.c b/src/src/smtp_in.c
index 6c043d434..1cfcc0404 100644
--- a/src/src/smtp_in.c
+++ b/src/src/smtp_in.c
@@ -2680,32 +2680,32 @@ if (!f.sender_host_unknown)


#if !HAVE_IPV6 && !defined(NO_IP_OPTIONS)

-  #ifdef GLIBC_IP_OPTIONS
-    #if (!defined __GLIBC__) || (__GLIBC__ < 2)
-    #define OPTSTYLE 1
-    #else
-    #define OPTSTYLE 2
-    #endif
-  #elif defined DARWIN_IP_OPTIONS
-    #define OPTSTYLE 2
-  #else
-    #define OPTSTYLE 3
-  #endif
+# ifdef GLIBC_IP_OPTIONS
+#  if (!defined __GLIBC__) || (__GLIBC__ < 2)
+#   define OPTSTYLE 1
+#  else
+#   define OPTSTYLE 2
+#  endif
+# elif defined DARWIN_IP_OPTIONS
+# define OPTSTYLE 2
+# else
+# define OPTSTYLE 3
+# endif


   if (!host_checking && !f.sender_host_notsocket)
     {
-    #if OPTSTYLE == 1
+# if OPTSTYLE == 1
     EXIM_SOCKLEN_T optlen = sizeof(struct ip_options) + MAX_IPOPTLEN;
     struct ip_options *ipopt = store_get(optlen, GET_UNTAINTED);
-    #elif OPTSTYLE == 2
+# elif OPTSTYLE == 2
     struct ip_opts ipoptblock;
     struct ip_opts *ipopt = &ipoptblock;
     EXIM_SOCKLEN_T optlen = sizeof(ipoptblock);
-    #else
+# else
     struct ipoption ipoptblock;
     struct ipoption *ipopt = &ipoptblock;
     EXIM_SOCKLEN_T optlen = sizeof(ipoptblock);
-    #endif
+# endif


     /* Occasional genuine failures of getsockopt() have been seen - for
     example, "reset by peer". Therefore, just log and give up on this
@@ -2735,19 +2735,19 @@ if (!f.sender_host_unknown)


     else if (optlen > 0)
       {
-      uschar *p = big_buffer;
-      uschar *pend = big_buffer + big_buffer_size;
-      uschar *adptr;
+      uschar * p = big_buffer;
+      uschar * pend = big_buffer + big_buffer_size;
+      uschar * adptr;
       int optcount;
       struct in_addr addr;


-      #if OPTSTYLE == 1
-      uschar *optstart = US (ipopt->__data);
-      #elif OPTSTYLE == 2
-      uschar *optstart = US (ipopt->ip_opts);
-      #else
-      uschar *optstart = US (ipopt->ipopt_list);
-      #endif
+# if OPTSTYLE == 1
+      uschar * optstart = US (ipopt->__data);
+# elif OPTSTYLE == 2
+      uschar * optstart = US (ipopt->ip_opts);
+# else
+      uschar * optstart = US (ipopt->ipopt_list);
+# endif


       DEBUG(D_receive) debug_printf("IP options exist\n");


@@ -2758,59 +2758,65 @@ if (!f.sender_host_unknown)
         switch (*opt)
           {
           case IPOPT_EOL:
-          opt = NULL;
-          break;
+        opt = NULL;
+        break;


           case IPOPT_NOP:
-          opt++;
-          break;
+        opt++;
+        break;


           case IPOPT_SSRR:
           case IPOPT_LSRR:
-          if (!string_format(p, pend-p, " %s [@%s",
-               (*opt == IPOPT_SSRR)? "SSRR" : "LSRR",
-               #if OPTSTYLE == 1
-               inet_ntoa(*((struct in_addr *)(&(ipopt->faddr))))))
-               #elif OPTSTYLE == 2
-               inet_ntoa(ipopt->ip_dst)))
-               #else
-               inet_ntoa(ipopt->ipopt_dst)))
-               #endif
-            {
-            opt = NULL;
-            break;
-            }
+        if (!
+# if OPTSTYLE == 1
+             string_format(p, pend-p, " %s [@%s",
+         (*opt == IPOPT_SSRR)? "SSRR" : "LSRR",
+         inet_ntoa(*((struct in_addr *)(&(ipopt->faddr)))))
+# elif OPTSTYLE == 2
+             string_format(p, pend-p, " %s [@%s",
+         (*opt == IPOPT_SSRR)? "SSRR" : "LSRR",
+         inet_ntoa(ipopt->ip_dst))
+# else
+             string_format(p, pend-p, " %s [@%s",
+         (*opt == IPOPT_SSRR)? "SSRR" : "LSRR",
+         inet_ntoa(ipopt->ipopt_dst))
+# endif
+          )
+          {
+          opt = NULL;
+          break;
+          }


-          p += Ustrlen(p);
-          optcount = (opt[1] - 3) / sizeof(struct in_addr);
-          adptr = opt + 3;
-          while (optcount-- > 0)
-            {
-            memcpy(&addr, adptr, sizeof(addr));
-            if (!string_format(p, pend - p - 1, "%s%s",
-                  (optcount == 0)? ":" : "@", inet_ntoa(addr)))
-              {
-              opt = NULL;
-              break;
-              }
-            p += Ustrlen(p);
-            adptr += sizeof(struct in_addr);
-            }
-          *p++ = ']';
-          opt += opt[1];
-          break;
+        p += Ustrlen(p);
+        optcount = (opt[1] - 3) / sizeof(struct in_addr);
+        adptr = opt + 3;
+        while (optcount-- > 0)
+          {
+          memcpy(&addr, adptr, sizeof(addr));
+          if (!string_format(p, pend - p - 1, "%s%s",
+            (optcount == 0)? ":" : "@", inet_ntoa(addr)))
+        {
+        opt = NULL;
+        break;
+        }
+          p += Ustrlen(p);
+          adptr += sizeof(struct in_addr);
+          }
+        *p++ = ']';
+        opt += opt[1];
+        break;


           default:
-            {
-            if (pend - p < 4 + 3*opt[1]) { opt = NULL; break; }
-            Ustrcat(p, "[ ");
-            p += 2;
-            for (int i = 0; i < opt[1]; i++)
-              p += sprintf(CS p, "%2.2x ", opt[i]);
-            *p++ = ']';
-            }
-          opt += opt[1];
-          break;
+          {
+          if (pend - p < 4 + 3*opt[1]) { opt = NULL; break; }
+          Ustrcat(p, "[ ");
+          p += 2;
+          for (int i = 0; i < opt[1]; i++)
+        p += sprintf(CS p, "%2.2x ", opt[i]);
+          *p++ = ']';
+          }
+        opt += opt[1];
+        break;
           }


       *p = 0;
diff --git a/src/src/spool_in.c b/src/src/spool_in.c
index 6d6651f57..e785f695b 100644
--- a/src/src/spool_in.c
+++ b/src/src/spool_in.c
@@ -64,13 +64,7 @@ for (int i = 0; i < 2; i++)
    * No -D file inside the spool area should be a symlink.
    */
   if ((fd = Uopen(fname,
-#ifdef O_CLOEXEC
-              O_CLOEXEC |
-#endif
-#ifdef O_NOFOLLOW
-              O_NOFOLLOW |
-#endif
-              O_RDWR | O_APPEND, 0)) >= 0)
+          EXIM_CLOEXEC | EXIM_NOFOLLOW | O_RDWR | O_APPEND, 0)) >= 0)
     break;
   save_errno = errno;
   if (errno == ENOENT)
diff --git a/src/src/string.c b/src/src/string.c
index 2cb419517..b30673c04 100644
--- a/src/src/string.c
+++ b/src/src/string.c
@@ -1783,7 +1783,7 @@ while (fgets(CS buffer, sizeof(buffer), stdin) != NULL)
   int llflag = 0;
   int n = 0;
   int count;
-  int countset = 0;
+  BOOL countset = FASE;
   uschar format[256];
   uschar outbuf[256];
   uschar *s;
@@ -1825,7 +1825,7 @@ while (fgets(CS buffer, sizeof(buffer), stdin) != NULL)
     else if (Ustrcmp(ss, "*") == 0)
       {
       args[n++] = (void *)(&count);
-      countset = 1;
+      countset = TRUE;
       }


     else