Fix asprintf bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3653 42af7a65-404d-4744-a932-0658087f49c3
This commit is contained in:
parent
29a70ad011
commit
c68ddb5a57
8
TODO
8
TODO
|
@ -1,4 +1,4 @@
|
|||
NuttX TODO List (Last updated May 28, 2011)
|
||||
NuttX TODO List (Last updated May 31, 2011)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
nuttx/
|
||||
|
@ -12,7 +12,7 @@ nuttx/
|
|||
(5) Binary loaders (binfmt/)
|
||||
(15) Network (net/, drivers/net)
|
||||
(2) USB (drivers/usbdev, drivers/usbhost)
|
||||
(5) Libraries (lib/)
|
||||
(6) Libraries (lib/)
|
||||
(13) File system/Generic drivers (fs/, drivers/)
|
||||
(1) Graphics subystem (graphics/)
|
||||
(1) Pascal add-on (pcode/)
|
||||
|
@ -386,6 +386,10 @@ o Libraries (lib/)
|
|||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
Description: Not implemented: ferror() and clearerr()
|
||||
Status: Open
|
||||
Priority: Low
|
||||
|
||||
o File system / Generic drivers (fs/, drivers/)
|
||||
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
||||
|
||||
|
|
|
@ -101,6 +101,8 @@ int asprintf (FAR char **ptr, const char *fmt, ...)
|
|||
va_list ap;
|
||||
int n;
|
||||
|
||||
DEBUGASSERT(ptr && fmt);
|
||||
|
||||
/* First, use a nullstream to get the size of the buffer */
|
||||
|
||||
lib_nulloutstream(&nulloutstream);
|
||||
|
@ -121,13 +123,19 @@ int asprintf (FAR char **ptr, const char *fmt, ...)
|
|||
lib_memoutstream((FAR struct lib_memoutstream_s *)&memoutstream,
|
||||
buf, nulloutstream.nput);
|
||||
|
||||
/* Then let lib_vsprintf do it real thing */
|
||||
/* Then let lib_vsprintf do it's real thing */
|
||||
|
||||
va_start(ap, fmt);
|
||||
n = lib_vsprintf((FAR struct lib_outstream_s *)&memoutstream.public, fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
/* Terminate the string and return a pointer to the string to the caller.
|
||||
* Hmmm.. looks like the memory would be stranded if lib_vsprintf() returned
|
||||
* an error. Does that ever happen?
|
||||
*/
|
||||
|
||||
DEBUGASSERT(n < 0 || n == nulloutstream.nput);
|
||||
buf[nulloutstream.nput] = '\0';
|
||||
*ptr = buf;
|
||||
return n;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue