Browse Source

Merge branch 'upstream-KWSys' into update-kwsys

# By KWSys Upstream
* upstream-KWSys:
  KWSys 2020-04-10 (b62956f5)
Brad King 5 years ago
parent
commit
0b495b6ca9

+ 4 - 1
Source/kwsys/Base64.c

@@ -130,7 +130,10 @@ size_t kwsysBase64_Encode(const unsigned char* input, size_t length,
 /* Decode 4 bytes into a 3 byte string. */
 /* Decode 4 bytes into a 3 byte string. */
 int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest)
 int kwsysBase64_Decode3(const unsigned char* src, unsigned char* dest)
 {
 {
-  unsigned char d0, d1, d2, d3;
+  unsigned char d0;
+  unsigned char d1;
+  unsigned char d2;
+  unsigned char d3;
 
 
   d0 = kwsysBase64DecodeChar(src[0]);
   d0 = kwsysBase64DecodeChar(src[0]);
   d1 = kwsysBase64DecodeChar(src[1]);
   d1 = kwsysBase64DecodeChar(src[1]);

+ 16 - 8
Source/kwsys/MD5.c

@@ -171,8 +171,10 @@ typedef struct md5_state_s
 
 
 static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/)
 static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/)
 {
 {
-  md5_word_t a = pms->abcd[0], b = pms->abcd[1], c = pms->abcd[2],
-             d = pms->abcd[3];
+  md5_word_t a = pms->abcd[0];
+  md5_word_t b = pms->abcd[1];
+  md5_word_t c = pms->abcd[2];
+  md5_word_t d = pms->abcd[3];
   md5_word_t t;
   md5_word_t t;
 #if BYTE_ORDER > 0
 #if BYTE_ORDER > 0
   /* Define storage only for big-endian CPUs. */
   /* Define storage only for big-endian CPUs. */
@@ -227,9 +229,10 @@ static void md5_process(md5_state_t* pms, const md5_byte_t* data /*[64]*/)
 #  else
 #  else
 #    define xbuf X /* (static only) */
 #    define xbuf X /* (static only) */
 #  endif
 #  endif
-      for (i = 0; i < 16; ++i, xp += 4)
+      for (i = 0; i < 16; ++i, xp += 4) {
         xbuf[i] =
         xbuf[i] =
           (md5_word_t)(xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24));
           (md5_word_t)(xp[0] + (xp[1] << 8) + (xp[2] << 16) + (xp[3] << 24));
+      }
     }
     }
 #endif
 #endif
   }
   }
@@ -367,34 +370,39 @@ static void md5_append(md5_state_t* pms, const md5_byte_t* data, size_t nbytes)
   size_t offset = (pms->count[0] >> 3) & 63;
   size_t offset = (pms->count[0] >> 3) & 63;
   md5_word_t nbits = (md5_word_t)(nbytes << 3);
   md5_word_t nbits = (md5_word_t)(nbytes << 3);
 
 
-  if (nbytes <= 0)
+  if (nbytes <= 0) {
     return;
     return;
+  }
 
 
   /* Update the message length. */
   /* Update the message length. */
   pms->count[1] += (md5_word_t)(nbytes >> 29);
   pms->count[1] += (md5_word_t)(nbytes >> 29);
   pms->count[0] += nbits;
   pms->count[0] += nbits;
-  if (pms->count[0] < nbits)
+  if (pms->count[0] < nbits) {
     pms->count[1]++;
     pms->count[1]++;
+  }
 
 
   /* Process an initial partial block. */
   /* Process an initial partial block. */
   if (offset) {
   if (offset) {
     size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
     size_t copy = (offset + nbytes > 64 ? 64 - offset : nbytes);
 
 
     memcpy(pms->buf + offset, p, copy);
     memcpy(pms->buf + offset, p, copy);
-    if (offset + copy < 64)
+    if (offset + copy < 64) {
       return;
       return;
+    }
     p += copy;
     p += copy;
     left -= copy;
     left -= copy;
     md5_process(pms, pms->buf);
     md5_process(pms, pms->buf);
   }
   }
 
 
   /* Process full blocks. */
   /* Process full blocks. */
-  for (; left >= 64; p += 64, left -= 64)
+  for (; left >= 64; p += 64, left -= 64) {
     md5_process(pms, p);
     md5_process(pms, p);
+  }
 
 
   /* Process a final partial block. */
   /* Process a final partial block. */
