summaryrefslogtreecommitdiff
path: root/nuttx/lib
diff options
context:
space:
mode:
authorpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-31 23:32:48 +0000
committerpatacongo <patacongo@42af7a65-404d-4744-a932-0658087f49c3>2011-05-31 23:32:48 +0000
commit7130c3c2de1b2e7647584b400367fbaae75d93a4 (patch)
tree65dbadb523bdab6338f9bc8969341fa76c031bec /nuttx/lib
parentcdd3a2dd952db4892ecb2350b639b0abe715d53d (diff)
downloadpx4-nuttx-7130c3c2de1b2e7647584b400367fbaae75d93a4.tar.gz
px4-nuttx-7130c3c2de1b2e7647584b400367fbaae75d93a4.tar.bz2
px4-nuttx-7130c3c2de1b2e7647584b400367fbaae75d93a4.zip
Fix asprintf bug
git-svn-id: svn://svn.code.sf.net/p/nuttx/code/trunk@3653 42af7a65-404d-4744-a932-0658087f49c3
Diffstat (limited to 'nuttx/lib')
-rw-r--r--nuttx/lib/stdio/lib_asprintf.c10
1 files changed, 9 insertions, 1 deletions
diff --git a/nuttx/lib/stdio/lib_asprintf.c b/nuttx/lib/stdio/lib_asprintf.c
index 2baffe1ac..42467e71d 100644
--- a/nuttx/lib/stdio/lib_asprintf.c
+++ b/nuttx/lib/stdio/lib_asprintf.c
@@ -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;
}