[GRASS-dev] Fwd: New Defects reported by Coverity Scan for grass
Glynn Clements
glynn at gclements.plus.com
Mon Oct 20 19:48:10 PDT 2014
Markus Neteler wrote:
> ** CID 1248526: Result is not floating-point (UNINTENDED_INTEGER_DIVISION)
> /imagery/i.atcorr/aerosolmodel.cpp: 388 in
for(int k = 1; k <= mu; k++)
{
double co_n = (2 * k + 1) / k / (k + 1);
co_n will be 1.0 if k==1 and 0.0 otherwise. I suggest:
double co_n = (2.0 * k + 1) / k / (k + 1);
to evaluate the expression using floating point.
> ** CID 1248523: Result is not floating-point (UNINTENDED_INTEGER_DIVISION)
> /raster/r.contour/cont.c: 349 in getpoint()
> /raster/r.contour/cont.c: 351 in getpoint()
double ratio;
...
ratio = 1 / 2;
This is equivalent to
ratio = 0.0;
It should probably be
ratio = 0.5;
>
> ** CID 1248527: Result is not floating-point (UNINTENDED_INTEGER_DIVISION)
> /raster/simwe/r.sim.sediment/main.c: 335 in main()
timesec = timesec * 60.0;
iterout = iterout * 60.0;
if ((timesec / iterout) > 100.0)
G_message(_("More than 100 files are going to be created !!!!!"));
timesec and iterout are both integers.
The integer division may actually be correct, in which case the
constants 60.0 and 100.0 should be replaced by integers.
> ** CID 1248529: Result is not floating-point (UNINTENDED_INTEGER_DIVISION)
> /raster/r.sunmask/main.c: 364 in main()
> /raster/r.sunmask/main.c: 385 in main()
> /raster/r.sunmask/main.c: 412 in main()
> /raster/r.sunmask/main.c: 423 in main()
if (sretr / 60 <= 24.0) {
Same issue, probably the same solution.
> ** CID 1248535: Untrusted value as argument (TAINTED_SCALAR)
>
> ** CID 1248540: Uninitialized scalar variable (UNINIT)
> /imagery/i.eb.hsebal01/main.c: 200 in main()
if(input_row_wet->answer&&
input_col_wet->answer&&
input_row_dry->answer&&
input_col_dry->answer){
m_row_wet = atof(input_row_wet->answer);
m_col_wet = atof(input_col_wet->answer);
m_row_dry = atof(input_row_dry->answer);
m_col_dry = atof(input_col_dry->answer);
}
if ((!input_row_wet->answer || !input_col_wet->answer ||
!input_row_dry->answer || !input_col_dry->answer) &&
!flag2->answer) {
G_fatal_error(_("Either auto-mode either wet/dry pixels coordinates should be provided!"));
}
if (flag3->answer) {
G_message(_("Manual wet/dry pixels in image coordinates"));
G_message(_("Wet Pixel=> x:%f y:%f"), m_col_wet, m_row_wet);
G_message(_("Dry Pixel=> x:%f y:%f"), m_col_dry, m_row_dry);
}
The variables are only initialised if all four options are given.
The code then checks that all four options are given *if* flag2 is not
given.
The variables are used if flag3 is given.
So, if you give flag3, don't give flag2, and don't give all of four
parameters, it will read uninitialised variables.
This needs the correct logic for option dependencies.
--
Glynn Clements <glynn at gclements.plus.com>
More information about the grass-dev
mailing list