-  if (left)
+  if (left) {
     memcpy(pms->buf, p, left);
     memcpy(pms->buf, p, left);
+  }
 }
 }
 
 
 /* Finish the message and return the digest. */
 /* Finish the message and return the digest. */

+ 101 - 96
Source/kwsys/ProcessUNIX.c

@@ -432,8 +432,8 @@ int kwsysProcess_AddCommand(kwsysProcess* cp, char const* const* command)
     char const* const* c = command;
     char const* const* c = command;
     kwsysProcess_ptrdiff_t n = 0;
     kwsysProcess_ptrdiff_t n = 0;
     kwsysProcess_ptrdiff_t i = 0;
     kwsysProcess_ptrdiff_t i = 0;
-    while (*c++)
-      ;
+    while (*c++) {
+    }
     n = c - command - 1;
     n = c - command - 1;
     newCommands[cp->NumberOfCommands] =
     newCommands[cp->NumberOfCommands] =
       (char**)malloc((size_t)(n + 1) * sizeof(char*));
       (char**)malloc((size_t)(n + 1) * sizeof(char*));
@@ -685,7 +685,8 @@ const char* kwsysProcess_GetErrorString(kwsysProcess* cp)
 {
 {
   if (!cp) {
   if (!cp) {
     return "Process management structure could not be allocated";
     return "Process management structure could not be allocated";
-  } else if (cp->State == kwsysProcess_State_Error) {
+  }
+  if (cp->State == kwsysProcess_State_Error) {
     return cp->ErrorMessage;
     return cp->ErrorMessage;
   }
   }
   return "Success";
   return "Success";
@@ -695,7 +696,8 @@ const char* kwsysProcess_GetExceptionString(kwsysProcess* cp)
 {
 {
   if (!(cp && cp->ProcessResults && (cp->NumberOfCommands > 0))) {
   if (!(cp && cp->ProcessResults && (cp->NumberOfCommands > 0))) {
     return "GetExceptionString called with NULL process management structure";
     return "GetExceptionString called with NULL process management structure";
-  } else if (cp->State == kwsysProcess_State_Exception) {
+  }
+  if (cp->State == kwsysProcess_State_Exception) {
     return cp->ProcessResults[cp->NumberOfCommands - 1].ExitExceptionString;
     return cp->ProcessResults[cp->NumberOfCommands - 1].ExitExceptionString;
   }
   }
   return "No exception";
   return "No exception";
@@ -787,8 +789,8 @@ void kwsysProcess_Execute(kwsysProcess* cp)
 
 
     /* Some platforms specify that the chdir call may be
     /* Some platforms specify that the chdir call may be
        interrupted.  Repeat the call until it finishes.  */
        interrupted.  Repeat the call until it finishes.  */
-    while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR))
-      ;
+    while (((r = chdir(cp->WorkingDirectory)) < 0) && (errno == EINTR)) {
+    }
     if (r < 0) {
     if (r < 0) {
       kwsysProcessCleanup(cp, 1);
       kwsysProcessCleanup(cp, 1);
       return;
       return;
@@ -1014,8 +1016,8 @@ void kwsysProcess_Execute(kwsysProcess* cp)
   if (cp->RealWorkingDirectory) {
   if (cp->RealWorkingDirectory) {
     /* Some platforms specify that the chdir call may be
     /* Some platforms specify that the chdir call may be
        interrupted.  Repeat the call until it finishes.  */
        interrupted.  Repeat the call until it finishes.  */
-    while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR))
-      ;
+    while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) {
+    }
     free(cp->RealWorkingDirectory);
     free(cp->RealWorkingDirectory);
     cp->RealWorkingDirectory = 0;
     cp->RealWorkingDirectory = 0;
   }
   }
@@ -1100,22 +1102,22 @@ int kwsysProcess_WaitForData(kwsysProcess* cp, char** data, int* length,
   if (wd.PipeId) {
   if (wd.PipeId) {
     /* Data are ready on a pipe.  */
     /* Data are ready on a pipe.  */
     return wd.PipeId;
     return wd.PipeId;
-  } else if (wd.Expired) {
+  }
+  if (wd.Expired) {
     /* A timeout has expired.  */
     /* A timeout has expired.  */
     if (wd.User) {
     if (wd.User) {
       /* The user timeout has expired.  It has no time left.  */
       /* The user timeout has expired.  It has no time left.  */
       return kwsysProcess_Pipe_Timeout;
       return kwsysProcess_Pipe_Timeout;
-    } else {
-      /* The process timeout has expired.  Kill the children now.  */
-      kwsysProcess_Kill(cp);
-      cp->Killed = 0;
-      cp->TimeoutExpired = 1;
-      return kwsysProcess_Pipe_None;
     }
     }
-  } else {
-    /* No pipes are left open.  */
+
+    /* The process timeout has expired.  Kill the children now.  */
+    kwsysProcess_Kill(cp);
+    cp->Killed = 0;
+    cp->TimeoutExpired = 1;
     return kwsysProcess_Pipe_None;
     return kwsysProcess_Pipe_None;
   }
   }
+  /* No pipes are left open.  */
+  return kwsysProcess_Pipe_None;
 }
 }
 
 
 static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
 static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
