Re: [Iup-users] Patch to simplify IM's (r757) src/process/im_analyze.cpp

2020-04-26 Thread Ranier Vilela
De: sur-behoffski 
Enviado: domingo, 26 de abril de 2020 00:39
Para: IUP discussion list.
Assunto: [Iup-users] Patch to simplify IM's (r757) src/process/im_analyze.cpp

G'day,

I've been steering clear of IM, partially as much of its code is from
third-party libraries, and partially because activity on the project SVN
tree was so low.

However, I notice that there were three SVN commits in the past few
day, so, I've started looking at non-third-party code as a candidate for
change.

I'm trying to reduce GCC's warnings, without altering the code
semantics in any way.

I've found that there are a number of cases of the warning
"-Wmisleading-indent", relating to the code:

if (cm20) free(cm20); if (cm02) free(cm02); if (cm11) free(cm11);

Looking at the documentation for free(3), it states that NULL (0) is
explicitly allowed as a parameter, and the call will be a no-op.  The
GNU documentation states that this has been formalised at least in C89,
as well as all C and C++ standards since:  30 years ago.

I know that during the '80s, there were some C compilers that generated
code which crashed if free(NULL) was called, but I believe that in the
modern era, this concern is no longer valid.  Similarly, I believe that
the compiler toolchains handle the NULL case without heavily penalising
the caller (perhaps by defining "free" as a macro internally, and doing
the NULL check in the macro expansion before attempting a call).

Therefore, the above code could be rewritten as:

free(cm20); free(cm02); free(cm11);
+1
I've tried without success, say what on that list. Which is a waste to test 
against NULL before calling free.

regards,
Ranier Vilela

___
Iup-users mailing list
Iup-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/iup-users


[Iup-users] Patch to simplify IM's (r757) src/process/im_analyze.cpp

2020-04-25 Thread sur-behoffski
G'day,

I've been steering clear of IM, partially as much of its code is from
third-party libraries, and partially because activity on the project SVN
tree was so low.

However, I notice that there were three SVN commits in the past few
day, so, I've started looking at non-third-party code as a candidate for
change.

I'm trying to reduce GCC's warnings, without altering the code
semantics in any way.

I've found that there are a number of cases of the warning
"-Wmisleading-indent", relating to the code:

if (cm20) free(cm20); if (cm02) free(cm02); if (cm11) free(cm11);

Looking at the documentation for free(3), it states that NULL (0) is
explicitly allowed as a parameter, and the call will be a no-op.  The
GNU documentation states that this has been formalised at least in C89,
as well as all C and C++ standards since:  30 years ago.

I know that during the '80s, there were some C compilers that generated
code which crashed if free(NULL) was called, but I believe that in the
modern era, this concern is no longer valid.  Similarly, I believe that
the compiler toolchains handle the NULL case without heavily penalising
the caller (perhaps by defining "free" as a macro internally, and doing
the NULL check in the macro expansion before attempting a call).

Therefore, the above code could be rewritten as:

free(cm20); free(cm02); free(cm11);

This has three major benefits:

1. The text change to the code is very localised and easy to review,
   and there is no change to the semantics of the program;

2. The code is much easier to read, and to statically analyse.  If
   the code was in a testing regime where every code path had to be
   exercised, each translation such as the one above would cut down the
   number of combinations to be tried by a factor of 8; and

3. The change eliminates the "-Wmisleading-indent" warning, which is a
   particularly verbose item.  For IM r757, the number of warning lines
   (excluding the common header) drops from 275 lines to 215 lines,
   just by patching one file.

Attached are the patch, and the "parse-build.lua" output for IM before
and after applying the patch.

cheers,

sur-behoffski (Brenton Hoff)
programmer, Grouse Software
* No diagnostics for:
   #include expects "FILENAME" or 
   missing binary operator before token "("
   converting to non-pointer type  from NULL [-Wconversion-null]
is deprecated [-Wdeprecated-declarations]
is deprecated: Use  instead [-Wdeprecated-declarations]
   assignment discards  qualifier from pointer target type 
[-Wdiscarded-qualifiers]
   too many arguments for format [-Wformat-extra-args]
may write a terminating nul past the end of the destination 
[-Wformat-overflow=]
directive writing 1 byte into a region of size between 0 and 
 [-Wformat-overflow=]
directive writing  bytes into a region of size 
between  and  [-Wformat-overflow=]
directive writing between  and  bytes 
into a region of size between  and  [-Wformat-overflow=]
directive writing up to  bytes into a region of size 
 [-Wformat-overflow=]
   format not a string literal and no format arguments [-Wformat-security]
   assignment from incompatible pointer type [-Wincompatible-pointer-types]
   initialization from incompatible pointer type [-Wincompatible-pointer-types]
   passing argument  of  from incompatible pointer type 
[-Wincompatible-pointer-types]
may be used uninitialized in this function [-Wmaybe-uninitialized]
   missing braces around initializer [-Wmissing-braces]
   suggest parentheses around arithmetic in operand of '|' [-Wparentheses]
   suggest explicit braces to avoid ambiguous 'else' [-Wparentheses]
   suggest parentheses around '&&' within '||' [-Wparentheses]
   no return statement in function returning non-void [-Wreturn-type]
   control reaches end of non-void function [-Wreturn-type]
   this 'else' clause does not guard... [-Wmisleading-indentation]
   this 'for' clause does not guard... [-Wmisleading-indentation]
   this 'while' clause does not guard... [-Wmisleading-indentation]
   ignoring #pragma omp critical [-Wunknown-pragmas]
   ignoring #pragma omp for [-Wunknown-pragmas]
   ignoring #pragma omp parallel [-Wunknown-pragmas]
   ignoring #pragma omp section [-Wunknown-pragmas]
   ignoring #pragma warning  [-Wunknown-pragmas]
   dereferencing type-punned pointer will break strict-aliasing rules 
[-Wstrict-aliasing]
   enumeration value  not handled in switch [-Wswitch]
is used uninitialized in this function [-Wuninitialized]
defined but not used [-Wunused-const-variable=]
declared  but never defined [-Wunused-function]
   label  defined but not used [-Wunused-label]
   value computed is not used [-Wunused-value]
   unused variable  [-Wunused-variable]
   deprecated conversion from string constant to  [-Wwrite-strings]
(End of list.)


suggest explicit braces to avoid ambiguous 'else' [-Wdangling-else]:
lua5/imlua_process.c:55:[Function:imluaProcessSplitComplex]: 
lua5/imlua_process.c:61: