]> git.ipfire.org Git - thirdparty/squid.git/commitdiff
Cleanup: remove several C-style casts from libcompat
authorAmos Jeffries <squid3@treenet.co.nz>
Fri, 5 Feb 2016 10:53:29 +0000 (23:53 +1300)
committerAmos Jeffries <squid3@treenet.co.nz>
Fri, 5 Feb 2016 10:53:29 +0000 (23:53 +1300)
compat/debug.h
compat/xalloc.cc
compat/xis.h
compat/xstring.cc

index dee773d59e7a10f348b83f44af29cd371b48886a..3b40d276490b19bf4ceae46a5a6c5e2f1afe0ad2 100644 (file)
@@ -27,7 +27,7 @@ SQUIDCEXTERN int debug_enabled;
 
 #define debug(X...) \
                      if (debug_enabled) { \
-                         fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, (long)getpid() ); \
+                         fprintf(stderr, "%s(%d): pid=%ld :", __FILE__, __LINE__, static_cast<long>(getpid())); \
                          fprintf(stderr,X); \
                      } else (void)0
 
index 4ba3bfd888b200fe37b97c6a6a01985b2c25c83b..a2c8e895b2be30aa771b683190148d059853eae2 100644 (file)
@@ -86,7 +86,7 @@ xcalloc(size_t n, size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xcalloc: Unable to allocate %lu blocks of %lu bytes!\n", (unsigned long)n, (unsigned long)sz);
+            snprintf(msg, 128, "xcalloc: Unable to allocate %" PRIuSIZE " blocks of %" PRIuSIZE " bytes!\n", n, sz);
             failure_notify(msg);
         } else {
             perror("xcalloc");
@@ -117,7 +117,7 @@ xmalloc(size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xmalloc: Unable to allocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xmalloc: Unable to allocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("malloc");
@@ -148,7 +148,7 @@ xrealloc(void *s, size_t sz)
     if (p == NULL) {
         if (failure_notify) {
             static char msg[128];
-            snprintf(msg, 128, "xrealloc: Unable to reallocate %lu bytes!\n", (unsigned long)sz);
+            snprintf(msg, 128, "xrealloc: Unable to reallocate %" PRIuSIZE " bytes!\n", sz);
             failure_notify(msg);
         } else {
             perror("realloc");
index 29f9fe0130fb4d9ef0e7a315afd3be0cff8549eb..3caf850a435db3e33b6b88e9fef49d38b9a35b3b 100644 (file)
 #if HAVE_CTYPE_H
 #include <ctype.h>
 #endif
+
+#if __cplusplus
+#define xisspace(x) isspace(static_cast<unsigned char>(x))
+#define xtoupper(x) toupper(static_cast<unsigned char>(x))
+#define xtolower(x) tolower(static_cast<unsigned char>(x))
+#define xisdigit(x) isdigit(static_cast<unsigned char>(x))
+#define xisascii(x) isascii(static_cast<unsigned char>(x))
+#define xislower(x) islower(static_cast<unsigned char>(x))
+#define xisalpha(x) isalpha(static_cast<unsigned char>(x))
+#define xisprint(x) isprint(static_cast<unsigned char>(x))
+#define xisalnum(x) isalnum(static_cast<unsigned char>(x))
+#define xiscntrl(x) iscntrl(static_cast<unsigned char>(x))
+#define xispunct(x) ispunct(static_cast<unsigned char>(x))
+#define xisupper(x) isupper(static_cast<unsigned char>(x))
+#define xisxdigit(x) isxdigit(static_cast<unsigned char>(x))
+#define xisgraph(x) isgraph(static_cast<unsigned char>(x))
+
+#else /* ! __cplusplus */
 #define xisspace(x) isspace((unsigned char)x)
 #define xtoupper(x) toupper((unsigned char)x)
 #define xtolower(x) tolower((unsigned char)x)
@@ -26,6 +44,7 @@
 #define xisupper(x) isupper((unsigned char)x)
 #define xisxdigit(x) isxdigit((unsigned char)x)
 #define xisgraph(x) isgraph((unsigned char)x)
+#endif
 
 #endif /* _SQUID_COMPAT_XIS_H */
 
index 7c16880f0d61150ff16a5a76964cfd0228c7268a..7f02d33f3c5f8aa493cfd2b533dfdf5264cab650 100644 (file)
 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 {
@@ -29,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;
@@ -58,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");
@@ -71,12 +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;
 }