]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Maintenance: code style updates in libcompat (#880)
authorAmos Jeffries <yadij@users.noreply.github.com>
Wed, 23 Feb 2022 18:42:41 +0000 (18:42 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Wed, 23 Feb 2022 21:09:33 +0000 (21:09 +0000)
The libcompat code is targeted here specifically because it is
rarely touched so is not likely to be soon updated by our
"upgrade when modified" policy for source style changes.

Doing this part of the code semi-manually also allows us
to trivially exclude the directory from automated conversion
attempts and not bother with automating the detection of
whether a .h is included in C files.

17 files changed:
compat/cmsg.h
compat/compat.cc
compat/getaddrinfo.cc
compat/getnameinfo.cc
compat/inet_ntop.cc
compat/inet_pton.cc
compat/mswindows.cc
compat/shm.cc
compat/statvfs.cc
compat/strnstr.cc
compat/xalloc.cc
compat/xalloc.h
compat/xstrerror.h
compat/xstring.cc
compat/xstring.h
compat/xstrto.cc
compat/xstrto.h

index ee6c167edb1f1b8d02764d91351b5999ac91b826..a61a1e948b007f43f952a6e67321243022c7b84f 100644 (file)
@@ -58,7 +58,7 @@ struct cmsghdr {
 #ifndef CMSG_FIRSTHDR
 # define CMSG_FIRSTHDR(mhdr) \
   ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr)        \
-   ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) NULL)
+   ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) nullptr)
 #endif
 
 #ifndef CMSG_ALIGN
index d3d5e845fc6941abe95cdf4fb960c2755cf33b47..17afe7af27df683602bee71ad8d6ec36fc6349b5 100644 (file)
@@ -9,5 +9,5 @@
 #include "squid.h"
 #include "compat.h"
 
-void (*failure_notify) (const char *) = NULL;
+void (*failure_notify) (const char *) = nullptr;
 
