[Libreoffice] About cppcheck 2 reports for desktop/unx/source/file_image_unx.c

Stephan Bergmann sbergman at redhat.com
Mon Jan 9 02:28:24 PST 2012

On 01/08/2012 12:25 PM, julien2412 wrote:
> For the file desktop/unx/source/file_image_unx.c, cppcheck tells :
> 120	duplicateExpression	style	Same expression on both sides of '-'.
> 93	unreadVariable	style	Variable 'c' is assigned a value that is never used
> line 93 is : volatile char c = 0
> Should this variable just be removed or c should be used in a way ?

What is done here is to touch a byte from every page of an mmap'ed file, 
in order to make sure the file is actually read in completely.  Hence 
the "volatile."  I guess we should live with the false cppcheck positive 
(or educate cppcheck to not assume writes to volatile variables need to 
be followed by reads).  What you could do, though, is to add a comment 
to c like "intentionally only written to and never read."

> line 120 is : w.m_size -= w.m_size;
> Either this is right and it could be simplified with w.m_size = 0
> or it's wrong and what should it be ?
> (this time no overload operator trick since it's plain C :-) )

The idea indeed appears to be to reduce w.m_size to zero.  However, 
since w is a local struct that is not used afterwards, anyway, it would 
probably be clearer to simply remove the two lines

   w.m_base = ...
   w.m_size = ...

from that last if-block.

> For both of them, if there's a easy fix, I suppose I may commit/push it on
> master, but on branch 3.5 too ?

Yes, please push to master.  These are fixing stylistic issues only, not 
real bugs, so I would not bother with 3.5 (unless you want to cppcheck 
the 3.5 branch and thus want to remove noise there).


More information about the LibreOffice mailing list