FastLED 3.9.15
Loading...
Searching...
No Matches

◆ grow()

void fl::StringHolder::grow ( size_t newLength)

Definition at line 139 of file str.cpp.

139 {
140 if (newLength <= mCapacity) {
141 // New length must be greater than current length
142 mLength = newLength;
143 return;
144 }
145 char *newData = (char *)realloc(mData, newLength + 1);
146 if (newData) {
147 mData = newData;
148 mLength = newLength;
149 mCapacity = newLength;
150 mData[mLength] = '\0'; // Ensure null-termination
151 } else {
152 // handle re-allocation failure.
153 char *newData = (char *)malloc(newLength + 1);
154 if (newData) {
155 memcpy(newData, mData, mLength + 1);
156 free(mData);
157 mData = newData;
158 mLength = newLength;
160 } else {
161 // memory failure.
162 }
163 }
164}
char * mData
Definition str.h:74
size_t mLength
Definition str.h:75
size_t mCapacity
Definition str.h:76

References mCapacity, mData, and mLength.