[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 <vegorov@google.com>
Reviewed-by: Martin Kustermann <kustermann@google.com>
Reviewed-by: Siva Annamalai <asiva@google.com>
Commit-Queue: Ryan Macnak <rmacnak@google.com>
diff --git a/runtime/vm/compiler/assembler/disassembler.cc b/runtime/vm/compiler/assembler/disassembler.cc
index 3037952..01312ca 100644
--- a/runtime/vm/compiler/assembler/disassembler.cc
+++ b/runtime/vm/compiler/assembler/disassembler.cc
@@ -198,7 +198,7 @@
}
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 cb74322..b43f894 100644
--- a/runtime/vm/compiler/assembler/disassembler.h
+++ b/runtime/vm/compiler/assembler/disassembler.h
@@ -33,7 +33,7 @@
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 a51753b..0899494 100644
--- a/runtime/vm/compiler/assembler/disassembler_kbc.cc
+++ b/runtime/vm/compiler/assembler/disassembler_kbc.cc
@@ -320,7 +320,7 @@
}
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 674a6b3..a59c3a0 100644
--- a/runtime/vm/compiler/frontend/constant_evaluator.cc
+++ b/runtime/vm/compiler/frontend/constant_evaluator.cc
@@ -146,7 +146,7 @@
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 ff94ef2..cb7dc87 100644
--- a/runtime/vm/compiler/frontend/kernel_translation_helper.h
+++ b/runtime/vm/compiler/frontend/kernel_translation_helper.h
@@ -156,17 +156,18 @@
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 7ab10b9..ae71c84 100644
--- a/runtime/vm/dwarf.cc
+++ b/runtime/vm/dwarf.cc
@@ -439,10 +439,10 @@
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 @@
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 b523663..cd68542 100644
--- a/runtime/vm/dwarf.h
+++ b/runtime/vm/dwarf.h
@@ -180,12 +180,12 @@
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 42848bb..c44a5f6 100644
--- a/runtime/vm/json_stream.h
+++ b/runtime/vm/json_stream.h
@@ -83,7 +83,8 @@
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 c18d6f5..b644884 100644
--- a/runtime/vm/log.h
+++ b/runtime/vm/log.h
@@ -22,7 +22,7 @@
#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 49ce2ea..6a926bb 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 717772c..4bd2ccd 100644
--- a/runtime/vm/service.cc
+++ b/runtime/vm/service.cc
@@ -2793,7 +2793,7 @@
}
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;
}
@@ -3714,7 +3714,7 @@
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 a470084..bb27436 100644
--- a/runtime/vm/timeline_analysis.h
+++ b/runtime/vm/timeline_analysis.h
@@ -77,7 +77,7 @@
void DiscoverThreads();
void FinalizeThreads();
- void SetError(const char* format, ...);
+ void SetError(const char* format, ...) PRINTF_ATTRIBUTE(2, 3);
Zone* zone_;
Isolate* isolate_;