@@ -1184,7 +1186,7 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
 
 
   /* Make sure the set is empty (it should always be empty here
   /* Make sure the set is empty (it should always be empty here
      anyway).  */
      anyway).  */
-  FD_ZERO(&cp->PipeSet);
+  FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration)
 
 
   /* Setup a timeout if required.  */
   /* Setup a timeout if required.  */
   if (wd->TimeoutTime.tv_sec < 0) {
   if (wd->TimeoutTime.tv_sec < 0) {
@@ -1227,7 +1229,8 @@ static int kwsysProcessWaitForPipe(kwsysProcess* cp, char** data, int* length,
     /* Select's timeout expired.  */
     /* Select's timeout expired.  */
     wd->Expired = 1;
     wd->Expired = 1;
     return 1;
     return 1;
-  } else if (numReady < 0) {
+  }
+  if (numReady < 0) {
     /* Select returned an error.  Leave the error description in the
     /* Select returned an error.  Leave the error description in the
        pipe buffer.  */
        pipe buffer.  */
     strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
     strncpy(cp->ErrorMessage, strerror(errno), KWSYSPE_PIPE_BUFFER_SIZE);
@@ -1367,11 +1370,13 @@ int kwsysProcess_WaitForExit(kwsysProcess* cp, double* userTimeout)
         cp->ProcessResults[prPipe].State = kwsysProcess_StateByIndex_Exited;
         cp->ProcessResults[prPipe].State = kwsysProcess_StateByIndex_Exited;
         cp->ProcessResults[prPipe].ExitException = kwsysProcess_Exception_None;
         cp->ProcessResults[prPipe].ExitException = kwsysProcess_Exception_None;
         cp->ProcessResults[prPipe].ExitValue =
         cp->ProcessResults[prPipe].ExitValue =
+          // NOLINTNEXTLINE(google-readability-casting)
           (int)WEXITSTATUS(cp->ProcessResults[prPipe].ExitCode);
           (int)WEXITSTATUS(cp->ProcessResults[prPipe].ExitCode);
       } else if (WIFSIGNALED(cp->ProcessResults[prPipe].ExitCode)) {
       } else if (WIFSIGNALED(cp->ProcessResults[prPipe].ExitCode)) {
         /* The child received an unhandled signal.  */
         /* The child received an unhandled signal.  */
         cp->ProcessResults[prPipe].State = kwsysProcess_State_Exception;
         cp->ProcessResults[prPipe].State = kwsysProcess_State_Exception;
         kwsysProcessSetExitExceptionByIndex(
         kwsysProcessSetExitExceptionByIndex(
+          // NOLINTNEXTLINE(google-readability-casting)
           cp, (int)WTERMSIG(cp->ProcessResults[prPipe].ExitCode), prPipe);
           cp, (int)WTERMSIG(cp->ProcessResults[prPipe].ExitCode), prPipe);
       } else {
       } else {
         /* Error getting the child return code.  */
         /* Error getting the child return code.  */
@@ -1450,8 +1455,8 @@ void kwsysProcess_Kill(kwsysProcess* cp)
 
 
       /* Reap the child.  Keep trying until the call is not
       /* Reap the child.  Keep trying until the call is not
          interrupted.  */
          interrupted.  */
-      while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR))
-        ;
+      while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) && (errno == EINTR)) {
+      }
     }
     }
   }
   }
 
 
@@ -1502,7 +1507,7 @@ static int kwsysProcessInitialize(kwsysProcess* cp)
   cp->PipesLeft = 0;
   cp->PipesLeft = 0;
   cp->CommandsLeft = 0;
   cp->CommandsLeft = 0;
 #if KWSYSPE_USE_SELECT
 #if KWSYSPE_USE_SELECT
