Skip to content

Commit be7a51b

Browse files
committed
fix: Grow allowed truncating of string
1 parent b0d8014 commit be7a51b

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ All notable changes to **ValueStringBuilder** will be documented in this file. T
99
### Added
1010
- Added the `scoped` keyword to simplify code and allow more scenarios for the user
1111

12+
### Fixed
13+
- `Grow` allowed values, which would truncate the internally represented string
14+
1215
## [1.3.0] - 2022-07-25
1316

1417
### Fixed

src/LinkDotNet.StringBuilder/ValueStringBuilder.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -259,9 +259,7 @@ private void Grow(int capacity = 0)
259259
{
260260
var currentSize = buffer.Length;
261261

262-
// This could lead to the potential problem that an user sets the capacity smaller than the current length
263-
// which would lead to a truncated string.
264-
var newSize = capacity > 0 ? capacity : currentSize * 2;
262+
var newSize = capacity > currentSize ? capacity : currentSize * 2;
265263
var rented = ArrayPool<char>.Shared.Rent(newSize);
266264
buffer.CopyTo(rented);
267265
var toReturn = arrayFromPool;

0 commit comments

Comments
 (0)