]> granicus.if.org Git - transmission/commitdiff
Attempt to explain something to Coverity
authorMike Gelfand <mikedld@mikedld.com>
Wed, 13 Mar 2019 02:32:35 +0000 (05:32 +0300)
committerMike Gelfand <mikedld@mikedld.com>
Wed, 13 Mar 2019 02:32:35 +0000 (05:32 +0300)
I'm seeing 7 potentially false reported issues re. use of uninitialized buffer
data here. It seems that `read` function should be properly supported by
Coverity, but maybe it can't figure out the postconditions of it properly...
Walking in the dark here.

libtransmission/file.c

index a2da678df42205c60a7edf26e26726c746ae213e..14335f70b0cdecd3d6336fa2f4640a97c759586c 100644 (file)
@@ -26,7 +26,9 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
 
     while (buffer_size > 0)
     {
-        ret = tr_sys_file_read(handle, buffer + offset, MIN(buffer_size, 1024u), &bytes_read, error);
+        size_t const bytes_needed = MIN(buffer_size, 1024u);
+
+        ret = tr_sys_file_read(handle, buffer + offset, bytes_needed, &bytes_read, error);
 
         if (!ret || (offset == 0 && bytes_read == 0))
         {
@@ -34,6 +36,9 @@ bool tr_sys_file_read_line(tr_sys_file_t handle, char* buffer, size_t buffer_siz
             break;
         }
 
+        TR_ASSERT(bytes_read <= bytes_needed);
+        TR_ASSERT(bytes_read <= buffer_size);
+
         int64_t delta = 0;
 
         for (size_t i = 0; i < bytes_read; ++i, ++offset, --buffer_size)