Date: Tue, 10 Feb 2004 20:20:25 +0000 From: Ben Smithurst <ben@FreeBSD.org> To: Bill Moran <wmoran@potentialtech.com> Cc: freebsd-chat@freebsd.org Subject: Re: Could use some help with variable length argument lists Message-ID: <20040210202025.GA93986@strontium.bcxs.net> In-Reply-To: <40293B38.30401@potentialtech.com> References: <40293B38.30401@potentialtech.com>
next in thread | previous in thread | raw e-mail | index | archive | help
--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--
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040210202025.GA93986>