-  FD_ZERO(&cp->PipeSet);
+  FD_ZERO(&cp->PipeSet); // NOLINT(readability-isolate-declaration)
 #endif
 #endif
   cp->State = kwsysProcess_State_Starting;
   cp->State = kwsysProcess_State_Starting;
   cp->Killed = 0;
   cp->Killed = 0;
@@ -1591,16 +1596,16 @@ static void kwsysProcessCleanup(kwsysProcess* cp, int error)
           /* Reap the child.  Keep trying until the call is not
           /* Reap the child.  Keep trying until the call is not
              interrupted.  */
              interrupted.  */
           while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) &&
           while ((waitpid(cp->ForkPIDs[i], &status, 0) < 0) &&
-                 (errno == EINTR))
-            ;
+                 (errno == EINTR)) {
+          }
         }
         }
       }
       }
     }
     }
 
 
     /* Restore the working directory.  */
     /* Restore the working directory.  */
     if (cp->RealWorkingDirectory) {
     if (cp->RealWorkingDirectory) {
-      while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR))
-        ;
+      while ((chdir(cp->RealWorkingDirectory) < 0) && (errno == EINTR)) {
+      }
     }
     }
   }
   }
 
 
@@ -1636,8 +1641,8 @@ static void kwsysProcessCleanupDescriptor(int* pfd)
   if (pfd && *pfd > 2) {
   if (pfd && *pfd > 2) {
     /* Keep trying to close until it is not interrupted by a
     /* Keep trying to close until it is not interrupted by a
      * signal.  */
      * signal.  */
-    while ((close(*pfd) < 0) && (errno == EINTR))
-      ;
+    while ((close(*pfd) < 0) && (errno == EINTR)) {
+    }
     *pfd = -1;
     *pfd = -1;
   }
   }
 }
 }
@@ -1662,8 +1667,8 @@ static void kwsysProcessClosePipes(kwsysProcess* cp)
            read until the operation is not interrupted.  */
            read until the operation is not interrupted.  */
         while ((read(cp->PipeReadEnds[i], cp->PipeBuffer,
         while ((read(cp->PipeReadEnds[i], cp->PipeBuffer,
                      KWSYSPE_PIPE_BUFFER_SIZE) < 0) &&
                      KWSYSPE_PIPE_BUFFER_SIZE) < 0) &&
-               (errno == EINTR))
-          ;
+               (errno == EINTR)) {
+        }
       }
       }
 #endif
 #endif
 
 
