POV-Ray : Newsgroups : povray.programming : code cleanup Server Time: 12 Dec 2018 21:22:59 GMT
  code cleanup (Message 1 to 3 of 3)  
From: hexcoder
Subject: code cleanup
Date: 15 Aug 2017 19:55:01
Message: <web.599340ed879ff37936107e040@news.povray.org>
Hi,
i just ran cppcheck for povray sources:

[libraries/tiff/libtiff/tif_ojpeg.c:925]: (error) Invalid number of character
'(' when these macros are defined: 'C_LOSSLESS_SUPPORTED;OJPEG_SUPPORT;never'.

ok, 'never' should obviously never be defined, otherwise it would not compile.

[libraries/tiff/contrib/stream/tiffstream.cpp:117]: (error) Uninitialized
variable: ostr

 ostream* ostr;
 if(ts->m_outStream != NULL) {
     ostr = ts->m_outStream;
 } else if(ts->m_ioStream != NULL) {
     ostr = ts->m_ioStream;
 }

 streampos start = ostr->tellp();

Here another else branch would be good in order to handle the case of
ts->m_outStream == NULL and ts->m_ioStream == NULL
(if that is possible (who knows))

[libraries/tiff/tools/tiffsplit.c:64]: (error) Buffer overrun possible for long
command line arguments.

might be triggered from the outside, if tiffsplit is used at all.


[source/base/povmscpp.cpp:1757]: (error) Memory leak: nodeptr

In case of an exception nodeptr cannot be freed anymore...

[source/base/povmscpp.cpp:1781]: (error) Memory leak: nodeptr

In case of an exception nodeptr cannot be freed anymore...

In both cases could

 err = POVMS_InstallReceiver(context, ReceiveHandler, hclass, hid, (void
*)this);
 if(err != pov_base::kNoErr)
  throw POV_EXCEPTION_CODE(err);

be moved to the beginning of the method? I see no dependency to local variables
here.

[windows/cmedit/ccodemax.cpp:289]:
[windows/cmedit/ccodemax.cpp:305]:
[windows/cmedit/ccodemax.cpp:321]:
[windows/cmedit/ccodemax.cpp:685]:
[windows/cmedit/ccodemax.cpp:699]:
The return value of malloc() should be checked before usage.

Hope you find that useful, best regards Heiko


Post a reply to this message

From: Thorsten Froehlich
Subject: Re: code cleanup
Date: 15 Aug 2017 20:50:01
Message: <web.59935e21e42ebdf653e6c55b0@news.povray.org>
"hexcoder" <nomail@nomail> wrote:
>
> [source/base/povmscpp.cpp:1757]: (error) Memory leak: nodeptr
>
> In case of an exception nodeptr cannot be freed anymore...
>
> [source/base/povmscpp.cpp:1781]: (error) Memory leak: nodeptr
>
> In case of an exception nodeptr cannot be freed anymore...
>
> In both cases could
>
>  err = POVMS_InstallReceiver(context, ReceiveHandler, hclass, hid, (void
> *)this);
>  if(err != pov_base::kNoErr)
>   throw POV_EXCEPTION_CODE(err);
>
> be moved to the beginning of the method? I see no dependency to local variables
> here.

No. This exception will always have to be a fatal error for the application
because if is more or less an emergency exit when POV-Ray runs out of memory. So
it is too late the fiddle with memory anyway. Basically all POVMS errors are
fatal because it means communication within POV-Ray's threads is broken, in
which case you actually "leak" whole threads...


Post a reply to this message

From: clipka
Subject: Re: code cleanup
Date: 15 Aug 2017 22:37:41
Message: <599377b5@news.povray.org>
Am 15.08.2017 um 21:51 schrieb hexcoder:

> [libraries/tiff/libtiff/tif_ojpeg.c:925]: (error) Invalid number of character
> '(' when these macros are defined: 'C_LOSSLESS_SUPPORTED;OJPEG_SUPPORT;never'.
...
> [libraries/tiff/contrib/stream/tiffstream.cpp:117]: (error) Uninitialized
> variable: ostr
...
> [libraries/tiff/tools/tiffsplit.c:64]: (error) Buffer overrun possible for long
> command line arguments.

This is libtiff, a 3rd party library. We won't be doing code cleanup in
there.


> [source/base/povmscpp.cpp:1757]: (error) Memory leak: nodeptr
...
> [source/base/povmscpp.cpp:1781]: (error) Memory leak: nodeptr

Thorsten commented on those already.


> [windows/cmedit/ccodemax.cpp:289]:
> [windows/cmedit/ccodemax.cpp:305]:
> [windows/cmedit/ccodemax.cpp:321]:
> [windows/cmedit/ccodemax.cpp:685]:
> [windows/cmedit/ccodemax.cpp:699]:
> The return value of malloc() should be checked before usage.

This is helper code for integrating CodeMax, a 3rd party library
providing the editor component for the Windows GUI. As we hope to get
rid of that component at the next possible opportunity (it doesn't fit
neatly with our current license), we probably won't be doing much code
cleanup in there either.


Post a reply to this message

Copyright 2003-2008 Persistence of Vision Raytracer Pty. Ltd.