From owner-freebsd-chat@FreeBSD.ORG Tue Feb 10 12:20:27 2004 Return-Path: Delivered-To: freebsd-chat@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 3CE4E16A4CE for ; Tue, 10 Feb 2004 12:20:27 -0800 (PST) Received: from strontium.bcxs.net (strontium.bcxs.net [81.174.236.226]) by mx1.FreeBSD.org (Postfix) with ESMTP id EAC9643D1F for ; Tue, 10 Feb 2004 12:20:26 -0800 (PST) (envelope-from ben@FreeBSD.org) Received: from ben by strontium.bcxs.net with local (Exim 4.30) id 1AqeMs-000OZF-08; Tue, 10 Feb 2004 20:20:26 +0000 Date: Tue, 10 Feb 2004 20:20:25 +0000 From: Ben Smithurst To: Bill Moran Message-ID: <20040210202025.GA93986@strontium.bcxs.net> References: <40293B38.30401@potentialtech.com> Mime-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="AhhlLboLdkugWU4S" Content-Disposition: inline In-Reply-To: <40293B38.30401@potentialtech.com> User-Agent: Mutt/1.4.1i X-PGP-Key: http://www.smithurst.org/ben/pgp-key.txt cc: freebsd-chat@freebsd.org Subject: Re: Could use some help with variable length argument lists X-BeenThere: freebsd-chat@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Non technical items related to the community List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 10 Feb 2004 20:20:27 -0000 --AhhlLboLdkugWU4S Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable Bill Moran wrote: > char **format, **errmsg; >=20 > va_start(ap, message); > if (level <=3D LOGLEVEL) { > asprintf(format, "PID %d: %s", getpid(), message); =2E.. > Doesn't seem too difficult, right? However, if I call the function > from elsewhere in my application like this: >=20 > _log(1, "Log test"); >=20 > I get a coredump! gdb complains that message is "out of bounds" > on the line "asprintf(format, "PID %d: %s", getpid(), message);" are you sure it isn't the format variable causing the problem? It's a while since I've used asprintf() but from memory you should write something more like char *format; =2E.. asprintf(&format, "PID %d: %s", getpid(), message); Your code above is passing format uninitialized (you should have got a compile time warning about that). Or maybe I'm misunderstanding something. :-) --=20 Ben Smithurst / ben@FreeBSD.org FreeBSD: The Power To Serve http://www.FreeBSD.org/ --AhhlLboLdkugWU4S Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.2.4 (FreeBSD) iD8DBQFAKT0JbPzJ+yzvRCwRAu+3AKCzkW07ait8hjbFAmEgQLqYwCFvsgCfbAYw IqL9xzbG7pz2KQMlxCACfik= =keic -----END PGP SIGNATURE----- --AhhlLboLdkugWU4S--