[Libreoffice] warnig and coding, need a little help on C++

2010-11-25 Thread Pierre-André Jacquod
Hello,
as I said, still in warm up phase and getting back familiar with C++..
So cleaning is a good exercise.

I got a compiler warning:

filters/binfilter/bf_sw/source/core/para/sw_paratr.cxx:214:26: warning:
'nTemp' may be used uninitialized in this function

for this:

case MID_DROPCAP_LINES :
{
 sal_Int8 nTemp;
 rVal = nTemp;
 if(nTemp =1  nTemp  0x7f
 nLines = (BYTE)nTemp;
}

Well, that's fine for me, nTemp is effectively not initialized. And the
second line is then the same as: rVal = rVal  nTemp

In my understanding, since nTemps is not initialized, if the compiler is
nice, nTemp is then defaulted to 0 (or NULL). Then rVal = rVal  0 make
not a lot of sense and is a true nop (no operation). And if the compiler
is not nice, I do not know which value has nTemp, i could almost use
random... So for me it seems the two first lines are not needed and even
dangerous.

OK, now the question: what did I missed ?

Thank for your help
regards
___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] warnig and coding, need a little help on C++

2010-11-25 Thread Caolán McNamara
On Thu, 2010-11-25 at 19:41 +0100, Pierre-André Jacquod wrote:
 {
  sal_Int8 nTemp;
  rVal = nTemp;
  if(nTemp =1  nTemp  0x7f
  nLines = (BYTE)nTemp;
 }
 
 Well, that's fine for me, nTemp is effectively not initialized. And the
 second line is then the same as: rVal = rVal  nTemp
 
 In my understanding, since nTemps is not initialized, if the compiler is
 nice, nTemp is then defaulted to 0 (or NULL). Then rVal = rVal  0 make
 not a lot of sense

 OK, now the question: what did I missed ?

Heh, this also confuses cppcheck as well. rVal is an Any and there is
an overloaded operator = which operates on that Any and nTemp. So
its not anything to do with bit shifting. Read it like...

rVal.ExtractTo(nTemp)

Now, if = fails it leaves nTemp untouched. So the general fix is
indeed to initialize nTemp to 0 to clear the warning.

C.

___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice


Re: [Libreoffice] warnig and coding, need a little help on C++

2010-11-25 Thread Pierre-André Jacquod
Thanks for helping.

 Heh, this also confuses cppcheck as well. 
cough... cough... ! I am not smarter than a machine... ! A professor I
had told: this not a good point being too smart... I understand what he
meant.

For stepping in, not the easiest way. Once there is no waring any more
when compiling, let start hacking to remove the overloaded operator and
replace it through more instinctive function call ::--)) /joke


___
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice