From 6c4961aaffa67f5a8ed0bb7dfd22f7fcbb4c47fb Mon Sep 17 00:00:00 2001 From: Linus Dierheimer Date: Wed, 17 Nov 2021 11:57:50 +0100 Subject: [PATCH] Fix a wrong compiler warning in io.c --- src/common/io.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/src/common/io.c b/src/common/io.c index 905f40a74..27a794cec 100644 --- a/src/common/io.c +++ b/src/common/io.c @@ -431,7 +431,16 @@ 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); }