Skip to content

SmallVector::insert(iterator I, InTy From, InTy To) is broken #4232

@llvmbot

Description

@llvmbot
Bugzilla Link 3860
Resolution FIXED
Resolved on Nov 07, 2018 00:17
Version 2.5
OS Windows NT
Reporter LLVM Bugzilla Contributor

Extended Description

SmallVector insert triggers a debug validation failure with MSVC++, because it passes an invalid range to std::copy. Specifially,

// Copy the existing elements that get replaced.
std::copy(I, OldEnd-NumToInsert, I+NumToInsert);

in

template
iterator insert(iterator I, ItTy From, ItTy To)

passes an I > (OldEnd-NumToInsert) to std::copy, which would result in memory corruption at best.

Simple test case to trigger it.
const char * t = "Cannot load string";
// 01234567890123456789
const char * other = ">> \n";
// 012345
SmallVector<char, 16> test (t, t + 18);
SmallVector<char, 16>::iterator it = test.end ();
--it;

test.insert (it, other, other + 4);

Actually, any insert at begin () + N, with N 3..17 fails in that case, including at the end.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugzillaIssues migrated from bugzilla

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions