From d6045255ae916be3890780d966fda0d738b635a5 Mon Sep 17 00:00:00 2001 From: DJ Delorie Date: Thu, 17 Mar 2016 13:45:05 -0400 Subject: Replace int with size_t as appropriate --- malloc/malloc.c | 10 +++++----- malloc/mtrace-ctl.c | 16 ++++++++++------ malloc/mtrace.h | 8 ++++---- 3 files changed, 19 insertions(+), 15 deletions(-) (limited to 'malloc') diff --git a/malloc/malloc.c b/malloc/malloc.c index 69d62f6140..e4616ca411 100644 --- a/malloc/malloc.c +++ b/malloc/malloc.c @@ -1085,15 +1085,15 @@ static void free_atfork(void* mem, const void *caller); #include "mtrace.h" volatile __malloc_trace_buffer_ptr __malloc_trace_buffer = NULL; -volatile int __malloc_trace_buffer_size = 0; -volatile int __malloc_trace_buffer_head = 0; +volatile size_t __malloc_trace_buffer_size = 0; +volatile size_t __malloc_trace_buffer_head = 0; static __thread __malloc_trace_buffer_ptr trace_ptr; static void __mtb_trace_entry (uint32_t type, int64_t size, void *ptr1) { - int head1; + size_t head1; head1 = catomic_exchange_and_add (&__malloc_trace_buffer_head, 1); @@ -1115,7 +1115,7 @@ __mtb_trace_entry (uint32_t type, int64_t size, void *ptr1) } int -__malloc_set_trace_buffer (void *bufptr, int bufsize) +__malloc_set_trace_buffer (void *bufptr, size_t bufsize) { __malloc_trace_buffer = 0; __malloc_trace_buffer_size = bufsize / sizeof(struct __malloc_trace_buffer_s); @@ -1125,7 +1125,7 @@ __malloc_set_trace_buffer (void *bufptr, int bufsize) } void * -__malloc_get_trace_buffer (int *bufcount, int *bufhead) +__malloc_get_trace_buffer (size_t *bufcount, size_t *bufhead) { if (bufcount) *bufcount = __malloc_trace_buffer_size; diff --git a/malloc/mtrace-ctl.c b/malloc/mtrace-ctl.c index a253a56288..d972dfcaae 100644 --- a/malloc/mtrace-ctl.c +++ b/malloc/mtrace-ctl.c @@ -29,15 +29,15 @@ void __attribute__((constructor)) djmain() { char *e; - int sz; + size_t sz; e = getenv("MTRACE_CTL_COUNT"); if (!e) e = "1000"; - sz = atoi(e) * sizeof(struct __malloc_trace_buffer_s); + sz = (size_t) atol(e) * sizeof(struct __malloc_trace_buffer_s); char *buf = mmap (NULL, sz, PROT_READ | PROT_WRITE, MAP_PRIVATE | MAP_ANONYMOUS, -1, 0); - if (!buf) + if (buf == NULL || buf == (char *)(-1)) err("Cannot mmap"); buf[0] = 1; @@ -64,7 +64,7 @@ djend() { char *e; FILE *outf; - int head, size, i; + size_t head, size, i; /* Prevent problems with recursion etc by shutting off trace right away. */ __malloc_trace_buffer_ptr buf = __malloc_get_trace_buffer (&size, &head); @@ -72,14 +72,18 @@ djend() e = getenv("MTRACE_CTL_FILE"); if (!e) - e = "/tmp/mtrace.out"; + { + static char fname[100]; + sprintf(fname, "/tmp/mtrace-%d.out", getpid()); + e = fname; + } outf = fopen(e, "w"); if (!outf) err("cannot open output file"); setbuf (outf, NULL); - fprintf (outf, "%d out of %d events captured\n", head, size); + fprintf (outf, "%ld out of %ld events captured\n", (long)head, (long)size); fprintf (outf, "threadid type path ptr1 size ptr2\n"); for (i=0; i