@@ -1690,7 +1695,8 @@ int decc$set_child_standard_streams(int fd1, int fd2, int fd3);
 static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
 static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
                               kwsysProcessCreateInformation* si)
                               kwsysProcessCreateInformation* si)
 {
 {
-  sigset_t mask, old_mask;
+  sigset_t mask;
+  sigset_t old_mask;
   int pgidPipe[2];
   int pgidPipe[2];
   char tmp;
   char tmp;
   ssize_t readRes;
   ssize_t readRes;
@@ -1818,8 +1824,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
   /* Make sure the child is in the process group before we proceed.  This
   /* Make sure the child is in the process group before we proceed.  This
      avoids race conditions with calls to the kill function that we make for
      avoids race conditions with calls to the kill function that we make for
      signalling process groups.  */
      signalling process groups.  */
-  while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0)
-    ;
+  while ((readRes = read(pgidPipe[0], &tmp, 1)) > 0) {
+  }
   if (readRes < 0) {
   if (readRes < 0) {
     sigprocmask(SIG_SETMASK, &old_mask, 0);
     sigprocmask(SIG_SETMASK, &old_mask, 0);
     kwsysProcessCleanupDescriptor(&si->ErrorPipe[0]);
     kwsysProcessCleanupDescriptor(&si->ErrorPipe[0]);
@@ -1847,8 +1853,8 @@ static int kwsysProcessCreate(kwsysProcess* cp, int prIndex,
       /* Keep trying to read until the operation is not interrupted.  */
       /* Keep trying to read until the operation is not interrupted.  */
       while (((n = read(si->ErrorPipe[0], cp->ErrorMessage + total,
       while (((n = read(si->ErrorPipe[0], cp->ErrorMessage + total,
                         (size_t)(KWSYSPE_PIPE_BUFFER_SIZE - total))) < 0) &&
                         (size_t)(KWSYSPE_PIPE_BUFFER_SIZE - total))) < 0) &&
-             (errno == EINTR))
-        ;
+             (errno == EINTR)) {
+      }
       if (n > 0) {
       if (n > 0) {
         total += n;
         total += n;
       }
       }
@@ -2000,28 +2006,26 @@ static int kwsysProcessGetTimeoutLeft(kwsysProcessTime* timeoutTime,
   if (timeoutTime->tv_sec < 0) {
   if (timeoutTime->tv_sec < 0) {
     /* No timeout time has been requested.  */
     /* No timeout time has been requested.  */
     return 0;
     return 0;
-  } else {
-    /* Calculate the remaining time.  */
-    kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
-    kwsysProcessTime timeLeft =
-      kwsysProcessTimeSubtract(*timeoutTime, currentTime);
-    if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) {
-      /* Caller has explicitly requested a zero timeout.  */
-      timeLeft.tv_sec = 0;
-      timeLeft.tv_usec = 0;
-    }
+  }
+  /* Calculate the remaining time.  */
+  kwsysProcessTime currentTime = kwsysProcessTimeGetCurrent();
+  kwsysProcessTime timeLeft =
+    kwsysProcessTimeSubtract(*timeoutTime, currentTime);
+  if (timeLeft.tv_sec < 0 && userTimeout && *userTimeout <= 0) {
+    /* Caller has explicitly requested a zero timeout.  */
+    timeLeft.tv_sec = 0;
+    timeLeft.tv_usec = 0;
+  }
 
 
-    if (timeLeft.tv_sec < 0 ||
-        (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) {
-      /* Timeout has already expired.  */
-      return 1;
-    } else {
-      /* There is some time left.  */
-      timeoutLength->tv_sec = timeLeft.tv_sec;
-      timeoutLength->tv_usec = timeLeft.tv_usec;
-      return 0;
-    }
+  if (timeLeft.tv_sec < 0 ||
+      (timeLeft.tv_sec == 0 && timeLeft.tv_usec == 0 && zeroIsExpired)) {
+    /* Timeout has already expired.  */
+    return 1;
   }
   }
+  /* There is some time left.  */
+  timeoutLength->tv_sec = timeLeft.tv_sec;
+  timeoutLength->tv_usec = timeLeft.tv_usec;
+  return 0;
 }
 }
 
 
 static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
 static kwsysProcessTime kwsysProcessTimeGetCurrent(void)
@@ -2426,41 +2430,39 @@ static pid_t kwsysProcessFork(kwsysProcess* cp,
     if (middle_pid < 0) {
     if (middle_pid < 0) {
       /* Fork failed.  Return as if we were not detaching.  */
       /* Fork failed.  Return as if we were not detaching.  */
       return middle_pid;
       return middle_pid;
-    } else if (middle_pid == 0) {
+    }
+    if (middle_pid == 0) {
       /* This is the intermediate process.  Create the real child.  */
       /* This is the intermediate process.  Create the real child.  */
       pid_t child_pid = fork();
       pid_t child_pid = fork();
       if (child_pid == 0) {
       if (child_pid == 0) {
         /* This is the real child process.  There is nothing to do here.  */
         /* This is the real child process.  There is nothing to do here.  */
         return 0;
         return 0;
-      } else {
-        /* Use the error pipe to report the pid to the real parent.  */
-        while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) &&
-               (errno == EINTR))
-          ;
-
-        /* Exit without cleanup.  The parent holds all resources.  */
-        kwsysProcessExit();
-        return 0; /* Never reached, but avoids SunCC warning.  */
       }
       }
-    } else {
-      /* This is the original parent process.  The intermediate
-         process will use the error pipe to report the pid of the
-         detached child.  */
-      pid_t child_pid;
-      int status;
-      while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) &&
-             (errno == EINTR))
-        ;
+      /* Use the error pipe to report the pid to the real parent.  */
+      while ((write(si->ErrorPipe[1], &child_pid, sizeof(child_pid)) < 0) &&
+             (errno == EINTR)) {
+      }
 
 
-      /* Wait for the intermediate process to exit and clean it up.  */
-      while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR))
-        ;
-      return child_pid;
+      /* Exit without cleanup.  The parent holds all resources.  */
+      kwsysProcessExit();
+      return 0; /* Never reached, but avoids SunCC warning.  */
     }
     }
