Skip to content

Commit

Permalink
str - reserve fix(BUG: crash when len arg was 0)
Browse files Browse the repository at this point in the history
    - reserve_virtual changed so it will not return ptr
dynarray - reserve_virtual changed so it will not return ptr
  • Loading branch information
cyrilgramblicka committed Sep 5, 2024
1 parent 600f2b9 commit c7be4e4
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 10 deletions.
4 changes: 1 addition & 3 deletions dynarray.h
Original file line number Diff line number Diff line change
Expand Up @@ -1189,14 +1189,12 @@ class dynarray
///Reserve address space for \a nitems of elements in virtual memory
/** @param nitems number of items to reserve
@return pointer to the first item of the array */
T* reserve_virtual(uints nitems)
void reserve_virtual(uints nitems)
{
discard();

_ptr = A::template reserve_virtual<T>(nitems);
_set_count(0);

return _ptr;
}

///Reserve stack memory for \a nitems of elements using _alloca
Expand Down
10 changes: 3 additions & 7 deletions str.h
Original file line number Diff line number Diff line change
Expand Up @@ -2049,20 +2049,16 @@ class charstr
/// @param m [optional] memory space to use
char* reserve(uints len, mspace m = 0) {
bool clear = _tstr.ptr() == nullptr;
char* p = _tstr.reserve(len, true, m);
char* p = _tstr.reserve(len > 0 ? len : 1, true, m);
if (clear)
*p = 0;
return p;
}

///Reserve virtual memory for string buffer
/// @param len min size for string to reserve (incl. term zero)
char* reserve_virtual(uints len) {
bool clear = _tstr.ptr() == nullptr;
char* p = _tstr.reserve_virtual(len);
if (clear)
*p = 0;
return p;
void reserve_virtual(uints len) {
_tstr.reserve_virtual(len);
}

///Reserve stack memory for string buffer
Expand Down

0 comments on commit c7be4e4

Please sign in to comment.