看板 FB_chat 關於我們 聯絡資訊
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"