Bug 18097 - ConcurrentStack<T>.PushRange() does not set the collection size correctly
Summary: ConcurrentStack<T>.PushRange() does not set the collection size correctly
Status: RESOLVED FIXED
Alias: None
Product: Class Libraries
Classification: Mono
Component: mscorlib ()
Version: 3.2.x
Hardware: PC Linux
: --- normal
Target Milestone: Untriaged
Assignee: Bugzilla
URL:
Depends on:
Blocks:
 
Reported: 2014-02-28 12:41 UTC by Craig Minihan
Modified: 2014-05-29 09:39 UTC (History)
2 users (show)

Tags:
Is this bug a regression?: ---
Last known good build:

Notice (2018-05-24): bugzilla.xamarin.com is now in read-only mode.

Please join us on Visual Studio Developer Community and in the Xamarin and Mono organizations on GitHub to continue tracking issues. Bugzilla will remain available for reference in read-only mode. We will continue to work on open Bugzilla bugs, copy them to the new locations as needed for follow-up, and add the new items under Related Links.

Our sincere thanks to everyone who has contributed on this bug tracker over the years. Thanks also for your understanding as we make these adjustments and improvements for the future.


Please create a new report on GitHub or Developer Community with your current version information, steps to reproduce, and relevant error messages or log files if you are hitting an issue that looks similar to this resolved bug and you do not yet see a matching new report.

Related Links:
Status:
RESOLVED FIXED

Description Craig Minihan 2014-02-28 12:41:59 UTC
In: System.Collections.Concurrent.ConcurrentStack<T>.PushRange(T[] items, int startIndex, int count)

The collection size is not increased by this call. The last line:

Interlocked.Add (ref count, count);
Should be:
Interlocked.Add (ref this.count, count);

Count is a member and a parameter in this method. The Interlocked.Add() is adding to the parameter not the method instance.

To replicate:
var stack = new ConcurrentStack<int>();
var data = new int[10];
stack.PushRange(data); // calls PushRange(T[] items, int startIndex, int count)
Console.WriteLine("Stack size is: {0}, should be {1}", stack.Count, data.Length);
Comment 1 Craig Minihan 2014-02-28 12:54:59 UTC
Fix make in pull request #928 on GitHub.
Comment 2 Craig Minihan 2014-03-05 07:45:32 UTC
Correction: fix in pull #931
Comment 3 Craig Minihan 2014-03-25 20:12:17 UTC
Merged into master in commit: 66aa46557bcafb3e49ca1d4e6b1a3d8cb48322bc