Skip to content
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

src: use SPrintF in ProcessEmitWarning #38758

Closed
Closed
Show file tree
Hide file tree
Changes from 1 commit
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
5 changes: 4 additions & 1 deletion src/node_process.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,10 @@ v8::Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
const char* type = nullptr,
const char* code = nullptr);

v8::Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...);
template <typename... Args>
v8::Maybe<bool> ProcessEmitWarning(Environment* env,
const char* fmt,
Args&&... args);
v8::Maybe<bool> ProcessEmitExperimentalWarning(Environment* env,
const char* warning);
v8::Maybe<bool> ProcessEmitDeprecationWarning(Environment* env,
Expand Down
15 changes: 7 additions & 8 deletions src/node_process_events.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#include <set>

#include "env-inl.h"
#include "debug_utils-inl.h"
#include "node_process.h"
#include "util.h"

Expand Down Expand Up @@ -85,15 +86,13 @@ Maybe<bool> ProcessEmitWarningGeneric(Environment* env,
}

// Call process.emitWarning(str), fmt is a snprintf() format string
Maybe<bool> ProcessEmitWarning(Environment* env, const char* fmt, ...) {
char warning[1024];
va_list ap;
template <typename... Args>
v8::Maybe<bool> ProcessEmitWarning(Environment* env,
const char* fmt,
Args&&... args) {
std::string warning = SPrintF(fmt, std::forward<Args>(args)...);

va_start(ap, fmt);
vsnprintf(warning, sizeof(warning), fmt, ap);
va_end(ap);

return ProcessEmitWarningGeneric(env, warning);
return ProcessEmitWarningGeneric(env, warning.c_str());
}


Expand Down