-  } else {
-    /* Not creating a detached process.  Use normal fork.  */
-    return fork();
+    /* This is the original parent process.  The intermediate
+        process will use the error pipe to report the pid of the
+        detached child.  */
+    pid_t child_pid;
+    int status;
+    while ((read(si->ErrorPipe[0], &child_pid, sizeof(child_pid)) < 0) &&
+           (errno == EINTR)) {
+    }
+
+    /* Wait for the intermediate process to exit and clean it up.  */
+    while ((waitpid(middle_pid, &status, 0) < 0) && (errno == EINTR)) {
+    }
+    return child_pid;
   }
   }
+  /* Not creating a detached process.  Use normal fork.  */
+  return fork();
 }
 }
 #endif
 #endif
 
 
@@ -2727,8 +2729,8 @@ static int kwsysProcessesAdd(kwsysProcess* cp)
       sigemptyset(&newSigAction.sa_mask);
       sigemptyset(&newSigAction.sa_mask);
       while ((sigaction(SIGCHLD, &newSigAction,
       while ((sigaction(SIGCHLD, &newSigAction,
                         &kwsysProcessesOldSigChldAction) < 0) &&
                         &kwsysProcessesOldSigChldAction) < 0) &&
-             (errno == EINTR))
-        ;
+             (errno == EINTR)) {
+      }
 
 
       /* Install our handler for SIGINT / SIGTERM.  Repeat call until
       /* Install our handler for SIGINT / SIGTERM.  Repeat call until
          it is not interrupted.  */
          it is not interrupted.  */
@@ -2736,15 +2738,15 @@ static int kwsysProcessesAdd(kwsysProcess* cp)
       sigaddset(&newSigAction.sa_mask, SIGTERM);
       sigaddset(&newSigAction.sa_mask, SIGTERM);
       while ((sigaction(SIGINT, &newSigAction,
       while ((sigaction(SIGINT, &newSigAction,
                         &kwsysProcessesOldSigIntAction) < 0) &&
                         &kwsysProcessesOldSigIntAction) < 0) &&
-             (errno == EINTR))
-        ;
+             (errno == EINTR)) {
+      }
 
 
       sigemptyset(&newSigAction.sa_mask);
       sigemptyset(&newSigAction.sa_mask);
       sigaddset(&newSigAction.sa_mask, SIGINT);
       sigaddset(&newSigAction.sa_mask, SIGINT);
       while ((sigaction(SIGTERM, &newSigAction,
       while ((sigaction(SIGTERM, &newSigAction,
                         &kwsysProcessesOldSigIntAction) < 0) &&
                         &kwsysProcessesOldSigIntAction) < 0) &&
-             (errno == EINTR))
-        ;
+             (errno == EINTR)) {
+      }
     }
     }
   }
   }
 
 
@@ -2775,14 +2777,14 @@ static void kwsysProcessesRemove(kwsysProcess* cp)
         /* Restore the signal handlers.  Repeat call until it is not
         /* Restore the signal handlers.  Repeat call until it is not
            interrupted.  */
            interrupted.  */
         while ((sigaction(SIGCHLD, &kwsysProcessesOldSigChldAction, 0) < 0) &&
         while ((sigaction(SIGCHLD, &kwsysProcessesOldSigChldAction, 0) < 0) &&
-               (errno == EINTR))
-          ;
+               (errno == EINTR)) {
+        }
         while ((sigaction(SIGINT, &kwsysProcessesOldSigIntAction, 0) < 0) &&
         while ((sigaction(SIGINT, &kwsysProcessesOldSigIntAction, 0) < 0) &&
-               (errno == EINTR))
-          ;
+               (errno == EINTR)) {
+        }
         while ((sigaction(SIGTERM, &kwsysProcessesOldSigTermAction, 0) < 0) &&
         while ((sigaction(SIGTERM, &kwsysProcessesOldSigTermAction, 0) < 0) &&
-               (errno == EINTR))
-          ;
+               (errno == EINTR)) {
+        }
 
 
         /* Free the table of process pointers since it is now empty.
         /* Free the table of process pointers since it is now empty.
            This is safe because the signal handler has been removed.  */
            This is safe because the signal handler has been removed.  */
