Skip to content

Commit

Permalink
[vm] Fix misc printf format bugs.
Browse files Browse the repository at this point in the history
Bug: dart-lang/sdk#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>
  • Loading branch information
rmacnak-google authored and commit-bot@chromium.org committed Nov 1, 2018
1 parent 97940e7 commit a651838
Show file tree
Hide file tree
Showing 12 changed files with 24 additions and 20 deletions.
2 changes: 1 addition & 1 deletion runtime/vm/compiler/assembler/disassembler.cc
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ void Disassembler::Disassemble(uword start,
}
if (!first) {
f.Print("]\n");
formatter->Print(str);
formatter->Print("%s", str);
}
}
int instruction_length;
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/compiler/assembler/disassembler.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/compiler/assembler/disassembler_kbc.cc
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ void KernelBytecodeDisassembler::Disassemble(uword start,
}
if (!first) {
f.Print("]\n");
formatter->Print(str);
formatter->Print("%s", str);
}
}
int instruction_length;
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/compiler/frontend/constant_evaluator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down
9 changes: 5 additions & 4 deletions runtime/vm/compiler/frontend/kernel_translation_helper.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 3 additions & 3 deletions runtime/vm/dwarf.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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,
Expand Down
8 changes: 4 additions & 4 deletions runtime/vm/dwarf.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
3 changes: 2 additions & 1 deletion runtime/vm/json_stream.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/log.h
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 2 additions & 0 deletions runtime/vm/log_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions runtime/vm/service.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion runtime/vm/timeline_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -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_;
Expand Down

0 comments on commit a651838

Please sign in to comment.