Skip to content

improve ULOG_OUTPUT_FLOAT, which avoids using inherent vsnprintf #5632

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions components/utilities/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ config RT_USING_ULOG
config ULOG_OUTPUT_FLOAT
bool "Enable float number support. It will using more thread stack."
default n
select PKG_USING_RT_VSNPRINTF_FULL
help
The default formater is using rt_vsnprint and it not supported float number.
When enable this option then it will enable libc. The formater will change to vsnprint on libc.
Expand Down
9 changes: 0 additions & 9 deletions components/utilities/ulog/syslog/syslog.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@
#include <stdint.h>
#include "syslog.h"

#ifdef ULOG_OUTPUT_FLOAT
#include <stdio.h>
#endif

/*
* reference:
* http://pubs.opengroup.org/onlinepubs/7908799/xsh/syslog.h.html
Expand Down Expand Up @@ -227,12 +223,7 @@ RT_WEAK rt_size_t syslog_formater(char *log_buf, int level, const char *tag, rt_
#endif /* ULOG_OUTPUT_THREAD_NAME */

log_len += ulog_strcpy(log_len, log_buf + log_len, ": ");

#ifdef ULOG_OUTPUT_FLOAT
fmt_result = vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
#else
fmt_result = rt_vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
#endif /* ULOG_OUTPUT_FLOAT */

/* calculate log length */
if ((log_len + fmt_result <= ULOG_LINE_BUF_SIZE) && (fmt_result > -1))
Expand Down
16 changes: 1 addition & 15 deletions components/utilities/ulog/ulog.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
#include <syslog.h>
#endif

#ifdef ULOG_OUTPUT_FLOAT
#include <stdio.h>
#endif

#ifdef ULOG_TIME_USING_TIMESTAMP
#include <sys/time.h>
#endif
Expand Down Expand Up @@ -367,12 +363,7 @@ RT_WEAK rt_size_t ulog_formater(char *log_buf, rt_uint32_t level, const char *ta
#endif /* ULOG_OUTPUT_THREAD_NAME */

log_len += ulog_strcpy(log_len, log_buf + log_len, ": ");

#ifdef ULOG_OUTPUT_FLOAT
fmt_result = vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
#else
fmt_result = rt_vsnprintf(log_buf + log_len, ULOG_LINE_BUF_SIZE - log_len, format, args);
#endif /* ULOG_OUTPUT_FLOAT */

/* calculate log length */
if ((log_len + fmt_result <= ULOG_LINE_BUF_SIZE) && (fmt_result > -1))
Expand Down Expand Up @@ -674,15 +665,10 @@ void ulog_raw(const char *format, ...)

/* lock output */
output_lock();

/* args point to the first variable parameter */
va_start(args, format);

#ifdef ULOG_OUTPUT_FLOAT
fmt_result = vsnprintf(log_buf, ULOG_LINE_BUF_SIZE, format, args);
#else
fmt_result = rt_vsnprintf(log_buf, ULOG_LINE_BUF_SIZE, format, args);
#endif /* ULOG_OUTPUT_FLOAT */

va_end(args);

/* calculate log length */
Expand Down