From a6518386520af63764ad40dde3b53e5e160b9bff Mon Sep 17 00:00:00 2001 From: Ryan Macnak Date: Thu, 1 Nov 2018 16:37:22 +0000 Subject: [PATCH] [vm] Fix misc printf format bugs. Bug: https://github.com/dart-lang/sdk/issues/35009 Change-Id: I6b509e1eb8e76e07f60a086c67358d65d2a1fae4 Reviewed-on: https://dart-review.googlesource.com/c/82460 Reviewed-by: Vyacheslav Egorov Reviewed-by: Martin Kustermann Reviewed-by: Siva Annamalai Commit-Queue: Ryan Macnak --- runtime/vm/compiler/assembler/disassembler.cc | 2 +- runtime/vm/compiler/assembler/disassembler.h | 2 +- runtime/vm/compiler/assembler/disassembler_kbc.cc | 2 +- runtime/vm/compiler/frontend/constant_evaluator.cc | 2 +- runtime/vm/compiler/frontend/kernel_translation_helper.h | 9 +++++---- runtime/vm/dwarf.cc | 6 +++--- runtime/vm/dwarf.h | 8 ++++---- runtime/vm/json_stream.h | 3 ++- runtime/vm/log.h | 2 +- runtime/vm/log_test.cc | 2 ++ runtime/vm/service.cc | 4 ++-- runtime/vm/timeline_analysis.h | 2 +- 12 files changed, 24 insertions(+), 20 deletions(-) diff --git a/runtime/vm/compiler/assembler/disassembler.cc b/runtime/vm/compiler/assembler/disassembler.cc index 1561a11557f..28dca3ffe8c 100644 --- a/runtime/vm/compiler/assembler/disassembler.cc +++ b/runtime/vm/compiler/assembler/disassembler.cc @@ -198,7 +198,7 @@ void Disassembler::Disassemble(uword start, } if (!first) { f.Print("]\n"); - formatter->Print(str); + formatter->Print("%s", str); } } int instruction_length; diff --git a/runtime/vm/compiler/assembler/disassembler.h b/runtime/vm/compiler/assembler/disassembler.h index cb743227dd5..b43f8946315 100644 --- a/runtime/vm/compiler/assembler/disassembler.h +++ b/runtime/vm/compiler/assembler/disassembler.h @@ -33,7 +33,7 @@ class DisassemblyFormatter { uword pc) = 0; // Print a formatted message. - virtual void Print(const char* format, ...) = 0; + virtual void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3) = 0; }; // Basic disassembly formatter that outputs the disassembled instruction diff --git a/runtime/vm/compiler/assembler/disassembler_kbc.cc b/runtime/vm/compiler/assembler/disassembler_kbc.cc index 00f892d7b64..a536dcd4557 100644 --- a/runtime/vm/compiler/assembler/disassembler_kbc.cc +++ b/runtime/vm/compiler/assembler/disassembler_kbc.cc @@ -317,7 +317,7 @@ void KernelBytecodeDisassembler::Disassemble(uword start, } if (!first) { f.Print("]\n"); - formatter->Print(str); + formatter->Print("%s", str); } } int instruction_length; diff --git a/runtime/vm/compiler/frontend/constant_evaluator.cc b/runtime/vm/compiler/frontend/constant_evaluator.cc index ce3a68bba37..f1c36dcc4c8 100644 --- a/runtime/vm/compiler/frontend/constant_evaluator.cc +++ b/runtime/vm/compiler/frontend/constant_evaluator.cc @@ -146,7 +146,7 @@ RawInstance* ConstantEvaluator::EvaluateExpression(intptr_t offset, default: H.ReportError( script_, TokenPosition::kNoSource, - "Not a constant expression: unexpected kernel tag %s (%" Pd ")", + "Not a constant expression: unexpected kernel tag %s (%d)", Reader::TagName(tag), tag); } diff --git a/runtime/vm/compiler/frontend/kernel_translation_helper.h b/runtime/vm/compiler/frontend/kernel_translation_helper.h index fe606dfd57e..f19ccad4e98 100644 --- a/runtime/vm/compiler/frontend/kernel_translation_helper.h +++ b/runtime/vm/compiler/frontend/kernel_translation_helper.h @@ -154,17 +154,18 @@ class TranslationHelper { Type& GetCanonicalType(const Class& klass); - void ReportError(const char* format, ...); + void ReportError(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); void ReportError(const Script& script, const TokenPosition position, const char* format, - ...); - void ReportError(const Error& prev_error, const char* format, ...); + ...) PRINTF_ATTRIBUTE(4, 5); + void ReportError(const Error& prev_error, const char* format, ...) + PRINTF_ATTRIBUTE(3, 4); void ReportError(const Error& prev_error, const Script& script, const TokenPosition position, const char* format, - ...); + ...) PRINTF_ATTRIBUTE(5, 6); private: // This will mangle [name_to_modify] if necessary and make the result a symbol diff --git a/runtime/vm/dwarf.cc b/runtime/vm/dwarf.cc index 7ab10b9927a..ae71c8436ed 100644 --- a/runtime/vm/dwarf.cc +++ b/runtime/vm/dwarf.cc @@ -439,10 +439,10 @@ void Dwarf::WriteInliningNode(InliningNode* node, Print("Ltemp%" Pd " = .Lfunc%" Pd " - .Ldebug_info\n", temp, function_index); Print(".4byte Ltemp%" Pd "\n", temp); // DW_AT_low_pc - Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", root_code_index, + Print(FORM_ADDR " .Lcode%" Pd " + %d\n", root_code_index, node->start_pc_offset); // DW_AT_high_pc - Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", root_code_index, + Print(FORM_ADDR " .Lcode%" Pd " + %d\n", root_code_index, node->end_pc_offset); // DW_AT_call_file uleb128(file); @@ -596,7 +596,7 @@ void Dwarf::WriteLines() { u1(0); // This is an extended opcode u1(1 + sizeof(void*)); // that is 5 or 9 bytes long u1(DW_LNE_set_address); - Print(FORM_ADDR " .Lcode%" Pd " + %" Pd "\n", i, current_pc_offset); + Print(FORM_ADDR " .Lcode%" Pd " + %d\n", i, current_pc_offset); } else { u1(DW_LNS_advance_pc); Print(".uleb128 .Lcode%" Pd " - .Lcode%" Pd " + %" Pd "\n", i, diff --git a/runtime/vm/dwarf.h b/runtime/vm/dwarf.h index b523663c631..cd685420cc1 100644 --- a/runtime/vm/dwarf.h +++ b/runtime/vm/dwarf.h @@ -180,12 +180,12 @@ class Dwarf : public ZoneAllocated { kInlinedFunction, }; - void Print(const char* format, ...); + void Print(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); void sleb128(intptr_t value) { Print(".sleb128 %" Pd "\n", value); } void uleb128(uintptr_t value) { Print(".uleb128 %" Pd "\n", value); } - void u1(uint8_t value) { Print(".byte %" Pd "\n", value); } - void u2(uint16_t value) { Print(".2byte %" Pd "\n", value); } - void u4(uint32_t value) { Print(".4byte %" Pd "\n", value); } + void u1(uint8_t value) { Print(".byte %d\n", value); } + void u2(uint16_t value) { Print(".2byte %d\n", value); } + void u4(uint32_t value) { Print(".4byte %d\n", value); } void WriteAbbreviations(); void WriteCompilationUnit(); diff --git a/runtime/vm/json_stream.h b/runtime/vm/json_stream.h index 42848bb4a3e..c44a5f615c2 100644 --- a/runtime/vm/json_stream.h +++ b/runtime/vm/json_stream.h @@ -83,7 +83,8 @@ class JSONStream : ValueObject { bool parameters_are_dart_objects = false); void SetupError(); - void PrintError(intptr_t code, const char* details_format, ...); + void PrintError(intptr_t code, const char* details_format, ...) + PRINTF_ATTRIBUTE(3, 4); void PostReply(); diff --git a/runtime/vm/log.h b/runtime/vm/log.h index c18d6f58673..b644884aa25 100644 --- a/runtime/vm/log.h +++ b/runtime/vm/log.h @@ -22,7 +22,7 @@ class Thread; #define THR_VPrint(format, args) Log::Current()->VPrint(format, args) -typedef void (*LogPrinter)(const char* str, ...); +typedef void (*LogPrinter)(const char* str, ...) PRINTF_ATTRIBUTE(1, 2); class Log { public: diff --git a/runtime/vm/log_test.cc b/runtime/vm/log_test.cc index 49ce2ea373a..6a926bbe253 100644 --- a/runtime/vm/log_test.cc +++ b/runtime/vm/log_test.cc @@ -17,6 +17,8 @@ namespace dart { static const char* test_output_ = NULL; + +PRINTF_ATTRIBUTE(1, 2) static void TestPrinter(const char* format, ...) { // Measure. va_list args; diff --git a/runtime/vm/service.cc b/runtime/vm/service.cc index 81fa99ea773..2959fc271bd 100644 --- a/runtime/vm/service.cc +++ b/runtime/vm/service.cc @@ -2729,7 +2729,7 @@ static bool CompileExpression(Thread* thread, JSONStream* js) { js->LookupParam("libraryUri"), js->LookupParam("klass"), is_static); if (compilation_result.status != Dart_KernelCompilationStatus_Ok) { - js->PrintError(kExpressionCompilationError, compilation_result.error); + js->PrintError(kExpressionCompilationError, "%s", compilation_result.error); free(compilation_result.error); return true; } @@ -3627,7 +3627,7 @@ static bool Resume(Thread* thread, JSONStream* js) { const char* error = NULL; if (!isolate->debugger()->SetResumeAction(step, frame_index, &error)) { - js->PrintError(kCannotResume, error); + js->PrintError(kCannotResume, "%s", error); return true; } isolate->SetResumeRequest(); diff --git a/runtime/vm/timeline_analysis.h b/runtime/vm/timeline_analysis.h index a4700843fb8..bb274366e91 100644 --- a/runtime/vm/timeline_analysis.h +++ b/runtime/vm/timeline_analysis.h @@ -77,7 +77,7 @@ class TimelineAnalysis : public ValueObject { void DiscoverThreads(); void FinalizeThreads(); - void SetError(const char* format, ...); + void SetError(const char* format, ...) PRINTF_ATTRIBUTE(2, 3); Zone* zone_; Isolate* isolate_;