CPU (Linux): fix var content was unexpectedly modified

This commit is contained in:
Carter Li
2025-01-06 10:57:29 +08:00
parent 6429c20466
commit 3ea0406b69
3 changed files with 23 additions and 0 deletions
+16
View File
@@ -570,6 +570,22 @@ bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer)
return true;
}
/// @brief Restore the end of a line that was modified by ffStrbufGetline.
/// @warning This function should be called before breaking an ffStrbufGetline loop.
void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer)
{
assert(buffer && lineptr && n);
assert(buffer->allocated > 0 || (buffer->allocated == 0 && buffer->length == 0));
assert(!*lineptr || (*lineptr >= buffer->chars && *lineptr <= buffer->chars + buffer->length));
if (!*lineptr)
return;
*lineptr += *n;
if (*lineptr < buffer->chars + buffer->length)
**lineptr = '\n';
}
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf)
{
if (strbuf->allocated == 0) return false; // Doesn't work with static strings
+1
View File
@@ -90,6 +90,7 @@ void ffStrbufUpperCase(FFstrbuf* strbuf);
void ffStrbufLowerCase(FFstrbuf* strbuf);
bool ffStrbufGetline(char** lineptr, size_t* n, FFstrbuf* buffer);
void ffStrbufGetlineRestore(char** lineptr, size_t* n, FFstrbuf* buffer);
bool ffStrbufRemoveDupWhitespaces(FFstrbuf* strbuf);
FF_C_NODISCARD static inline FFstrbuf ffStrbufCreateA(uint32_t allocate)