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

◆ grow()

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

Definition at line 195 of file str.cpp.

195 {
196 if (newLength <= mCapacity) {
197 // New length must be greater than current length
198 mLength = newLength;
199 return;
200 }
201 char *newData = (char *)realloc(mData, newLength + 1);
202 if (newData) {
203 mData = newData;
204 mLength = newLength;
205 mCapacity = newLength;
206 mData[mLength] = '\0'; // Ensure null-termination
207 } else {
208 // handle re-allocation failure.
209 char *newData = (char *)malloc(newLength + 1);
210 if (newData) {
211 memcpy(newData, mData, mLength + 1);
212 free(mData);
213 mData = newData;
214 mLength = newLength;
216 } else {
217 // memory failure.
218 }
219 }
220}
char * mData
Definition str.h:101
size_t mLength
Definition str.h:102
size_t mCapacity
Definition str.h:103

References mCapacity, mData, and mLength.