summaryrefslogtreecommitdiff
path: root/deps/jemalloc/src/util.c
diff options
context:
space:
mode:
Diffstat (limited to 'deps/jemalloc/src/util.c')
-rwxr-xr-x[-rw-r--r--]deps/jemalloc/src/util.c42
1 files changed, 29 insertions, 13 deletions
diff --git a/deps/jemalloc/src/util.c b/deps/jemalloc/src/util.c
index 4cb0d6c1e..dd8c23630 100644..100755
--- a/deps/jemalloc/src/util.c
+++ b/deps/jemalloc/src/util.c
@@ -1,3 +1,7 @@
+/*
+ * Define simple versions of assertion macros that won't recurse in case
+ * of assertion failures in malloc_*printf().
+ */
#define assert(e) do { \
if (config_debug && !(e)) { \
malloc_write("<jemalloc>: Failed assertion\n"); \
@@ -10,6 +14,7 @@
malloc_write("<jemalloc>: Unreachable code reached\n"); \
abort(); \
} \
+ unreachable(); \
} while (0)
#define not_implemented() do { \
@@ -44,15 +49,19 @@ static void
wrtmessage(void *cbopaque, const char *s)
{
-#ifdef SYS_write
+#if defined(JEMALLOC_USE_SYSCALL) && defined(SYS_write)
/*
* Use syscall(2) rather than write(2) when possible in order to avoid
* the possibility of memory allocation within libc. This is necessary
* on FreeBSD; most operating systems do not have this problem though.
+ *
+ * syscall() returns long or int, depending on platform, so capture the
+ * unused result in the widest plausible type to avoid compiler
+ * warnings.
*/
- UNUSED int result = syscall(SYS_write, STDERR_FILENO, s, strlen(s));
+ UNUSED long result = syscall(SYS_write, STDERR_FILENO, s, strlen(s));
#else
- UNUSED int result = write(STDERR_FILENO, s, strlen(s));
+ UNUSED ssize_t result = write(STDERR_FILENO, s, strlen(s));
#endif
}
@@ -82,7 +91,7 @@ buferror(int err, char *buf, size_t buflen)
#ifdef _WIN32
FormatMessageA(FORMAT_MESSAGE_FROM_SYSTEM, NULL, err, 0,
- (LPSTR)buf, buflen, NULL);
+ (LPSTR)buf, (DWORD)buflen, NULL);
return (0);
#elif defined(__GLIBC__) && defined(_GNU_SOURCE)
char *b = strerror_r(err, buf, buflen);
@@ -191,7 +200,7 @@ malloc_strtoumax(const char *restrict nptr, char **restrict endptr, int base)
p++;
}
if (neg)
- ret = -ret;
+ ret = (uintmax_t)(-((intmax_t)ret));
if (p == ns) {
/* No conversion performed. */
@@ -306,10 +315,9 @@ x2s(uintmax_t x, bool alt_form, bool uppercase, char *s, size_t *slen_p)
return (s);
}
-int
+size_t
malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
{
- int ret;
size_t i;
const char *f;
@@ -400,6 +408,8 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
int prec = -1;
int width = -1;
unsigned char len = '?';
+ char *s;
+ size_t slen;
f++;
/* Flags. */
@@ -490,8 +500,6 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
}
/* Conversion specifier. */
switch (*f) {
- char *s;
- size_t slen;
case '%':
/* %% */
APPEND_C(*f);
@@ -577,20 +585,19 @@ malloc_vsnprintf(char *str, size_t size, const char *format, va_list ap)
str[i] = '\0';
else
str[size - 1] = '\0';
- ret = i;
#undef APPEND_C
#undef APPEND_S
#undef APPEND_PADDED_S
#undef GET_ARG_NUMERIC
- return (ret);
+ return (i);
}
JEMALLOC_FORMAT_PRINTF(3, 4)
-int
+size_t
malloc_snprintf(char *str, size_t size, const char *format, ...)
{
- int ret;
+ size_t ret;
va_list ap;
va_start(ap, format);
@@ -648,3 +655,12 @@ malloc_printf(const char *format, ...)
malloc_vcprintf(NULL, NULL, format, ap);
va_end(ap);
}
+
+/*
+ * Restore normal assertion macros, in order to make it possible to compile all
+ * C files as a single concatenation.
+ */
+#undef assert
+#undef not_reached
+#undef not_implemented
+#include "jemalloc/internal/assert.h"