From owner-freebsd-bugs Tue Oct 5 18:12: 7 1999 Delivered-To: freebsd-bugs@freebsd.org Received: from freefall.freebsd.org (freefall.FreeBSD.ORG [204.216.27.21]) by hub.freebsd.org (Postfix) with ESMTP id 8497214A17 for ; Tue, 5 Oct 1999 18:12:04 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Received: (from gnats@localhost) by freefall.freebsd.org (8.9.3/8.9.2) id SAA02518; Tue, 5 Oct 1999 18:10:02 -0700 (PDT) (envelope-from gnats@FreeBSD.org) Date: Tue, 5 Oct 1999 18:10:02 -0700 (PDT) Message-Id: <199910060110.SAA02518@freefall.freebsd.org> To: freebsd-bugs@FreeBSD.org Cc: From: Bruce Evans Subject: Re: bin/14142: sendmail: mci.c: bad pointer conversion in debug print Reply-To: Bruce Evans Sender: owner-freebsd-bugs@FreeBSD.ORG Precedence: bulk X-Loop: FreeBSD.org The following reply was made to PR bin/14142; it has been noted by GNATS. From: Bruce Evans To: Valentin Nechayev Cc: FreeBSD-gnats-submit@FreeBSD.ORG Subject: Re: bin/14142: sendmail: mci.c: bad pointer conversion in debug print Date: Wed, 6 Oct 1999 10:59:25 +1000 (EST) > The following piece of mci_dump() uses bad conversion: > > snprintf(p, SPACELEFT(buf, p), "MCI@%lx: ", > sizeof(void *) == sizeof(u_long) ? > (u_long)(void *)mci : (u_long)(u_int)(void *)mci); > > On Alpha architecture, conversion from void* to u_int loses significant bits. On FreeBSD-alpha sizeof(void *) == sizeof(long), so the conversion from void * to u_int is never executed. Unfortunately, gcc apparently warns about casts from pointers to integers of a different size even in dead code. On FreeBSD_i386-with-64-bit-longs, gcc warns about the dead code in the other arm of the if and about 3 casts from pointers to u_longs. All these problems can be fixed better now by casting pointers to (u_long)(uintptr_t)(void *) and printing them with %lx, or if the format doesn't matter, by casting pointers to (void *) and printing them with %p. > These conversions are FreeBSD-specific; original Allman's sendmail > does not contain them. The original code was broken at runtime (it shows only the low 32 bits of pointers on FreeBSD-alpha). Bruce To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-bugs" in the body of the message