discuss@mandoc.bsd.lv
 help / color / mirror / Atom feed
* Logic error in mandoc.c time2a()
@ 2011-03-11 20:42 Ulrich Spörlein
  2011-03-12  0:27 ` Ingo Schwarze
  0 siblings, 1 reply; 2+ messages in thread
From: Ulrich Spörlein @ 2011-03-11 20:42 UTC (permalink / raw)
  To: discuss

Hi,

now that the clang/llvm folks unbroke their static analysis tool again,
I had another run on the mdocml sources. Only one bug stood out
(disregard the 'Dead store' class).

See https://www.spoerlein.net/scan-build/mdocml/2011-03-11-1/

In time2a(), 'buf' is a stack-local buffer and its address will be
returned. Oops. Either make it global, static, use malloc/free, or have
the caller provide the buffer, not sure which solution you guys would
prefer.

Uli
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Logic error in mandoc.c time2a()
  2011-03-11 20:42 Logic error in mandoc.c time2a() Ulrich Spörlein
@ 2011-03-12  0:27 ` Ingo Schwarze
  0 siblings, 0 replies; 2+ messages in thread
From: Ingo Schwarze @ 2011-03-12  0:27 UTC (permalink / raw)
  To: discuss

Hi Ulrich,

Ulrich Spoerlein wrote on Fri, Mar 11, 2011 at 09:42:04PM +0100:

> now that the clang/llvm folks unbroke their static analysis tool again,
> I had another run on the mdocml sources. Only one bug stood out
> (disregard the 'Dead store' class).
> 
> See https://www.spoerlein.net/scan-build/mdocml/2011-03-11-1/
> 
> In time2a(), 'buf' is a stack-local buffer and its address will be
> returned. Oops.

Oops indeed, i guess i'm programming too much in Perl lately,
forming bad habits like returning references to local storage.

> Either make it global, static, use malloc/free,

malloc is the way to go here; time2a ist static and called
from one place only, and the return value is strdup'ed right
away, so we can as well malloc it in the first place.
I need to cook a diff...

> or have the caller provide the buffer, not sure which solution you guys
> would prefer.

Thanks,
  Ingo
--
 To unsubscribe send an email to discuss+unsubscribe@mdocml.bsd.lv

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2011-03-12  0:27 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-03-11 20:42 Logic error in mandoc.c time2a() Ulrich Spörlein
2011-03-12  0:27 ` Ingo Schwarze

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).