Skip to content

Commit 79c1a06

Browse files
WonderMrclaude
andcommitted
string/memmgr: address Copilot review feedback on #4360
furi/core/string.c (furi_string_cat_vprintf): The retry condition used >= which fired one extra vsnprintf when the formatted output fit exactly into the reserved capacity (NUL byte included). vsnprintf only truncates when size + 1 > buffer; change the predicate to match. furi/core/memmgr.c (realloc): Drop the unreachable NULL-guard around the copy/free. pvPortMalloc() calls furi_check(pvReturn, ...) on OOM (memmgr_heap.c:466) and crashes before returning, so p cannot be NULL after the call. The guard was dead code; the "preserve allocation on OOM" behavior advertised in the original commit message never actually triggered. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent f48d096 commit 79c1a06

2 files changed

Lines changed: 5 additions & 7 deletions

File tree

furi/core/memmgr.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,12 +26,10 @@ void* realloc(void* ptr, size_t size) {
2626

2727
void* p = pvPortMalloc(size);
2828
if(ptr != NULL) {
29-
if(p != NULL) {
30-
size_t old_size = memmgr_heap_get_block_size(ptr);
31-
size_t copy_size = old_size < size ? old_size : size;
32-
memcpy(p, ptr, copy_size);
33-
vPortFree(ptr);
34-
}
29+
size_t old_size = memmgr_heap_get_block_size(ptr);
30+
size_t copy_size = old_size < size ? old_size : size;
31+
memcpy(p, ptr, copy_size);
32+
vPortFree(ptr);
3533
}
3634

3735
return p;

furi/core/string.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ int furi_string_cat_vprintf(FuriString* v, const char format[], va_list args) {
187187

188188
int size = vsnprintf(&ptr[old_size], alloc - old_size, format, args);
189189

190-
if(size > 0 && (old_size + (size_t)size + 1 >= alloc)) {
190+
if(size > 0 && (old_size + (size_t)size + 1 > alloc)) {
191191
// Buffer too small — grow and retry
192192
ptr = m_str1ng_fit2size(v->string, old_size + (size_t)size + 1);
193193
size = vsnprintf(

0 commit comments

Comments
 (0)