From 12ea83a4afcc21286574951031eb4426d9d05457 Mon Sep 17 00:00:00 2001 From: Stefano Sanfilippo Date: Mon, 9 Mar 2015 13:35:33 +0100 Subject: [PATCH] Make sure vectors are not empty when calling back(). --- BitcodeEmitter.cpp | 1 + CppEmitter.cpp | 7 +++++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/BitcodeEmitter.cpp b/BitcodeEmitter.cpp index b468ae2..7b0d309 100644 --- a/BitcodeEmitter.cpp +++ b/BitcodeEmitter.cpp @@ -460,6 +460,7 @@ bool BitcodeEmitter::emit(Branch const& node) { getGlobalContext(), "endif" ); + assert(!body.getCases().empty()); BranchCase const& last = body.getCases().back(); for (BranchCase const& cas: body.getCases()) { diff --git a/CppEmitter.cpp b/CppEmitter.cpp index b708874..24de662 100644 --- a/CppEmitter.cpp +++ b/CppEmitter.cpp @@ -201,7 +201,7 @@ bool CppEmitter::emit(Branch const& branch) { stream << "if ("; GUARDED(var.emit(this)); - if (body.getCases().size() > 0) { + if (!body.getCases().empty()) { BranchCase const& last = body.getCases().back(); for (BranchCase const& cas: body.getCases()) { emitBranchCase(cas); @@ -236,6 +236,8 @@ bool CppEmitter::emit(Assignment const& assignment) { bool CppEmitter::emitFunctionArglist(PointerList const& args) { + if (args.empty()) return stream; + Expression const& last = args.back(); for (Expression const& arg: args) { GUARDED(arg.emit(this)); @@ -297,8 +299,9 @@ std::ostream& operator<<(std::ostream &stream, Type const& type) { } bool CppEmitter::emitFunctionParams(PointerList const& funargs) { - FunArg const& last = funargs.back(); + if (funargs.empty()) return stream; + FunArg const& last = funargs.back(); for (FunArg const& funarg: funargs) { stream << funarg.getType() << (funarg.isPointer()? "* ": " "); GUARDED(funarg.getName().emit(this));