Date: Tue, 10 Feb 2004 15:34:39 -0500 From: Bill Moran <wmoran@potentialtech.com> To: Ben Smithurst <ben@FreeBSD.org> Cc: freebsd-chat@freebsd.org Subject: Re: Could use some help with variable length argument lists Message-ID: <4029405F.1090609@potentialtech.com> In-Reply-To: <20040210202025.GA93986@strontium.bcxs.net> References: <40293B38.30401@potentialtech.com> <20040210202025.GA93986@strontium.bcxs.net>
next in thread | previous in thread | raw e-mail | index | archive | help
Ben Smithurst wrote: > 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. :-) Nope. You're understanding far more clearly than I, today. Your suggestion fixed it! I owe you a big one, if you're ever in western PA, give me a call, the drinks are on me - you've earned it! I guess it just goes to show that I've been sitting in front of this computer too long ;) -- Bill Moran Potential Technologies http://www.potentialtech.com
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4029405F.1090609>