Skip to content

Commit

Permalink
Merge pull request #623 from ssilverman/issue-591
Browse files Browse the repository at this point in the history
Fix Print::printf() to call va_end()
  • Loading branch information
PaulStoffregen committed Dec 22, 2021
2 parents cbfea6e + 42006d0 commit ca6c78b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 6 deletions.
8 changes: 6 additions & 2 deletions teensy/Print.cpp
Expand Up @@ -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, ...)
Expand All @@ -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;
}


Expand Down
10 changes: 8 additions & 2 deletions teensy3/Print.cpp
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down
10 changes: 8 additions & 2 deletions teensy4/Print.cpp
Expand Up @@ -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
}

Expand All @@ -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
}

Expand Down

0 comments on commit ca6c78b

Please sign in to comment.