[GRASS-user] Segmentation fault with i.atcorr

Glynn Clements glynn at gclements.plus.com
Tue Jun 3 16:00:43 EDT 2008


Markus Neteler wrote:

> I have reproduced it in the NC dataset (some mapset problems of i.atcorr fixed
> in SVN):
> 
> cat icnd
> 8 (TM)
> 02 13 2.30 125.1297377 5.7841158 (Geometrical conditions)
> 1 (Tropical)
> 1 Continental
> 15 visibility
> -.600
> -1000
> 61 (chosen band)
> 
> 
> i.atcorr -b iimg=lsat5_1987_60 iscl=-6.978740,191.600 ialt=elevation
> icnd=./icnd oimg=test_p112r056_b1.rad.atcorr oscl=0,255
> ...
> Percent complete: Segmentation fault
> 
> The problem is in main.c, line 251:
>              if(isnan(vis[col]) || isnan(alt[col]) || isnan(buf[col]))
> {buf[col] = FP_NAN; continue;}

1. i.atcorr doesn't have a main.c (it's C++, so it's main.cpp).
2. that's line 304 (of main.cpp):

	if(isnan(vis[col]) || isnan(alt[col]) || isnan(buf[col])) {buf[col] = FP_NAN; continue;}

> Not sure what is FP_NAN is it seems to cause problems.

Contrary to what the author probably assumed, FP_NAN isn't NaN. It's
the value which the fpclassify() function returns if its argument is
NaN.

C99 defines the macro NAN in <math.h>; I don't know about C++.

AFAIK, the most portable way to create a NaN value is "0.0/0". In
GRASS, you can use e.g. G_set_f_null_value().

In any case, the problem appears to be that the code is accessing
elements of vis and alt without checking that those arrays have been
allocated.

-			if(isnan(vis[col]) || isnan(alt[col]) || isnan(buf[col])) {buf[col] = FP_NAN; continue;}
+			if(vis && isnan(vis[col]) || alt && isnan(alt[col]) || isnan(buf[col])) {buf[col] = FP_NAN; continue;}


-- 
Glynn Clements <glynn at gclements.plus.com>


More information about the grass-user mailing list