Make sure vectors are not empty when calling back().

This commit is contained in:
Stefano Sanfilippo 2015-03-09 13:35:33 +01:00
parent 0c3702ea34
commit 12ea83a4af
2 changed files with 6 additions and 2 deletions

View File

@ -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()) {

View File

@ -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<Expression> 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<FunArg> 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));