src: remove unnecessary c_str() conversions in diagnostic messages

PR-URL: https://github.com/nodejs/node/pull/61786
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Edy Silva <edigleyssonsilva@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
Reviewed-By: Stephen Belanger <admin@stephenbelanger.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Rafael Gonzaga <rafael.nunu@hotmail.com>
This commit is contained in:
Anna Henningsen authored and Antoine du Hamel committed 2026-04-08 23:53:04 +02:00
1 parent 1c2064c1f8
commit 6cda3d30c0
11 files changed
+55 -63

No files matched your search

+9 -9
View File
@@ -105,7 +105,7 @@ template <typename T>
std::vector<T> BlobDeserializer<Impl>::ReadVector() {
if (is_debug) {
std::string name = GetName<T>();
Debug("\nReadVector<%s>()(%d-byte)\n", name.c_str(), sizeof(T));
Debug("\nReadVector<%s>()(%d-byte)\n", name, sizeof(T));
}
size_t count = static_cast<size_t>(ReadArithmetic<size_t>());
if (count == 0) {
@@ -123,7 +123,7 @@ std::vector<T> BlobDeserializer<Impl>::ReadVector() {
if (is_debug) {
std::string str = std::is_arithmetic_v<T> ? "" : ToStr(result);
std::string name = GetName<T>();
Debug("ReadVector<%s>() read %s\n", name.c_str(), str.c_str());
Debug("ReadVector<%s>() read %s\n", name, str);
}
return result;
}
@@ -163,7 +163,7 @@ void BlobDeserializer<Impl>::ReadArithmetic(T* out, size_t count) {
DCHECK_GT(count, 0); // Should not read contents for vectors of size 0.
if (is_debug) {
std::string name = GetName<T>();
Debug("Read<%s>()(%d-byte), count=%d: ", name.c_str(), sizeof(T), count);
Debug("Read<%s>()(%d-byte), count=%d: ", name, sizeof(T), count);
}
size_t size = sizeof(T) * count;
@@ -172,7 +172,7 @@ void BlobDeserializer<Impl>::ReadArithmetic(T* out, size_t count) {
if (is_debug) {
std::string str =
"{ " + std::to_string(out[0]) + (count > 1 ? ", ... }" : " }");
Debug("%s, read %zu bytes\n", str.c_str(), size);
Debug("%s, read %zu bytes\n", str, size);
}
read_total += size;
}
@@ -240,10 +240,10 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) {
std::string name = GetName<T>();
Debug("\nAt 0x%x: WriteVector<%s>() (%d-byte), count=%d: %s\n",
sink.size(),
name.c_str(),
name,
sizeof(T),
data.size(),
str.c_str());
str);
}
size_t written_total = WriteArithmetic<size_t>(data.size());
@@ -259,7 +259,7 @@ size_t BlobSerializer<Impl>::WriteVector(const std::vector<T>& data) {
if (is_debug) {
std::string name = GetName<T>();
Debug("WriteVector<%s>() wrote %d bytes\n", name.c_str(), written_total);
Debug("WriteVector<%s>() wrote %d bytes\n", name, written_total);
}
return written_total;
@@ -319,10 +319,10 @@ size_t BlobSerializer<Impl>::WriteArithmetic(const T* data, size_t count) {
std::string name = GetName<T>();
Debug("At 0x%x: Write<%s>() (%zu-byte), count=%zu: %s",
sink.size(),
name.c_str(),
name,
sizeof(T),
count,
str.c_str());
str);
}
size_t size = sizeof(T) * count;
+2 -2
View File
@@ -265,8 +265,8 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(Local<String> code,
if (!relative_path.empty()) {
file_path = relative_path;
Debug("[compile cache] using relative path %s from %s\n",
file_path.c_str(),
compile_cache_dir_.c_str());
file_path,
compile_cache_dir_);
}
}
uint32_t key = GetCacheKey(file_path, type);
+1 -1
View File
@@ -2181,7 +2181,7 @@ size_t Environment::NearHeapLimitCallback(void* data,
env->RemoveHeapSnapshotNearHeapLimitCallback(0);
}
FPrintF(stderr, "Wrote snapshot to %s\n", filename.c_str());
FPrintF(stderr, "Wrote snapshot to %s\n", filename);
// Tell V8 to reset the heap limit once the heap usage falls down to
// 95% of the initial limit.
env->isolate()->AutomaticallyRestoreInitialHeapLimit(0.95);
+1 -1
View File
@@ -66,7 +66,7 @@ uint64_t V8ProfilerConnection::DispatchMessage(const char* method,
Debug(env(),
DebugCategory::INSPECTOR_PROFILER,
"Dispatching message %s\n",
message.c_str());
message);
session_->Dispatch(StringView(message_data, message.length()));
return id;
}
+1 -1
View File
@@ -559,7 +559,7 @@ bool BuiltinLoader::CompileAllBuiltinsAndCopyCodeCache(
if (bootstrapCatch.HasCaught()) {
per_process::Debug(DebugCategory::CODE_CACHE,
"Failed to compile code cache for %s\n",
id.data());
id);
all_succeeded = false;
PrintCaughtException(context->GetIsolate(), context, bootstrapCatch);
} else {
+14 -18
View File
@@ -48,7 +48,7 @@ ParseResult ConfigReader::ProcessOptionValue(
case options_parser::OptionType::kBoolean: {
bool result;
if (option_value->get_bool().get(result)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
@@ -74,13 +74,13 @@ ParseResult ConfigReader::ProcessOptionValue(
std::vector<std::string> result;
simdjson::ondemand::array raw_imports;
if (option_value->get_array().get(raw_imports)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
for (auto raw_import : raw_imports) {
std::string_view import;
if (raw_import.get_string(import)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
output->push_back(option_name + "=" + std::string(import));
@@ -90,14 +90,14 @@ ParseResult ConfigReader::ProcessOptionValue(
case simdjson::ondemand::json_type::string: {
std::string result;
if (option_value->get_string(result)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
output->push_back(option_name + "=" + result);
break;
}
default:
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
break;
@@ -105,7 +105,7 @@ ParseResult ConfigReader::ProcessOptionValue(
case options_parser::OptionType::kString: {
std::string result;
if (option_value->get_string(result)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
output->push_back(option_name + "=" + result);
@@ -114,7 +114,7 @@ ParseResult ConfigReader::ProcessOptionValue(
case options_parser::OptionType::kInteger: {
int64_t result;
if (option_value->get_int64().get(result)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
output->push_back(option_name + "=" + std::to_string(result));
@@ -124,22 +124,19 @@ ParseResult ConfigReader::ProcessOptionValue(
case options_parser::OptionType::kUInteger: {
uint64_t result;
if (option_value->get_uint64().get(result)) {
FPrintF(stderr, "Invalid value for %s\n", option_name.c_str());
FPrintF(stderr, "Invalid value for %s\n", option_name);
return ParseResult::InvalidContent;
}
output->push_back(option_name + "=" + std::to_string(result));
break;
}
case options_parser::OptionType::kNoOp: {
FPrintF(stderr,
"No-op flag %s is currently not supported\n",
option_name.c_str());
FPrintF(
stderr, "No-op flag %s is currently not supported\n", option_name);
return ParseResult::InvalidContent;
}
case options_parser::OptionType::kV8Option: {
FPrintF(stderr,
"V8 flag %s is currently not supported\n",
option_name.c_str());
FPrintF(stderr, "V8 flag %s is currently not supported\n", option_name);
return ParseResult::InvalidContent;
}
default:
@@ -187,8 +184,7 @@ ParseResult ConfigReader::ParseOptions(
if (option != options_map.end()) {
// If the option has already been set, return an error
if (unique_options->contains(option->first)) {
FPrintF(
stderr, "Option %s is already defined\n", option->first.c_str());
FPrintF(stderr, "Option %s is already defined\n", option->first);
return ParseResult::InvalidContent;
}
// Add the option to the unique set to prevent duplicates
@@ -204,7 +200,7 @@ ParseResult ConfigReader::ParseOptions(
FPrintF(stderr,
"Unknown or not allowed option %s for namespace %s\n",
option_key,
namespace_name.c_str());
namespace_name);
return ParseResult::InvalidContent;
}
}
@@ -277,7 +273,7 @@ ParseResult ConfigReader::ParseConfig(const std::string_view& config_path) {
if (field_error) {
FPrintF(stderr,
"\"%s\" value unexpected for %s (should be an object)\n",
namespace_name.c_str(),
namespace_name,
config_path.data());
return ParseResult::InvalidContent;
}
+2 -4
View File
@@ -156,10 +156,8 @@ static std::string GetErrorSource(Isolate* isolate,
end -= script_start;
}
std::string buf = SPrintF("%s:%i\n%s\n",
filename_string,
linenum,
sourceline.c_str());
std::string buf =
SPrintF("%s:%i\n%s\n", filename_string, linenum, sourceline);
CHECK_GT(buf.size(), 0);
*added_exception_line = true;
+1 -1
View File
@@ -642,7 +642,7 @@ int BuildAssets(const std::unordered_map<std::string, std::string>& config,
int r = ReadFileSync(&blob, path.c_str());
if (r != 0) {
const char* err = uv_strerror(r);
FPrintF(stderr, "Cannot read asset %s: %s\n", path.c_str(), err);
FPrintF(stderr, "Cannot read asset %s: %s\n", path, err);
return r;
}
assets->emplace(key, std::move(blob));
+21 -21
View File
@@ -225,7 +225,7 @@ builtins::CodeCacheInfo SnapshotDeserializer::Read() {
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<builtins::CodeCacheInfo>() %s\n", str.c_str());
Debug("Read<builtins::CodeCacheInfo>() %s\n", str);
}
return result;
}
@@ -234,7 +234,7 @@ template <>
size_t SnapshotSerializer::Write(const builtins::CodeCacheInfo& info) {
Debug("\nWrite<builtins::CodeCacheInfo>() id = %s"
", length=%d\n",
info.id.c_str(),
info.id,
info.data.length);
size_t written_total = WriteString(info.id);
@@ -263,7 +263,7 @@ PropInfo SnapshotDeserializer::Read() {
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<PropInfo>() %s\n", str.c_str());
Debug("Read<PropInfo>() %s\n", str);
}
return result;
@@ -273,7 +273,7 @@ template <>
size_t SnapshotSerializer::Write(const PropInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<PropInfo>() %s\n", str.c_str());
Debug("Write<PropInfo>() %s\n", str);
}
size_t written_total = WriteString(data.name);
@@ -305,7 +305,7 @@ AsyncHooks::SerializeInfo SnapshotDeserializer::Read() {
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<AsyncHooks::SerializeInfo>() %s\n", str.c_str());
Debug("Read<AsyncHooks::SerializeInfo>() %s\n", str);
}
return result;
@@ -314,7 +314,7 @@ template <>
size_t SnapshotSerializer::Write(const AsyncHooks::SerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<AsyncHooks::SerializeInfo>() %s\n", str.c_str());
Debug("Write<AsyncHooks::SerializeInfo>() %s\n", str);
}
size_t written_total =
@@ -341,7 +341,7 @@ TickInfo::SerializeInfo SnapshotDeserializer::Read() {
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<TickInfo::SerializeInfo>() %s\n", str.c_str());
Debug("Read<TickInfo::SerializeInfo>() %s\n", str);
}
return result;
@@ -351,7 +351,7 @@ template <>
size_t SnapshotSerializer::Write(const TickInfo::SerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<TickInfo::SerializeInfo>() %s\n", str.c_str());
Debug("Write<TickInfo::SerializeInfo>() %s\n", str);
}
size_t written_total = WriteArithmetic<AliasedBufferIndex>(data.fields);
@@ -370,7 +370,7 @@ ImmediateInfo::SerializeInfo SnapshotDeserializer::Read() {
result.fields = ReadArithmetic<AliasedBufferIndex>();
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<ImmediateInfo::SerializeInfo>() %s\n", str.c_str());
Debug("Read<ImmediateInfo::SerializeInfo>() %s\n", str);
}
return result;
}
@@ -379,7 +379,7 @@ template <>
size_t SnapshotSerializer::Write(const ImmediateInfo::SerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<ImmediateInfo::SerializeInfo>() %s\n", str.c_str());
Debug("Write<ImmediateInfo::SerializeInfo>() %s\n", str);
}
size_t written_total = WriteArithmetic<AliasedBufferIndex>(data.fields);
@@ -403,7 +403,7 @@ performance::PerformanceState::SerializeInfo SnapshotDeserializer::Read() {
result.observers = ReadArithmetic<AliasedBufferIndex>();
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<PerformanceState::SerializeInfo>() %s\n", str.c_str());
Debug("Read<PerformanceState::SerializeInfo>() %s\n", str);
}
return result;
}
@@ -413,7 +413,7 @@ size_t SnapshotSerializer::Write(
const performance::PerformanceState::SerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<PerformanceState::SerializeInfo>() %s\n", str.c_str());
Debug("Write<PerformanceState::SerializeInfo>() %s\n", str);
}
size_t written_total = WriteArithmetic<AliasedBufferIndex>(data.root);
@@ -439,7 +439,7 @@ IsolateDataSerializeInfo SnapshotDeserializer::Read() {
result.template_values = ReadVector<PropInfo>();
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<IsolateDataSerializeInfo>() %s\n", str.c_str());
Debug("Read<IsolateDataSerializeInfo>() %s\n", str);
}
return result;
}
@@ -448,7 +448,7 @@ template <>
size_t SnapshotSerializer::Write(const IsolateDataSerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("Write<IsolateDataSerializeInfo>() %s\n", str.c_str());
Debug("Write<IsolateDataSerializeInfo>() %s\n", str);
}
size_t written_total = WriteVector<SnapshotIndex>(data.primitive_values);
@@ -473,7 +473,7 @@ template <>
size_t SnapshotSerializer::Write(const RealmSerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("\nWrite<RealmSerializeInfo>() %s\n", str.c_str());
Debug("\nWrite<RealmSerializeInfo>() %s\n", str);
}
// Use += here to ensure order of evaluation.
@@ -507,7 +507,7 @@ template <>
size_t SnapshotSerializer::Write(const EnvSerializeInfo& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("\nWrite<EnvSerializeInfo>() %s\n", str.c_str());
Debug("\nWrite<EnvSerializeInfo>() %s\n", str);
}
// Use += here to ensure order of evaluation.
@@ -549,7 +549,7 @@ SnapshotMetadata SnapshotDeserializer::Read() {
if (is_debug) {
std::string str = ToStr(result);
Debug("Read<SnapshotMetadata>() %s\n", str.c_str());
Debug("Read<SnapshotMetadata>() %s\n", str);
}
return result;
}
@@ -558,7 +558,7 @@ template <>
size_t SnapshotSerializer::Write(const SnapshotMetadata& data) {
if (is_debug) {
std::string str = ToStr(data);
Debug("\nWrite<SnapshotMetadata>() %s\n", str.c_str());
Debug("\nWrite<SnapshotMetadata>() %s\n", str);
}
size_t written_total = 0;
// We need the Node.js version, platform and arch to match because
@@ -566,7 +566,7 @@ size_t SnapshotSerializer::Write(const SnapshotMetadata& data) {
// can be changed in semver-patches.
Debug("Write snapshot type %d\n", static_cast<uint8_t>(data.type));
written_total += WriteArithmetic<uint8_t>(static_cast<uint8_t>(data.type));
Debug("Write Node.js version %s\n", data.node_version.c_str());
Debug("Write Node.js version %s\n", data.node_version);
written_total += WriteString(data.node_version);
Debug("Write Node.js arch %s\n", data.node_arch);
written_total += WriteString(data.node_arch);
@@ -1130,8 +1130,8 @@ ExitCode BuildCodeCacheFromSnapshot(SnapshotData* out,
std::string size_str = FormatSize(item.data.length);
per_process::Debug(DebugCategory::MKSNAPSHOT,
"Generated code cache for %d: %s\n",
item.id.c_str(),
size_str.c_str());
item.id,
size_str);
}
}
return ExitCode::kNoFailure;
+1 -1
View File
@@ -886,7 +886,7 @@ std::optional<std::string> ValidateDatabasePath(Environment* env,
THROW_ERR_INVALID_ARG_TYPE(env->isolate(),
"The \"%s\" argument must be a string, "
"Uint8Array, or URL without null bytes.",
field_name.c_str());
field_name);
return std::nullopt;
}
+2 -4
View File
@@ -102,10 +102,8 @@ void PrintTree(const node::permission::FSPermission::RadixTree::Node* node,
}
}
node::per_process::Debug(node::DebugCategory::PERMISSION_MODEL,
"%s%s\n",
indent.c_str(),
node->prefix.c_str());
node::per_process::Debug(
node::DebugCategory::PERMISSION_MODEL, "%s%s\n", indent, node->prefix);
}
if (node->children.size() > 0) {