From f71627ffe0dd05f2b358398691b7fa0aad8b8deb Mon Sep 17 00:00:00 2001 From: tedu Date: Sat, 4 Jan 2014 17:50:55 +0000 Subject: [PATCH] use standard types and formats for size_t like variables. ok dtucker --- usr.bin/ssh/mac.c | 6 +++--- usr.bin/ssh/monitor_mm.c | 31 ++++++++++++++++--------------- usr.bin/ssh/monitor_mm.h | 4 ++-- usr.bin/ssh/xmalloc.c | 12 ++++++------ 4 files changed, 27 insertions(+), 26 deletions(-) diff --git a/usr.bin/ssh/mac.c b/usr.bin/ssh/mac.c index 63cd09b07aa..b2bdb193848 100644 --- a/usr.bin/ssh/mac.c +++ b/usr.bin/ssh/mac.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mac.c,v 1.25 2013/11/07 11:58:27 dtucker Exp $ */ +/* $OpenBSD: mac.c,v 1.26 2014/01/04 17:50:55 tedu Exp $ */ /* * Copyright (c) 2001 Markus Friedl. All rights reserved. * @@ -172,8 +172,8 @@ mac_compute(Mac *mac, u_int32_t seqno, u_char *data, int datalen) u_char b[4], nonce[8]; if (mac->mac_len > sizeof(u)) - fatal("mac_compute: mac too long %u %lu", - mac->mac_len, (u_long)sizeof(u)); + fatal("mac_compute: mac too long %u %zu", + mac->mac_len, sizeof(u)); switch (mac->type) { case SSH_EVP: diff --git a/usr.bin/ssh/monitor_mm.c b/usr.bin/ssh/monitor_mm.c index 76f24b125d2..f618023d7f0 100644 --- a/usr.bin/ssh/monitor_mm.c +++ b/usr.bin/ssh/monitor_mm.c @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor_mm.c,v 1.18 2013/11/08 00:39:15 djm Exp $ */ +/* $OpenBSD: monitor_mm.c,v 1.19 2014/01/04 17:50:55 tedu Exp $ */ /* * Copyright 2002 Niels Provos * All rights reserved. @@ -31,6 +31,7 @@ #include #include +#include #include #include @@ -42,7 +43,7 @@ static int mm_compare(struct mm_share *a, struct mm_share *b) { - long diff = (char *)a->address - (char *)b->address; + ptrdiff_t diff = (char *)a->address - (char *)b->address; if (diff == 0) return (0); @@ -69,8 +70,8 @@ mm_make_entry(struct mm_master *mm, struct mmtree *head, tmp2 = RB_INSERT(mmtree, head, tmp); if (tmp2 != NULL) - fatal("mm_make_entry(%p): double address %p->%p(%lu)", - mm, tmp2, address, (u_long)size); + fatal("mm_make_entry(%p): double address %p->%p(%zu)", + mm, tmp2, address, size); return (tmp); } @@ -96,9 +97,9 @@ mm_create(struct mm_master *mmalloc, size_t size) mm->mmalloc = mmalloc; address = mmap(NULL, size, PROT_WRITE|PROT_READ, MAP_ANON|MAP_SHARED, - -1, (off_t)0); + -1, 0); if (address == MAP_FAILED) - fatal("mmap(%lu): %s", (u_long)size, strerror(errno)); + fatal("mmap(%zu): %s", size, strerror(errno)); mm->address = address; mm->size = size; @@ -137,7 +138,7 @@ mm_destroy(struct mm_master *mm) mm_freelist(mm->mmalloc, &mm->rb_allocated); if (munmap(mm->address, mm->size) == -1) - fatal("munmap(%p, %lu): %s", mm->address, (u_long)mm->size, + fatal("munmap(%p, %zu): %s", mm->address, mm->size, strerror(errno)); if (mm->mmalloc == NULL) free(mm); @@ -152,7 +153,7 @@ mm_xmalloc(struct mm_master *mm, size_t size) address = mm_malloc(mm, size); if (address == NULL) - fatal("%s: mm_malloc(%lu)", __func__, (u_long)size); + fatal("%s: mm_malloc(%zu)", __func__, size); memset(address, 0, size); return (address); } @@ -187,7 +188,7 @@ mm_malloc(struct mm_master *mm, size_t size) /* Does not change order in RB tree */ mms->size -= size; - mms->address = (u_char *)mms->address + size; + mms->address = (char *)mms->address + size; if (mms->size == 0) { RB_REMOVE(mmtree, &mm->rb_free, mms); @@ -240,8 +241,8 @@ mm_free(struct mm_master *mm, void *address) /* Check if range does not overlap */ if (prev != NULL && MM_ADDRESS_END(prev) > address) - fatal("mm_free: memory corruption: %p(%lu) > %p", - prev->address, (u_long)prev->size, address); + fatal("mm_free: memory corruption: %p(%zu) > %p", + prev->address, prev->size, address); /* See if we can merge backwards */ if (prev != NULL && MM_ADDRESS_END(prev) == address) { @@ -263,8 +264,8 @@ mm_free(struct mm_master *mm, void *address) return; if (MM_ADDRESS_END(prev) > mms->address) - fatal("mm_free: memory corruption: %p < %p(%lu)", - mms->address, prev->address, (u_long)prev->size); + fatal("mm_free: memory corruption: %p < %p(%zu)", + mms->address, prev->address, prev->size); if (MM_ADDRESS_END(prev) != mms->address) return; @@ -335,12 +336,12 @@ mm_share_sync(struct mm_master **pmm, struct mm_master **pmmalloc) void mm_memvalid(struct mm_master *mm, void *address, size_t size) { - void *end = (u_char *)address + size; + void *end = (char *)address + size; if (address < mm->address) fatal("mm_memvalid: address too small: %p", address); if (end < address) fatal("mm_memvalid: end < address: %p < %p", end, address); - if (end > (void *)((u_char *)mm->address + mm->size)) + if (end > MM_ADDRESS_END(mm)) fatal("mm_memvalid: address too large: %p", address); } diff --git a/usr.bin/ssh/monitor_mm.h b/usr.bin/ssh/monitor_mm.h index c890f77097d..f1fae7e3bf5 100644 --- a/usr.bin/ssh/monitor_mm.h +++ b/usr.bin/ssh/monitor_mm.h @@ -1,4 +1,4 @@ -/* $OpenBSD: monitor_mm.h,v 1.5 2008/04/29 11:20:31 otto Exp $ */ +/* $OpenBSD: monitor_mm.h,v 1.6 2014/01/04 17:50:55 tedu Exp $ */ /* * Copyright 2002 Niels Provos @@ -47,7 +47,7 @@ RB_PROTOTYPE(mmtree, mm_share, next, mm_compare) #define MM_MINSIZE 128 -#define MM_ADDRESS_END(x) (void *)((u_char *)(x)->address + (x)->size) +#define MM_ADDRESS_END(x) (void *)((char *)(x)->address + (x)->size) struct mm_master *mm_create(struct mm_master *, size_t); void mm_destroy(struct mm_master *); diff --git a/usr.bin/ssh/xmalloc.c b/usr.bin/ssh/xmalloc.c index 7f74dff13a4..c6bd95973a6 100644 --- a/usr.bin/ssh/xmalloc.c +++ b/usr.bin/ssh/xmalloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: xmalloc.c,v 1.28 2013/05/17 00:13:14 djm Exp $ */ +/* $OpenBSD: xmalloc.c,v 1.29 2014/01/04 17:50:55 tedu Exp $ */ /* * Author: Tatu Ylonen * Copyright (c) 1995 Tatu Ylonen , Espoo, Finland @@ -31,7 +31,7 @@ xmalloc(size_t size) fatal("xmalloc: zero size"); ptr = malloc(size); if (ptr == NULL) - fatal("xmalloc: out of memory (allocating %lu bytes)", (u_long) size); + fatal("xmalloc: out of memory (allocating %zu bytes)", size); return ptr; } @@ -46,8 +46,8 @@ xcalloc(size_t nmemb, size_t size) fatal("xcalloc: nmemb * size > SIZE_T_MAX"); ptr = calloc(nmemb, size); if (ptr == NULL) - fatal("xcalloc: out of memory (allocating %lu bytes)", - (u_long)(size * nmemb)); + fatal("xcalloc: out of memory (allocating %zu bytes)", + size * nmemb); return ptr; } @@ -66,8 +66,8 @@ xrealloc(void *ptr, size_t nmemb, size_t size) else new_ptr = realloc(ptr, new_size); if (new_ptr == NULL) - fatal("xrealloc: out of memory (new_size %lu bytes)", - (u_long) new_size); + fatal("xrealloc: out of memory (new_size %zu bytes)", + new_size); return new_ptr; } -- 2.20.1