From 4e818c981a3da7c3b973ceffccbfe49c32f9a950 Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 17 Nov 2021 12:00:06 +0100 Subject: [PATCH] Found a better way to fix the warning from pevious commit --- src/common/io.c | 9 --------- src/util/FFstrbuf.c | 2 +- 2 files changed, 1 insertion(+), 10 deletions(-) diff --git a/src/common/io.c b/src/common/io.c index 27a794cec..905f40a74 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -431,16 +431,7 @@ void ffAppendFDContent(int fd, FFstrbuf* buffer) (uint32_t) readed == free ) { buffer->length += readed; - - //GCC is complaining about a possible write to an array of length zero. - //It believes (buffer->allocated * 2) - 1) can be zero. | This is done in ffStrbufEnsureCapacity. - //This would happen when buffer->allocated is zero: 0 * 2 = 0; 0 - 1 = UINT32_MAX; UINT32_MAX + 1 = 0; - //However, this can never be true, because of our ffStrbufEnsureFree call above. - #pragma GCC diagnostic push - #pragma GCC diagnostic ignored "-Wstringop-overflow" ffStrbufEnsureCapacity(buffer, (buffer->allocated * 2) - 1); // -1 for null terminator - #pragma GCC diagnostic pop - free = ffStrbufGetFree(buffer); } diff --git a/src/util/FFstrbuf.c b/src/util/FFstrbuf.c index 1a782ac9a..69f88ff77 100644 --- a/src/util/FFstrbuf.c +++ b/src/util/FFstrbuf.c @@ -101,7 +101,7 @@ static void setCapacity(FFstrbuf* strbuf, uint32_t capacity) void ffStrbufEnsureCapacity(FFstrbuf* strbuf, uint32_t capacity) { - if(strbuf->allocated > capacity) + if(strbuf->allocated > capacity || capacity == 0) return; setCapacity(strbuf, capacity + 1); // + 1 for the null byte