@@ -2808,7 +2810,10 @@ static void kwsysProcessesSignalHandler(int signum
 #endif
 #endif
 )
 )
 {
 {
-  int i, j, procStatus, old_errno = errno;
+  int i;
+  int j;
+  int procStatus;
+  int old_errno = errno;
 #if KWSYSPE_USE_SIGINFO
 #if KWSYSPE_USE_SIGINFO
   (void)info;
   (void)info;
   (void)ucontext;
   (void)ucontext;
@@ -2865,8 +2870,8 @@ static void kwsysProcessesSignalHandler(int signum
         memset(&defSigAction, 0, sizeof(defSigAction));
         memset(&defSigAction, 0, sizeof(defSigAction));
         defSigAction.sa_handler = SIG_DFL;
         defSigAction.sa_handler = SIG_DFL;
         sigemptyset(&defSigAction.sa_mask);
         sigemptyset(&defSigAction.sa_mask);
-        while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR))
-          ;
+        while ((sigaction(signum, &defSigAction, 0) < 0) && (errno == EINTR)) {
+        }
         /* Unmask the signal.  */
         /* Unmask the signal.  */
         sigemptyset(&unblockSet);
         sigemptyset(&unblockSet);
         sigaddset(&unblockSet, signum);
         sigaddset(&unblockSet, signum);

+ 1 - 1
Source/kwsys/SystemTools.cxx

@@ -1904,7 +1904,7 @@ std::vector<std::string> SystemTools::SplitString(const std::string& p,
     paths.emplace_back("/");
     paths.emplace_back("/");
   }
   }
   std::string::size_type pos1 = 0;
   std::string::size_type pos1 = 0;
-  std::string::size_type pos2 = path.find(sep, pos1 + 1);
+  std::string::size_type pos2 = path.find(sep, pos1);
   while (pos2 != std::string::npos) {
   while (pos2 != std::string::npos) {
     paths.push_back(path.substr(pos1, pos2 - pos1));
     paths.push_back(path.substr(pos1, pos2 - pos1));
     pos1 = pos2 + 1;
     pos1 = pos2 + 1;

+ 2 - 1
Source/kwsys/testProcess.c

@@ -631,7 +631,8 @@ int main(int argc, const char* argv[])
     }
     }
     fprintf(stderr, "Invalid test number %d.\n", n);
     fprintf(stderr, "Invalid test number %d.\n", n);
     return 1;
     return 1;
-  } else if (n >= 1 && n <= 10) {
+  }
+  if (n >= 1 && n <= 10) {
     /* This is the parent process for a requested test number.  */
     /* This is the parent process for a requested test number.  */
     int states[10] = {
     int states[10] = {
       kwsysProcess_State_Exited,   kwsysProcess_State_Exited,
       kwsysProcess_State_Exited,   kwsysProcess_State_Exited,

+ 38 - 0
Source/kwsys/testSystemTools.cxx

@@ -1120,6 +1120,42 @@ static bool CheckURLParsing()
   return ret;
   return ret;
 }
 }
 
 
+static bool CheckSplitString()
+{
+  bool ret = true;
+
+  auto check_split = [](std::string const& input,
+                        std::initializer_list<const char*> expected) -> bool {
+    auto const components = kwsys::SystemTools::SplitString(input, '/');
+    if (components.size() != expected.size()) {
+      std::cerr << "Incorrect split count for " << input << ": "
+                << components.size() << std::endl;
+      return false;
+    }
+    size_t i = 0;
+    for (auto& part : expected) {
+      if (components[i] != part) {
+        std::cerr << "Incorrect split component " << i << " for " << input
+                  << ": " << components[i] << std::endl;
+        return false;
+      }
+      ++i;
+    }
+    return true;
+  };
+
+  // No separators
+  ret &= check_split("nosep", { "nosep" });
+  // Simple
+  ret &= check_split("first/second", { "first", "second" });
+  // Separator at beginning
+  ret &= check_split("/starts/sep", { "", "starts", "sep" });
+  // Separator at end
+  ret &= check_split("ends/sep/", { "ends", "sep", "" });
+
+  return ret;
+}
+
 int testSystemTools(int, char* [])
 int testSystemTools(int, char* [])
 {
 {
   bool res = true;
   bool res = true;
@@ -1169,5 +1205,7 @@ int testSystemTools(int, char* [])
 
 
   res &= CheckURLParsing();
   res &= CheckURLParsing();
 
 
+  res &= CheckSplitString();
+
   return res ? 0 : 1;
   return res ? 0 : 1;
 }
 }