On Sat, Aug 10, 2013 at 12:26 AM, Sergey Isakov <[email protected]> wrote: > Hi all, > I just checked edk2-14538 with cppcheck and found one of possible bug to be > a real error. > -------- > [edk2/StdLib/LibC/Stdio/vsnprintf_ss.c:145]: (error) Uninitialized variable: > n > --------- > The procedure looks like > ----------- > int > vsnprintf_ss(char *sbuf, size_t slen, const char *fmt0, va_list ap) > { <snip> > > _DIAGASSERT(n == 0 || sbuf != NULL); > _DIAGASSERT(fmt != NULL); > > ----------- > There should be > ------------- > _DIAGASSERT(slen != 0 || sbuf != NULL); > _DIAGASSERT(fmt0 != NULL); > > -------------- > How do you think? >
I'd say it should be: _DIAGASSERT(slen == 0 || sbuf != NULL); Caller can pass a NULL buffer if slen is zero - if slen is zero, nothing should be output. And if you want to be extra helpful to catch a possible common error (they should just use vsprintf style if buffer size didn't matter): _DIAGASSERT((slen == 0 || sbuf != NULL) && slen!=(size_t)-1); ------------------------------------------------------------------------------ Get 100% visibility into Java/.NET code with AppDynamics Lite! It's a free troubleshooting tool designed for production. Get down to code-level detail for bottlenecks, with <2% overhead. Download for free and get started troubleshooting in minutes. http://pubads.g.doubleclick.net/gampad/clk?id=48897031&iu=/4140/ostg.clktrk _______________________________________________ edk2-devel mailing list [email protected] https://lists.sourceforge.net/lists/listinfo/edk2-devel
