From 42006d027d51874f24a30b70fd967e2b2095019e Mon Sep 17 00:00:00 2001 From: Shawn Silverman Date: Mon, 25 Oct 2021 13:27:35 -0700 Subject: [PATCH] Fix Print::printf() to call va_end() --- teensy/Print.cpp | 8 ++++++-- teensy3/Print.cpp | 10 ++++++++-- teensy4/Print.cpp | 10 ++++++++-- 3 files changed, 22 insertions(+), 6 deletions(-) diff --git a/teensy/Print.cpp b/teensy/Print.cpp index 4ee7e0917..8a6ed8f6a 100644 --- a/teensy/Print.cpp +++ b/teensy/Print.cpp @@ -102,7 +102,9 @@ int Print::printf(const char *format, ...) fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE); fdev_set_udata(&f, this); va_start(ap, format); - return vfprintf(&f, format, ap); + int retval = vfprintf(&f, format, ap); + va_end(ap); + return retval; } int Print::printf(const __FlashStringHelper *format, ...) @@ -113,7 +115,9 @@ int Print::printf(const __FlashStringHelper *format, ...) fdev_setup_stream(&f, printf_putchar, NULL, _FDEV_SETUP_WRITE); fdev_set_udata(&f, this); va_start(ap, format); - return vfprintf_P(&f, (const char *)format, ap); + int retval = vfprintf_P(&f, (const char *)format, ap); + va_end(ap); + return retval; } diff --git a/teensy3/Print.cpp b/teensy3/Print.cpp index 601635310..cc63975d1 100644 --- a/teensy3/Print.cpp +++ b/teensy3/Print.cpp @@ -96,9 +96,12 @@ int Print::printf(const char *format, ...) va_list ap; va_start(ap, format); #ifdef __STRICT_ANSI__ + va_end(ap); return 0; // TODO: make this work with -std=c++0x #else - return vdprintf((int)this, format, ap); + int retval = vdprintf((int)this, format, ap); + va_end(ap); + return retval; #endif } @@ -107,9 +110,12 @@ int Print::printf(const __FlashStringHelper *format, ...) va_list ap; va_start(ap, format); #ifdef __STRICT_ANSI__ + va_end(ap); return 0; #else - return vdprintf((int)this, (const char *)format, ap); + int retval = vdprintf((int)this, (const char *)format, ap); + va_end(ap); + return retval; #endif } diff --git a/teensy4/Print.cpp b/teensy4/Print.cpp index a4d24fe66..9a63c46a1 100644 --- a/teensy4/Print.cpp +++ b/teensy4/Print.cpp @@ -102,9 +102,12 @@ int Print::printf(const char *format, ...) va_list ap; va_start(ap, format); #ifdef __STRICT_ANSI__ + va_end(ap); return 0; // TODO: make this work with -std=c++0x #else - return vdprintf((int)this, format, ap); + int retval = vdprintf((int)this, format, ap); + va_end(ap); + return retval; #endif } @@ -113,9 +116,12 @@ int Print::printf(const __FlashStringHelper *format, ...) va_list ap; va_start(ap, format); #ifdef __STRICT_ANSI__ + va_end(ap); return 0; #else - return vdprintf((int)this, (const char *)format, ap); + int retval = vdprintf((int)this, (const char *)format, ap); + va_end(ap); + return retval; #endif }