index eaa8998ae4d4f117e7b9f91701dfcafc1aac92b3..b74434188e8c32a4b29fc71f6e04174b75c35fcf 100644 (file)
@@ -84,13 +84,13 @@ dup_addrinfo (struct addrinfo *info, void *addr, size_t addrlen) {
     struct addrinfo *ret;
 
     ret = (struct addrinfo *)malloc(sizeof (struct addrinfo));
-    if (ret == NULL)
-        return NULL;
+    if (!ret)
+        return nullptr;
     memcpy (ret, info, sizeof (struct addrinfo));
     ret->ai_addr = (struct sockaddr*)malloc(addrlen);
-    if (ret->ai_addr == NULL) {
+    if (!ret->ai_addr) {
         free (ret);
-        return NULL;
+        return nullptr;
     }
     memcpy (ret->ai_addr, addr, addrlen);
     ret->ai_addrlen = addrlen;
@@ -109,19 +109,19 @@ xgetaddrinfo (const char *nodename, const char *servname,
     struct addrinfo *ai, *sai, *eai;
     char **addrs;
 
-    if (servname == NULL && nodename == NULL)
+    if (!servname && !nodename)
         return EAI_NONAME;
 
     memset (&result, 0, sizeof result);
 
     /* default for hints */
-    if (hints == NULL) {
+    if (!hints) {
         memset (&hint, 0, sizeof hint);
         hint.ai_family = PF_UNSPEC;
         hints = &hint;
     }
 
-    if (servname == NULL)
+    if (!servname)
         port = 0;
     else {
         /* check for tcp or udp sockets only */
@@ -135,16 +135,16 @@ xgetaddrinfo (const char *nodename, const char *servname,
 
         /* Note: maintain port in host byte order to make debugging easier */
         if (isdigit (*servname))
-            port = strtol (servname, NULL, 10);
-        else if ((servent = getservbyname (servname, socktype)) != NULL)
+            port = strtol (servname, nullptr, 10);
+        else if ((servent = getservbyname (servname, socktype)))
             port = ntohs (servent->s_port);
         else
             return EAI_NONAME;
     }
 
-    /* if nodename == NULL refer to the local host for a client or any
+    /* if !nodename, refer to the local host for a client or any
        for a server */
-    if (nodename == NULL) {
+    if (!nodename) {
         struct sockaddr_in sin;
 
         /* check protocol family is PF_UNSPEC or PF_INET - could try harder
@@ -162,7 +162,7 @@ xgetaddrinfo (const char *nodename, const char *servname,
             sin.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
         /* Duplicate result and addr and return */
         *res = dup_addrinfo (&result, &sin, sizeof sin);
-        return (*res == NULL) ? EAI_MEMORY : 0;
+        return (!*res) ? EAI_MEMORY : 0;
     }
 
     /* If AI_NUMERIC is specified, use inet_pton to translate numbers and
@@ -183,7 +183,7 @@ xgetaddrinfo (const char *nodename, const char *servname,
         sin.sin_addr.s_addr = inet_addr (nodename);
         /* Duplicate result and addr and return */
         *res = dup_addrinfo (&result, &sin, sizeof sin);
-        return (*res == NULL) ? EAI_MEMORY : 0;
+        return (!*res) ? EAI_MEMORY : 0;
     }
 
 #if HAVE_H_ERRNO
@@ -191,7 +191,7 @@ xgetaddrinfo (const char *nodename, const char *servname,
 #endif
     errno = 0;
     hp = gethostbyname(nodename);
-    if (hp == NULL) {
+    if (!hp) {
 #ifdef EAI_SYSTEM
         if (errno != 0) {
             return EAI_SYSTEM;
@@ -233,8 +233,8 @@ xgetaddrinfo (const char *nodename, const char *servname,
 
     /* For each element pointed to by hp, create an element in the
        result linked list. */
-    sai = eai = NULL;
-    for (addrs = hp->h_addr_list; *addrs != NULL; addrs++) {
+    sai = eai = nullptr;
+    for (addrs = hp->h_addr_list; *addrs; addrs++) {
         struct sockaddr sa;
         size_t addrlen;
 
@@ -263,24 +263,24 @@ xgetaddrinfo (const char *nodename, const char *servname,
 
         result.ai_family = hp->h_addrtype;
         ai = dup_addrinfo (&result, &sa, addrlen);
-        if (ai == NULL) {
+        if (!ai) {
             xfreeaddrinfo (sai);
             return EAI_MEMORY;
         }
-        if (sai == NULL)
+        if (!sai)
             sai = ai;
         else
             eai->ai_next = ai;
         eai = ai;
     }
 
-    if (sai == NULL) {
+    if (!sai) {
         return EAI_NODATA;
     }
 
     if (hints->ai_flags & AI_CANONNAME) {
         sai->ai_canonname = (char *)malloc(strlen(hp->h_name) + 1);
-        if (sai->ai_canonname == NULL) {
+        if (!sai->ai_canonname) {
             xfreeaddrinfo (sai);
             return EAI_MEMORY;
         }
@@ -296,11 +296,11 @@ xfreeaddrinfo (struct addrinfo *ai)
 {
     struct addrinfo *next;
 
-    while (ai != NULL) {
+    while (ai) {
         next = ai->ai_next;
-        if (ai->ai_canonname != NULL)
+        if (ai->ai_canonname)
             free (ai->ai_canonname);
-        if (ai->ai_addr != NULL)
+        if (ai->ai_addr)
             free (ai->ai_addr);
         free (ai);
         ai = next;
index a3c8f5ff57c042b557e8b0ad5638180067567217..e7c97cb63419fc069ba5da80e5e702f8fa01d64d 100644 (file)
@@ -162,7 +162,7 @@ xgetnameinfo(const struct sockaddr *sa, socklen_t salen, char *host, size_t host
     uint32_t v4a;
     char numserv[512];
 
-    if (sa == NULL)
+    if (!sa)
         return EAI_FAIL;
 
 #if HAVE_SA_LEN /*XXX*/
@@ -186,16 +186,16 @@ found:
     memcpy(&port, (const char *)sa + afd->a_portoff, sizeof(port));
     addr = (const char *)sa + afd->a_off;
 
-    if (serv == NULL || servlen == 0) {
+    if (!serv || servlen == 0) {
         /*
          * do nothing in this case.
          * in case you are wondering if "&&" is more correct than
-         * "||" here: RFC3493 says that serv == NULL OR servlen == 0
+         * "||" here: RFC3493 says that !serv OR servlen == 0
          * means that the caller does not want the result.
          */
     } else {
         if (flags & NI_NUMERICSERV)
-            sp = NULL;
+            sp = nullptr;
         else {
             sp = getservbyport(port,
                                (flags & NI_DGRAM) ? "udp" : "tcp");
@@ -246,11 +246,11 @@ found:
     break;
 #endif
     }
-    if (host == NULL || hostlen == 0) {
+    if (!host || hostlen == 0) {
         /*
          * do nothing in this case.
          * in case you are wondering if "&&" is more correct than
-         * "||" here: RFC3493 says that host == NULL or hostlen == 0
+         * "||" here: RFC3493 says that !host or hostlen == 0
          * means that the caller does not want the result.
          */
     } else if (flags & NI_NUMERICHOST) {
@@ -296,8 +296,7 @@ numeric:
             }
 #endif
             default:
-                if (inet_ntop(afd->a_af, addr, host,
-                              hostlen) == NULL)
+                if (!inet_ntop(afd->a_af, addr, host, hostlen))
                     return EAI_SYSTEM;
                 break;
             }
@@ -318,7 +317,7 @@ int flags;
     int numaddrlen;
     char numaddr[512];
 
-    if (inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)) == NULL)
+    if (!inet_ntop(AF_INET6, addr, numaddr, sizeof(numaddr)))
         return EAI_SYSTEM;
 
     numaddrlen = strlen(numaddr);
index 5ff864c86b3eda416dcdc67dee49ddd4cddafb12..183a2ffae88b35fd9f77eed4851f549bd3229cb8 100644 (file)
@@ -103,7 +103,7 @@ static const char *inet_ntop6 (const u_char *src, char *dst, size_t size);
  * inet_ntop(af, src, dst, size)
  *  convert a network format address to presentation format.
  * return:
- *  pointer to presentation format address (`dst'), or NULL (see errno).
+ *  pointer to presentation format address (`dst'), or nullptr (see errno).
  * author:
  *  Paul Vixie, 1996.
  */
@@ -117,7 +117,7 @@ xinet_ntop(int af, const void *src, char *dst, size_t size)
         return (inet_ntop6((const u_char*)src, dst, size));
     default:
         errno = EAFNOSUPPORT;
-        return (NULL);
+        return nullptr;
     }
     /* NOTREACHED */
 }
@@ -141,7 +141,7 @@ inet_ntop4(const u_char *src, char *dst, size_t size)
 
     if ((size_t)snprintf(tmp, min(sizeof(tmp),size), fmt, src[0], src[1], src[2], src[3]) >= size) {
         errno = ENOSPC;
-        return (NULL);
+        return nullptr;
     }
     strcpy(dst, tmp);
     return (dst);
@@ -221,7 +221,7 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
                                          (best.len == 7 && words[7] != 0x0001) ||
                                          (best.len == 5 && words[5] == 0xffff))) {
             if (!inet_ntop4(src+12, tp, sizeof tmp - (tp - tmp)))
-                return (NULL);
+                return nullptr;
             tp += strlen(tp);
             break;
         }
@@ -238,7 +238,7 @@ inet_ntop6(const u_char *src, char *dst, size_t size)
      */
     if ((size_t)(tp - tmp) > size) {
         errno = ENOSPC;
-        return (NULL);
+        return nullptr;
     }
     strcpy(dst, tmp);
     return (dst);
index 2ec56d7173ee09c51f0cb849e62853afd63c257f..e95ee8e7b73c214890ac59449b44c0ebce98cd33 100644 (file)
@@ -143,7 +143,7 @@ inet_pton4(const char *src, u_char *dst)
     while ((ch = *src++) != '\0') {
         const char *pch;
 
-        if ((pch = strchr(digits, ch)) != NULL) {
+        if ((pch = strchr(digits, ch))) {
             u_int nw = *tp * 10 + (pch - digits);
 
             if (saw_digit && *tp == 0)
@@ -195,7 +195,7 @@ inet_pton6(const char *src, u_char *dst)
 
     memset((tp = tmp), '\0', NS_IN6ADDRSZ);
     endp = tp + NS_IN6ADDRSZ;
-    colonp = NULL;
+    colonp = nullptr;
     /* Leading :: requires some special handling. */
     if (*src == ':')
         if (*++src != ':')
@@ -206,9 +206,9 @@ inet_pton6(const char *src, u_char *dst)
     while ((ch = *src++) != '\0') {
         const char *pch;
 
-        if ((pch = strchr((xdigits = xdigits_l), ch)) == NULL)
+        if (!(pch = strchr((xdigits = xdigits_l), ch)))
             pch = strchr((xdigits = xdigits_u), ch);
-        if (pch != NULL) {
+        if (pch) {
             val <<= 4;
             val |= (pch - xdigits);
             if (++seen_xdigits > 4)
@@ -247,7 +247,7 @@ inet_pton6(const char *src, u_char *dst)
         *tp++ = (u_char) (val >> 8) & 0xff;
         *tp++ = (u_char) val & 0xff;
     }
-    if (colonp != NULL) {
+    if (colonp) {
         /*
          * Since some memmove()'s erroneously fail to handle
          * overlapping regions, we'll do the shift by hand.
index fa0ec3fcd646fcc064a76892f21dd8183ba64b35..987f4199c385a0d30a1d920493796efde55092da 100644 (file)
@@ -31,7 +31,7 @@
 #endif
 
 THREADLOCAL int ws32_result;
-LPCRITICAL_SECTION dbg_mutex = NULL;
+LPCRITICAL_SECTION dbg_mutex = nullptr;
 
 void GetProcessName(pid_t, char *);
 
@@ -66,7 +66,7 @@ GetProcessName(pid_t pid, char *ProcessName)
     /* Get a handle to the process. */
     HANDLE hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid);
     /* Get the process name. */
-    if (NULL != hProcess) {
+    if (hProcess) {
         HMODULE hMod;
         DWORD cbNeeded;
 
@@ -90,9 +90,7 @@ kill(pid_t pid, int sig)
     char ProcessNameToCheck[MAX_PATH];
 
     if (sig == 0) {
-        if ((hProcess = OpenProcess(PROCESS_QUERY_INFORMATION |
-                                    PROCESS_VM_READ,
-                                    FALSE, pid)) == NULL)
+        if (!(hProcess = OpenProcess(PROCESS_QUERY_INFORMATION | PROCESS_VM_READ, FALSE, pid)))
             return -1;
         else {
             CloseHandle(hProcess);
@@ -136,9 +134,9 @@ WIN32_ftruncate(int fd, off_t size)
         return -1;
 
     hfile = (HANDLE) _get_osfhandle(fd);
-    curpos = SetFilePointer(hfile, 0, NULL, FILE_CURRENT);
+    curpos = SetFilePointer(hfile, 0, nullptr, FILE_CURRENT);
     if (curpos == 0xFFFFFFFF
-            || SetFilePointer(hfile, size, NULL, FILE_BEGIN) == 0xFFFFFFFF
+            || SetFilePointer(hfile, size, nullptr, FILE_BEGIN) == 0xFFFFFFFF
             || !SetEndOfFile(hfile)) {
         int error = GetLastError();
 
@@ -177,13 +175,13 @@ WIN32_truncate(const char *pathname, off_t length)
 
 struct passwd *
 getpwnam(char *unused) {
-    static struct passwd pwd = {NULL, NULL, 100, 100, NULL, NULL, NULL};
+    static struct passwd pwd = {nullptr, nullptr, 100, 100, nullptr, nullptr, nullptr};
     return &pwd;
 }
 
 struct group *
 getgrnam(char *unused) {
-    static struct group grp = {NULL, NULL, 100, NULL};
+    static struct group grp = {nullptr, nullptr, 100, nullptr};
     return &grp;
 }
 
@@ -196,13 +194,13 @@ _free_osfhnd(int filehandle)
             (_osfhnd(filehandle) != (long) INVALID_HANDLE_VALUE)) {
         switch (filehandle) {
         case 0:
-            SetStdHandle(STD_INPUT_HANDLE, NULL);
+            SetStdHandle(STD_INPUT_HANDLE, nullptr);
             break;
         case 1:
-            SetStdHandle(STD_OUTPUT_HANDLE, NULL);
+            SetStdHandle(STD_OUTPUT_HANDLE, nullptr);
             break;
         case 2:
-            SetStdHandle(STD_ERROR_HANDLE, NULL);
+            SetStdHandle(STD_ERROR_HANDLE, nullptr);
             break;
         }
         _osfhnd(filehandle) = (long) INVALID_HANDLE_VALUE;
@@ -301,9 +299,9 @@ openlog(const char *ident, int logopt, int facility)
     if (ms_eventlog)
         return;
 
-    ms_eventlog = RegisterEventSourceA(NULL, ident);
+    ms_eventlog = RegisterEventSourceA(nullptr, ident);
 
-    // note: RegisterEventAtSourceA may fail and return NULL.
+    // note: RegisterEventAtSourceA may fail and return nullptr.
     //   in that case we'll just retry at the next message or not log
 }
 #define SYSLOG_MAX_MSG_SIZE 1024
@@ -349,8 +347,8 @@ syslog(int priority, const char *fmt, ...)
     }
 
     //Windows API suck. They are overengineered
-    ReportEventA(ms_eventlog, logtype, 0, 0, NULL, 1, 0,
-                 const_cast<const char **>(&str), NULL);
+    ReportEventA(ms_eventlog, logtype, 0, 0, nullptr, 1, 0,
+                 const_cast<const char **>(&str), nullptr);
 }
 
 /* note: this is all MSWindows-specific code; all of it should be conditional */
index 186939967d2a0aa3adf3d909b44cec7f42f5c201..976a1a89d259f67924f594c1448796b358b5b600 100644 (file)
@@ -27,7 +27,7 @@ shm_portable_segment_name_is_path()
 #elif _SQUID_FREEBSD_
     int jailed = 0;
     size_t len = sizeof(jailed);
-    ::sysctlbyname("security.jail.jailed", &jailed, &len, NULL, 0);
+    ::sysctlbyname("security.jail.jailed", &jailed, &len, nullptr, 0);
     return !jailed;
 #else
     return false;
index 5cad7691741c4df5bbd144c24fab2060479e48b6..bff7ea2b1690dd1180719c78c12d27c0eeb3f289 100644 (file)
@@ -38,7 +38,7 @@ xstatvfs(const char *path, struct statvfs *sfs)
         errno = ENOENT;
         return -1;
     }
-    if (!GetVolumeInformation(drive, NULL, 0, &vsn, &maxlen, &flags, NULL, 0)) {
+    if (!GetVolumeInformation(drive, nullptr, 0, &vsn, &maxlen, &flags, nullptr, 0)) {
         errno = ENOENT;
         return -1;
     }
index fee92c0448dca925d45d8f2b6d4b1dfab773d3c5..295722a7f9884e9b34af9c31ffbd3b7e86a354c6 100644 (file)
@@ -84,12 +84,12 @@ squid_strnstr(const char *s, const char *find, size_t slen)
         do {
             do {
                 if (slen < 1 || (sc = *s) == '\0')
-                    return (NULL);
+                    return nullptr;
                 --slen;
                 ++s;
             } while (sc != c);
             if (len > slen)
-                return (NULL);
+                return nullptr;
         } while (strncmp(s, find, len) != 0);
         --s;
     }
index b2f087cd613893d1cb24ed6d5685ea17aa0fd50b..d48608443a84a88e3fbd66585dc17520c58a2ef7 100644 (file)
@@ -78,7 +78,7 @@ xcalloc(size_t n, size_t sz)
 
     void *p = calloc(n, sz);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
             snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
@@ -104,7 +104,7 @@ xmalloc(size_t sz)
 
     void *p = malloc(sz);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
             snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
@@ -130,7 +130,7 @@ xrealloc(void *s, size_t sz)
 
     void *p= realloc(s, sz);
 
-    if (p == NULL) {
+    if (!p) {
         if (failure_notify) {
             static char msg[128];
             snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
index acd3f5293a447ec4318626f199610f0f63f45851..4d03a4bc1564ffeacd53bbd9c65bdd81bcd1416b 100644 (file)
@@ -15,7 +15,7 @@ extern "C" {
 
 /**
  * xcalloc() - same as calloc(3).  Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
  *
  * Define failure_notify to receive error message.
  * otherwise perror() is used to display it.
@@ -24,7 +24,7 @@ void *xcalloc(size_t n, size_t sz);
 
 /**
  * xmalloc() - same as malloc(3).  Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
  *
  * Define failure_notify to receive error message.
  * otherwise perror() is used to display it.
@@ -33,7 +33,7 @@ void *xmalloc(size_t sz);
 
 /**
  * xrealloc() - same as realloc(3). Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
  */
 void *xrealloc(void *s, size_t sz);
 
@@ -49,10 +49,10 @@ void free_const(const void *s);
 /**
  *  xfree() - same as free(3).  Used for portability.
  * Accepts pointers to dynamically allocated const data.
- * Will not call free(3) if the pointer is NULL.
+ * Will not call free(3) if the pointer is nullptr.
  *
  * Pointer is left with a value on completion.
- * Use safe_free() if the pointer needs to be set to NULL afterward.
+ * Use safe_free() if the pointer needs to be set to nullptr afterward.
  *
  * Define failure_notify to receive error message.
  * otherwise perror() is used to display it.
@@ -62,15 +62,15 @@ static inline void xfree(const void *p) { if (p) free_const(p); }
 /**
  *  safe_free() - same as free(3).  Used for portability.
  * Accepts pointers to dynamically allocated const data.
- * Will not call free(3) if the pointer is NULL.
- * Sets the pointer to NULL on completion.
+ * Will not call free(3) if the pointer is nullptr.
+ * Sets the pointer to nullptr on completion.
  *
  * Use xfree() if the pointer does not need to be set afterward.
  *
  * Define failure_notify to receive error message.
  * otherwise perror() is used to display it.
  */
-#define safe_free(x)    while ((x)) { free_const((x)); (x) = NULL; }
+#define safe_free(x)    while ((x)) { free_const((x)); (x) = nullptr; }
 
 #ifdef __cplusplus
 }
index 8eedefa7cf15ff69ada05a3f1888250f0eabfd48..d73e45890d75b0aac279b7d60bc3a131b63decf3 100644 (file)
@@ -15,7 +15,7 @@
 
 /** Provide the textual display of a system error number.
  * A string is always returned.
- * Where strerror() would have provided NULL this will report the error as unknown.
+ * Where strerror() would have provided nullptr this will report the error as unknown.
  * On MS Windows the native Win32 errors are also translated.
  */
 extern const char * xstrerr(int error);
index 75295573da29c51de8e21f9c0220c04c2e15b730..27945527ad06bbc7de6220abce14edc8e99f71ff 100644 (file)
@@ -17,10 +17,10 @@ xstrdup(const char *s)
 {
     if (!s) {
         if (failure_notify) {
-            (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n");
+            (*failure_notify) ("xstrdup: tried to dup a nullptr!\n");
         } else {
             errno = EINVAL;
-            perror("xstrdup: tried to dup a NULL pointer!");
+            perror("xstrdup: tried to dup a nullptr!");
         }
         exit(1);
     }
@@ -58,9 +58,9 @@ xstrndup(const char *s, size_t n)
     if (!s) {
         errno = EINVAL;
         if (failure_notify) {
-            (*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n");
+            (*failure_notify) ("xstrndup: tried to dup a nullptr!\n");
         } else {
-            perror("xstrndup: tried to dup a NULL pointer!");
+            perror("xstrndup: tried to dup a nullptr!");
         }
         exit(1);
     }
index decdd829e971e2e3e46e3c45309ad6ffebe6bc59..131a353c9b0d70e6bc54a4694edf820cf88456d6 100644 (file)
@@ -19,9 +19,9 @@ extern "C" {
 
 /**
  * xstrdup() - same as strdup(3).  Used for portability.
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
  *
- * Sets errno to EINVAL if a NULL pointer is passed.
+ * Sets errno to EINVAL if a nullptr pointer is passed.
  *
  * Define failure_notify to receive error message.
  * otherwise perror() is used to display it.
@@ -35,7 +35,7 @@ char *xstrdup(const char *s);
 
 /*
  *  xstrncpy() - similar to strncpy(3) but terminates string
- *  always with '\0' if (n != 0 and dst != NULL),
+ *  always with '\0' if (n != 0 and dst != nullptr),
  *  and doesn't do padding
  */
 char *xstrncpy(char *dst, const char *src, size_t n);
@@ -45,9 +45,9 @@ char *xstrncpy(char *dst, const char *src, size_t n);
  * while strndup(3) copies up to n bytes and allocates up to n+1 bytes
  * to fit the terminating character. Assumes s is 0-terminated (another XXX).
  *
- * Never returns NULL; fatal on error.
+ * Never returns nullptr; fatal on error.
  *
- * Sets errno to EINVAL if a NULL pointer or negative
+ * Sets errno to EINVAL if a nullptr pointer or negative
  * length is passed.
  *
  * Define failure_notify to receive error message.
index d6b8a6e4e2ed6f80ad16132c35dcc6acf208c08b..aca00c638d629a756c122bd937bd69a0f124f906 100644 (file)
@@ -61,20 +61,20 @@ bool
 xstrtoul(const char *s, char **end, unsigned long *value,
          unsigned long min, unsigned long max)
 {
-    char *my_end = NULL;
+    char *my_end = nullptr;
 
     errno = 0;
     unsigned long v = strtoul(s, &my_end, 0);
 
     if (my_end == s)
         return false;
-    if (end != NULL)
+    if (end)
         *end = my_end;
 
     if (errno != ERANGE && min <= v && (max == 0 || v <= max)) {
-        if (value != NULL)
+        if (value)
             *value = v;
-        if (end == NULL)
+        if (!end)
             return *my_end == '\0';
         return true;
     }
@@ -88,7 +88,7 @@ xstrtoui(const char *s, char **end, unsigned int *value,
 {
     unsigned long v = 0;
     bool ret = xstrtoul(s, end, &v, min, max);
-    if (value != NULL) {
+    if (value) {
         *value = v;
 
         if (v != static_cast<unsigned long>(*value)) {
index ca8c0d3f28ea3ce79bbcf724a3e3325901750e36..f34165a859f65de202dccd8f4f07800fdafce56d 100644 (file)
@@ -20,7 +20,7 @@
  * \param min   minimum accepted value
  * \param max   maximum accepted value
  *
- * If @end is NULL, we assume the caller wants a "strict strtoul", and hence
+ * If @end is nullptr, we assume the caller wants a "strict strtoul", and hence
  * "15a" is rejected.
  * In either case, the value obtained is compared for min-max compliance.
  * Base is always 0, i.e. autodetect depending on @s.