]> git.ipfire.org Git - thirdparty/squid.git/blobdiff - compat/xstring.cc
SourceFormat Enforcement
[thirdparty/squid.git] / compat / xstring.cc
index 622695802114e373727cab48ea31a28467e47848..bba036b1d9bfac290618490dd579754ca6b90c0c 100644 (file)
@@ -1,3 +1,11 @@
+/*
+ * Copyright (C) 1996-2017 The Squid Software Foundation and contributors
+ *
+ * Squid software is distributed under GPLv2+ license and includes
+ * contributions from numerous individuals and organizations.
+ * Please see the COPYING and CONTRIBUTORS files for details.
+ */
+
 #include "squid.h"
 #include "compat/xalloc.h"
 #include "compat/xstring.h"
@@ -7,10 +15,7 @@
 char *
 xstrdup(const char *s)
 {
-    size_t sz;
-    char *p;
-
-    if (s == NULL) {
+    if (!s) {
         if (failure_notify) {
             (*failure_notify) ("xstrdup: tried to dup a NULL pointer!\n");
         } else {
@@ -21,8 +26,8 @@ xstrdup(const char *s)
     }
 
     /* copy string, including terminating character */
-    sz = strlen(s) + 1;
-    p = (char *)xmalloc(sz);
+    size_t sz = strlen(s) + 1;
+    char *p = static_cast<char *>(xmalloc(sz));
     memcpy(p, s, sz);
 
     return p;
@@ -50,10 +55,7 @@ xstrncpy(char *dst, const char *src, size_t n)
 char *
 xstrndup(const char *s, size_t n)
 {
-    size_t sz;
-    char *p;
-
-    if (s == NULL) {
+    if (!s) {
         errno = EINVAL;
         if (failure_notify) {
             (*failure_notify) ("xstrndup: tried to dup a NULL pointer!\n");
@@ -63,11 +65,12 @@ xstrndup(const char *s, size_t n)
         exit(1);
     }
 
-    sz = strlen(s) + 1;
+    size_t sz = strlen(s) + 1;
     // size_t is unsigned, as mandated by c99 and c++ standards.
     if (sz > n)
         sz = n;
 
-    p = xstrncpy((char *)xmalloc(sz), s, sz);
+    char *p = xstrncpy(static_cast<char *>(xmalloc(sz)), s, sz);
     return p;
 }
+