From 0428717bb30877bb08fd70300af82f950f405dee Mon Sep 17 00:00:00 2001 From: Anna Henningsen Date: Thu, 12 Feb 2026 11:36:22 +0100 Subject: [PATCH] src: remove unnecessary `c_str()` conversions in diagnostic messages --- src/blob_serializer_deserializer-inl.h | 18 +++++------ src/compile_cache.cc | 4 +-- src/env.cc | 2 +- src/inspector_profiler.cc | 2 +- src/node_builtins.cc | 2 +- src/node_config_file.cc | 32 +++++++++----------- src/node_errors.cc | 6 ++-- src/node_sea.cc | 2 +- src/node_snapshotable.cc | 42 +++++++++++++------------- src/node_sqlite.cc | 2 +- src/permission/fs_permission.cc | 6 ++-- 11 files changed, 55 insertions(+), 63 deletions(-) diff --git a/src/blob_serializer_deserializer-inl.h b/src/blob_serializer_deserializer-inl.h index 7f5a3860b5b7e5..fa258dbe814459 100644 --- a/src/blob_serializer_deserializer-inl.h +++ b/src/blob_serializer_deserializer-inl.h @@ -105,7 +105,7 @@ template std::vector BlobDeserializer::ReadVector() { if (is_debug) { std::string name = GetName(); - 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(ReadArithmetic()); if (count == 0) { @@ -123,7 +123,7 @@ std::vector BlobDeserializer::ReadVector() { if (is_debug) { std::string str = std::is_arithmetic_v ? "" : ToStr(result); std::string name = GetName(); - 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::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(); - 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::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::WriteVector(const std::vector& data) { std::string name = GetName(); 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(data.size()); @@ -259,7 +259,7 @@ size_t BlobSerializer::WriteVector(const std::vector& data) { if (is_debug) { std::string name = GetName(); - 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::WriteArithmetic(const T* data, size_t count) { std::string name = GetName(); 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; diff --git a/src/compile_cache.cc b/src/compile_cache.cc index 0920747012f072..6b054db1ccc2e8 100644 --- a/src/compile_cache.cc +++ b/src/compile_cache.cc @@ -265,8 +265,8 @@ CompileCacheEntry* CompileCacheHandler::GetOrInsert(Local 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); diff --git a/src/env.cc b/src/env.cc index 6df324e04316c5..b94cb9784b0791 100644 --- a/src/env.cc +++ b/src/env.cc @@ -2200,7 +2200,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); diff --git a/src/inspector_profiler.cc b/src/inspector_profiler.cc index dd57c779595c80..28653a3939daef 100644 --- a/src/inspector_profiler.cc +++ b/src/inspector_profiler.cc @@ -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; } diff --git a/src/node_builtins.cc b/src/node_builtins.cc index 1ebefba4b8bb6c..5ef8d06933700c 100644 --- a/src/node_builtins.cc +++ b/src/node_builtins.cc @@ -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(Isolate::GetCurrent(), context, bootstrapCatch); } else { diff --git a/src/node_config_file.cc b/src/node_config_file.cc index 4205a3cee7e52a..ce89a51b7b97d3 100644 --- a/src/node_config_file.cc +++ b/src/node_config_file.cc @@ -49,7 +49,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; } @@ -75,13 +75,13 @@ ParseResult ConfigReader::ProcessOptionValue( std::vector 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)); @@ -91,14 +91,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; @@ -106,7 +106,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); @@ -115,7 +115,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)); @@ -125,22 +125,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: @@ -189,8 +186,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 @@ -206,7 +202,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; } } @@ -303,7 +299,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; } diff --git a/src/node_errors.cc b/src/node_errors.cc index 30753ec2b07cd3..23ca0bc50f68c6 100644 --- a/src/node_errors.cc +++ b/src/node_errors.cc @@ -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; diff --git a/src/node_sea.cc b/src/node_sea.cc index bffdc72d1d1791..bb566ec2155bb6 100644 --- a/src/node_sea.cc +++ b/src/node_sea.cc @@ -639,7 +639,7 @@ int BuildAssets(const std::unordered_map& 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)); diff --git a/src/node_snapshotable.cc b/src/node_snapshotable.cc index 5f39029563eecb..30df4f53abc446 100644 --- a/src/node_snapshotable.cc +++ b/src/node_snapshotable.cc @@ -225,7 +225,7 @@ builtins::CodeCacheInfo SnapshotDeserializer::Read() { if (is_debug) { std::string str = ToStr(result); - Debug("Read() %s\n", str.c_str()); + Debug("Read() %s\n", str); } return result; } @@ -234,7 +234,7 @@ template <> size_t SnapshotSerializer::Write(const builtins::CodeCacheInfo& info) { Debug("\nWrite() 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() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %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() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %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() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %s\n", str); } size_t written_total = WriteArithmetic(data.fields); @@ -370,7 +370,7 @@ ImmediateInfo::SerializeInfo SnapshotDeserializer::Read() { result.fields = ReadArithmetic(); if (is_debug) { std::string str = ToStr(result); - Debug("Read() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %s\n", str); } size_t written_total = WriteArithmetic(data.fields); @@ -403,7 +403,7 @@ performance::PerformanceState::SerializeInfo SnapshotDeserializer::Read() { result.observers = ReadArithmetic(); if (is_debug) { std::string str = ToStr(result); - Debug("Read() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %s\n", str); } size_t written_total = WriteArithmetic(data.root); @@ -439,7 +439,7 @@ IsolateDataSerializeInfo SnapshotDeserializer::Read() { result.template_values = ReadVector(); if (is_debug) { std::string str = ToStr(result); - Debug("Read() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("Write() %s\n", str); } size_t written_total = WriteVector(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() %s\n", str.c_str()); + Debug("\nWrite() %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() %s\n", str.c_str()); + Debug("\nWrite() %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() %s\n", str.c_str()); + Debug("Read() %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() %s\n", str.c_str()); + Debug("\nWrite() %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(data.type)); written_total += WriteArithmetic(static_cast(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; diff --git a/src/node_sqlite.cc b/src/node_sqlite.cc index 3f4749286406e0..fb229e19fd6aef 100644 --- a/src/node_sqlite.cc +++ b/src/node_sqlite.cc @@ -886,7 +886,7 @@ std::optional 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; } diff --git a/src/permission/fs_permission.cc b/src/permission/fs_permission.cc index 63dfc25f536c7c..3b817c5bcdce75 100644 --- a/src/permission/fs_permission.cc +++ b/src/permission/fs_permission.cc @@ -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) {