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
[-- Attachment #1 --]
Bill Moran wrote:
> char **format, **errmsg;
>
> va_start(ap, message);
> if (level <= LOGLEVEL) {
> asprintf(format, "PID %d: %s", getpid(), message);
...
> Doesn't seem too difficult, right? However, if I call the function
> from elsewhere in my application like this:
>
> _log(1, "Log test");
>
> 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;
...
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. :-)
--
Ben Smithurst / ben@FreeBSD.org FreeBSD: The Power To Serve
http://www.FreeBSD.org/
[-- Attachment #2 --]
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.2.4 (FreeBSD)
iD8DBQFAKT0JbPzJ+yzvRCwRAu+3AKCzkW07ait8hjbFAmEgQLqYwCFvsgCfbAYw
IqL9xzbG7pz2KQMlxCACfik=
=keic
-----END PGP SIGNATURE-----
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20040210202025.GA93986>
