Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/nodejs/node.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnna Henningsen <anna@addaleax.net>2020-01-21 22:30:35 +0300
committerShelley Vohr <shelley.vohr@gmail.com>2020-02-17 22:17:05 +0300
commit76aad0e5e1ada72ca39e1f73c31d7e81bc6e2dc0 (patch)
treeec06bb073dfeb3ce153bdc676880ba1342cd6707 /src/debug_utils.h
parenta685827a55a74427562fbe7255e78e5b9fba0d68 (diff)
src: use custom fprintf alike to write errors to stderr
This allows printing errors that contain nul characters, for example. Fixes: https://github.com/nodejs/node/issues/28761 Fixes: https://github.com/nodejs/node/issues/31218 PR-URL: https://github.com/nodejs/node/pull/31446 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Gus Caplan <me@gus.host> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Rich Trott <rtrott@gmail.com>
Diffstat (limited to 'src/debug_utils.h')
-rw-r--r--src/debug_utils.h10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/debug_utils.h b/src/debug_utils.h
index 08d23bb7703..c745cbe0a1a 100644
--- a/src/debug_utils.h
+++ b/src/debug_utils.h
@@ -25,13 +25,16 @@ namespace node {
template <typename T>
inline std::string ToString(const T& value);
-// C++-style variant of sprintf() that:
+// C++-style variant of sprintf()/fprintf() that:
// - Returns an std::string
// - Handles \0 bytes correctly
// - Supports %p and %s. %d, %i and %u are aliases for %s.
// - Accepts any class that has a ToString() method for stringification.
template <typename... Args>
inline std::string SPrintF(const char* format, Args&&... args);
+template <typename... Args>
+inline void FPrintF(FILE* file, const char* format, Args&&... args);
+void FWrite(FILE* file, const std::string& str);
template <typename... Args>
inline void FORCE_INLINE Debug(Environment* env,
@@ -40,8 +43,7 @@ inline void FORCE_INLINE Debug(Environment* env,
Args&&... args) {
if (!UNLIKELY(env->debug_enabled(cat)))
return;
- std::string out = SPrintF(format, std::forward<Args>(args)...);
- fwrite(out.data(), out.size(), 1, stderr);
+ FPrintF(stderr, format, std::forward<Args>(args)...);
}
inline void FORCE_INLINE Debug(Environment* env,
@@ -49,7 +51,7 @@ inline void FORCE_INLINE Debug(Environment* env,
const char* message) {
if (!UNLIKELY(env->debug_enabled(cat)))
return;
- fprintf(stderr, "%s", message);
+ FPrintF(stderr, "%s", message);
}
template <typename... Args>