]> Savannah Git Hosting - gnulib.git/commitdiff
nproc, openmp-init: omit unnecessary strtol code
authorPaul Eggert <eggert@cs.ucla.edu>
Wed, 19 Mar 2025 20:23:46 +0000 (13:23 -0700)
committerPaul Eggert <eggert@cs.ucla.edu>
Wed, 19 Mar 2025 20:24:10 +0000 (13:24 -0700)
* lib/nproc.c (parse_omp_threads):
* lib/omp-init.c (parse_omp_threads):
Remove unnecessary initialization and unnecessary check
whether endptr == NULL.
Reported by Alejandro Colomar in:
https://lore.kernel.org/liba2i/jx4664ishtl34eg2npdrv5fkfdiczqnlq3vjuacjrupjvh377x@gddcftzgwmfq/

ChangeLog
lib/nproc.c
lib/omp-init.c

index dae23affdb35ed91268a1a20ae680902676f695a..8a788702e687c70ffcfdd457b7ff605fb9f71652 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+2025-03-19  Paul Eggert  <eggert@cs.ucla.edu>
+
+       nproc, openmp-init: omit unnecessary strtol code
+       * lib/nproc.c (parse_omp_threads):
+       * lib/omp-init.c (parse_omp_threads):
+       Remove unnecessary initialization and unnecessary check
+       whether endptr == NULL.
+       Reported by Alejandro Colomar in:
+       https://lore.kernel.org/liba2i/jx4664ishtl34eg2npdrv5fkfdiczqnlq3vjuacjrupjvh377x@gddcftzgwmfq/
+
 2025-03-19  Bruno Haible  <bruno@clisp.org>
 
        getlogin, getlogin_r: Fix typo in documentation.
index d48e4dd94f545ef0bc62782d01df6617429115da..051426a6f00372b30db4da7f3750ad7a29b05605 100644 (file)
@@ -398,20 +398,16 @@ parse_omp_threads (char const* threads)
   /* Convert it from positive decimal to 'unsigned long'.  */
   if (c_isdigit (*threads))
     {
-      char *endptr = NULL;
+      char *endptr;
       unsigned long int value = strtoul (threads, &endptr, 10);
-
-      if (endptr != NULL)
-        {
-          while (*endptr != '\0' && c_isspace (*endptr))
-            endptr++;
-          if (*endptr == '\0')
-            return value;
-          /* Also accept the first value in a nesting level,
-             since we can't determine the nesting level from env vars.  */
-          else if (*endptr == ',')
-            return value;
-        }
+      while (*endptr != '\0' && c_isspace (*endptr))
+        endptr++;
+      if (*endptr == '\0')
+        return value;
+      /* Also accept the first value in a nesting level,
+         since we can't determine the nesting level from env vars.  */
+      else if (*endptr == ',')
+        return value;
     }
 
   return ret;
index 53d0747e26131edeba96e45973769b639bb1ab6e..b72bec9f238c5adb70b8eb3459e9fa04b3a62541 100644 (file)
@@ -44,20 +44,16 @@ parse_omp_threads (char const* threads)
   /* Convert it from positive decimal to 'unsigned long'.  */
   if (c_isdigit (*threads))
     {
-      char *endptr = NULL;
+      char *endptr;
       unsigned long int value = strtoul (threads, &endptr, 10);
-
-      if (endptr != NULL)
-        {
-          while (*endptr != '\0' && c_isspace (*endptr))
-            endptr++;
-          if (*endptr == '\0')
-            return value;
-          /* Also accept the first value in a nesting level,
-             since we can't determine the nesting level from env vars.  */
-          else if (*endptr == ',')
-            return value;
-        }
+      while (*endptr != '\0' && c_isspace (*endptr))
+        endptr++;
+      if (*endptr == '\0')
+        return value;
+      /* Also accept the first value in a nesting level,
+         since we can't determine the nesting level from env vars.  */
+      else if (*endptr == ',')
+        return value;
     }
 
   return ret;