Re: Could use some help with variable length argument lists

看板FB_chat作者時間22年前 (2004/02/11 04:35), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串4/5 (看更多)
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 _______________________________________________ freebsd-chat@freebsd.org mailing list http://lists.freebsd.org/mailman/listinfo/freebsd-chat To unsubscribe, send any mail to "freebsd-chat-unsubscribe@freebsd.org"
文章代碼(AID): #10AK2900 (FB_chat)
討論串 (同標題文章)
文章代碼(AID): #10AK2900 (FB_chat)