Community
cancel
Showing results for 
Search instead for 
Did you mean: 
michaelmarcin
Beginner
46 Views

Bug in concurrent_vector documentation

Section 5.2 of the Tutorial (Open Source).pdf on the website contains the following code snippet.

void Append( concurrent_vector& vector, const char* string ) {
size_t n = strlen(string)+1;
memcpy( &vector[vector.grow_by(n)], string, n+1 );
}

Isn't this copying the null terminated string plus an additional byte to the vector?
0 Kudos
1 Reply
Andrey_Marochko
New Contributor III
46 Views

Thanks for catching and reporting the error! Though it looks like someone has already fixed it by rewriting the memcpy line in the following way

std::copy( string, string+n, vector.begin()+vector.grow_by(n) );

Not sure if this version has already been released, but at least it is what I see in our mainline at the moment. Anyway, thanks again, and don't hesitate posting other errors you may find (you evidently have a sharp eye), there is a good chance that they are still lying about nonfixedsmiley [:-)].

Reply