[GRASS-dev] r.flow: crash on 64bit

Hi,

when using r.flow on 64bit, it crashes (Spearfish example):
r.flow elevation.dem flout=flout lgout=lgout dsout=dsout
Reading input files: elevation
Precomputing: tangents
Precomputing: e/w distances
Precomputing: quantization tolerances
Precomputing: interpolated border elevations
Precomputing: aspects
Calculating maps ...
Segmentation fault

It dies in calc.c:223.

A backtrace:

GRASS 6.3.cvs (spearfish60):~ > gdb `which r.flow`
GNU gdb Red Hat Linux (6.3.0.0-1.132.EL4rh)
This GDB was configured as "x86_64-redhat-linux-gnu"...Using host libthread_db library "/lib64/tls/libthread_db.so.1".

(gdb) r elevation.dem flout=flout lgout=lgout dsout=dsout
Starting program: /nfsmnt/bartok0/ssi/neteler/software/cvsgrass63/dist.x86_64-unknown-linux-gnu/bin/r.flow elevation.dem flout=flout lgout=lgout dsout=dsout
[Thread debugging using libthread_db enabled]
[New Thread 182925195200 (LWP 26627)]
Detaching after fork from child process 26630.
Detaching after fork from child process 26631.
WARNING: The vector 'flout' already exists and will be overwritten.
Reading input files: elevation
Precomputing: tangents
Precomputing: e/w distances
Precomputing: quantization tolerances
Precomputing: interpolated border elevations
Precomputing: aspects
Calculating maps ...
   0%
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 182925195200 (LWP 26627)]
0x0000000000403e3f in next_point (p=0x7fbfffdf20, a=0x7fbfffdf10, b=0x7fbfffdf00, l=0x7fbfffdec0)
    at calc.c:223
223 if (oldtheta != 90 && oldtheta != 270 && /* north/south */
(gdb) bt full
#0 0x0000000000403e3f in next_point (p=0x7fbfffdf20, a=0x7fbfffdf10, b=0x7fbfffdf00, l=0x7fbfffdec0)
    at calc.c:223
        sub = 0
        cut = 2.356693130662746e-321
        horiz = 2
        semi = 1
        length = 1.1899763912722237e-312
        delta = 0
        deltaz = 0
        oldz = -nan(0xfffffffffffff)
        oldtheta = -2147483648
        oldr = 0
        oldc = 0
        ads = {row = 0, col = 0}
        bdy = {-30, 30}
        bdx = {-30, 30}
#1 0x0000000000404bb4 in calculate () at calc.c:369
        pts = {x = 589995, y = 4927995, z = -nan(0xfffffffffffff), theta = -2147483648, r = 0, c = 0}
        ads = {row = 0, col = 0}
        bbs = {{-1, 1}, {1, -1}}
        fls = {px = 0xc224b0, py = 0xc287e0, index = 1}
        row = 0
        col = 0
        x = 589995
        y = 4927995
        length = 0
        xstep = 30
        ystep = 30
        lg = (FCELL *) 0xc1f9f0
        points = (struct line_pnts *) 0xc1f550
        cats = (struct line_cats *) 0xc1f5e0
        loopstep = 1
#2 0x0000000000404dd2 in main (argc=5, argv=0x7fbffff288) at calc.c:419
        history = {
  mapid = "\020�\177\000\000\000\232�0238\000\000\000\000\200i\225*\000\000\000H\205i\225*\000\000\000\210\212i\225*\000\000\000\000`\225*\000\000\000t \227*", '\0' <repeats 11 times>, "@�\177\000\000\000\224�0238\000\000",
  title = "\000\000\000\000\000\000\000\000�\177\000\000\000\020�\177\000\000\000n\022\221\225*\000\000\000h\203\225*\000\000\0000�\177\000\000\000\210\212i\225*\000\000\000�226�0238", '\0' <repeats 11 times>, "�\t\000\000\000\000",
  mapset = "n\022\221\225*\000\000\000�0238", '\0' <repeats 11 times>, "@X�0238\000\000\000�\177\000\000\000\226�0238\000\000\000\230�\177\000\000\000\220�\177", '\0' <repeats 11 times>, "\002\000\000\000\000\000\000",
  creator = "\020�\177\000\000\000\232�0238\000\000\000t \227*", '\0' <repeats 11 times>, "0�\177\000\000\000\210\212i\225*\000\000\000 �\177\000\000\000\224�0238\000\000\000\000\000\000\000\177\000\000\000�{\225*\000\000",
  maptype = "\220\225*\000\000\000`�\177\000\000\000H\205i\225*\000\000\000�226�0238", '\0' <repeats 11 times>, "\020�\177\000\000\000�{\225*\000\000\000�0238\000\000\000�031@\000\000\000\000\000@X�0238\000\000",
  datsrc_1 = "�\177\000\000\000\226�0238\000\000\000\230�\177\000\000\000\220�\177\000\000\000@\003", '\0' <repeats 14 times>, "�{\225*\000\000\000\002\000\000\000\000\000\000\000\020�\177\000\000\000\232�0238\000\000",
  datsrc_2 = "t \227*", '\0' <repeats 11 times>, "�\177\000\000\000\224�0238", '\0' <repeats 11 times>, "�\177\000\000\000\020�\177\000\000\000�i\225*\000\000\000Xz\225*\000\000\000\220�\177\000\000",
---Type <return> to continue, or q <return> to quit---
  keywrd = "\000\200i\225*\000\000\000�226�0238", '\0' <repeats 11 times>, "@A�0238\000\000\000�i\225*\000\000\000�0238\000\000\000\020\000\000\000\000\000\000\000@X�0238\000\000\000�\177\000\000\000\226�0238\000\000", edlinecnt = -1073746536, edhist = {
    "\177\000\000\000\220�\177\000\000\000\022\000\000\000\000\000\004\000\000\000\000\000\000\000\020�\177\000\000\000\232�0238\000\000\000\000`\225*\000\000\000\210\212i\225*\000\000\000t \227*", '\0' <repeats 11 times>, "�",
    "\177\000\000\000\224�0238", '\0' <repeats 11 times>, "�002\0248\000\000\000�002\0248\000\000\000�\177\000\000\000\020�\177\000\000\000\r�\225*\000\000\000Hbi\225*\000\000\000�\177\000\000\000\230gU\225",
    "*\000\000\000�226�0238", '\0' <repeats 11 times>, " \000\000\000\000\000\000\000\r�\225*\000\000\000�0238\000\000\000\030\022\000\000\000\000\000@X�0238\000\000\000�\177\000\000\000\226�0238\000\000\000\230�",
    "\177\000\000\000\005\000\000\000\000\000\000\000\020�\177\000\000\000\232�0238\000\000\000H\205i\225*\000\000\000\210\212i\225*\000\000\000\000`\225*\000\000\000t \227*", '\0' <repeats 11 times>, "\230gU\225*\000\000\000�",
    "\177\000\000\000\224�0238", '\0' <repeats 27 times>, "\b\000\000\000\000\000\000\000R�d\004\000\000\000(\022\000\000\000\000\000(\002\0248\000\000\000\030\002\0248\000\000\000X,\000",
    "\000\000\000\000X,\000\000\000\000\000\000 \000\000\000\000\000\000\000\004\000\000\000\020\000\000\000\001\000\000\000GNU\000\000\000\000\000\002\000\000\000\004\000\000\000\024\000\000\000\001\000\000�a\000\000\005\006\000\000!\004\000\000b\a\000\000i\006\000\000\203\a\000",
    "j\005\000\000$\000\000\000\000\000\000\000\020�\177\000\000\000\232�0238\000\000\000H\205i\225*\000\000\000\210\212i\225*\000\000\000\000`\225*\000\000\000\000\020�225*\000\000\000H\025�225*\000\000\000Hj\225*\000\000\000\220\032�225",
    "*\000\000\000d\225*\000\000\000\000\200i\225*\000\000\000\000\000\225*\000\000\000\004\225*\000\000\000`\t\225*\000\000\000\000P\225\226*\000\000\000T\225\226*\000\000\000hY\225\226*\000\000\000\000\000�226*\000\000\000\004�226",
    "*\000\000\000X\t�226*\000\000\000\r�226*\000\000\000\230\022�226*\000\000\0008\027�226*\000\000\000�--Type <return> to continue, or q <return> to quit---
\033�226*\000\000\000\210 �226*\000\000\0000%�226*\000\000\000��226*\000\000\000\000\020\020\227*\000\000\000\024\020\227",
    "*\000\000\000P\031\020\227*\000\000\000\035\020\227*\000\000\000\"\020\227*\000\000\000H'\020\227*\000\000\000+\020\227*\000\000\0000\020\227*\000\000\000P5\020\227*\000\000\000t \227*", '\0' <repeats 11 times>, "b\032@",
    "\000\000\000\000\020�\177\000\000\000b\032@\000\000\000\000\000x�\000\000\000\000\000�\177\000\000\000Y�0238\000\000\000�\177\000\000\000\224�0238", '\0' <repeats 11 times>, "h�\000\000\000\000\000�",
    "\177\000\000\000Y�0238\000\000\000\000�\177\000\000\000\224�0238", '\0' <repeats 11 times>, "X�\000\000\000\000\000�\177\000\000\000Y�0238\000\000\0000�\177\000\000\000\224�0238\000\000\000\000\000\000",
    "\000\000\000\000H�\000\000\000\000\000�\177\000\000\000Y�0238\000\000\000\001\000\000\000\177\000\000\000t \227*\000\000\0000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\000\000p \227*\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000@:\020\227*\000\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000P5\020\227*\000\000\0000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\0000\020\227*\000\000\000`�",
    "\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000+\020\227*\000\000\000\220�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\000H'\020\227*\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\"\020\227*\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\035\020\227*\000\000\000 �\177"---Type <return> to continue, or q <return> to quit---
, '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000P\031\020\227*\000\000\000P�",
    "\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\024\020\227*\000\000\000\200�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\000\000\020\020\227*\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000��226*\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\0000%�226*\000\000\000\020�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\210 �226*\000\000\000@�",
    "\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000�033�226*\000\000\000p�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\0008\027�226*\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\230\022�226*\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\r�226*\000\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000X\t�226*\000\000\0000�",
    "\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\004�226*\000\000\000`�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\000\000\000�226*\000\000\000\220�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000hY\225\226*\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000T\225\226*\000\000\000�\177", ---Type <return> to continue, or q <return> to quit---
'\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\000P\225\226*\000\000\000 �",
    "\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000`\t\225*\000\000\000P�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000",
    "\177\000\000\000\004\225*\000\000\000\200�\177", '\0' <repeats 11 times>, "�\177\000\000\000�231�0238\000\000\000\001\000\000\000\177\000\000\000\000\000\225*\000\000\000�\177", '\0' <repeats 11 times>, "�",
    "\177\000\000\000\037�0238\000\000\000\001\000\000\000\177\000\000\000\0010\227*\000\000\000�\020\227*\000\000\000��0238\000\000\000�\177\000\000\000�231�023u\032i\t\002\000\000\000\177\000\000\000H\025�225*\000\000\000\000\000\000",
    '\0' <repeats 12 times>, "t0�0238\000\000\000\210�\0238\000\000\000\210)�0238\000\000\000-\000\000\000\000\000\000\000H�\227*\000\000\000@�\227*\000\000\000�\177\000\000\000`\005�0238\000\000\000�006",
    "\000\000\000\000\006�0238\000\000\000p�\177\000\000\0005!�0238\000\000\000\000�\177\000\000\000�\177\000\000\000�006\000\000\000\000\000\006�0238", '\0' <repeats 11 times>, "\236x�0238\000\000\000@�\227",
    "*\000\000\000\000\000\000\0008", '\0' <repeats 11 times>, "\001\000\000\000*\000\000\000�\177", '\0' <repeats 11 times>, "�\177\000\000\000\000\000\000\000\001\000\000\000@�\227*\000\000\000�\�0238\000\000\000\210�",
    "\177\000\000\000hS�0238", '\0' <repeats 11 times>, "�231�0238\000\000\000\001\000\000\000\000\000\000\000H\205i\225*\000\000\0000�\177", '\0' <repeats 19 times>, "�231�0238\000\000\000\001\000\000",
    "\000\000\000\000\037�0238\000\000\000\005\000\000\000\000\000\000\000\001\000\000\000\000\000\000\000�201 \227*\000\000\000��0238\000\000\000h�\0238\000\000\000t \227u\032i\t\002\000@;\000\000\000hS�0238\000\000\000\000\000\000",
    "\000\000\000\000\003\000\000\000\000\000\000\000t0�0238\000\000\000\210�\0238\000\000\000\210)�0238\000\000\000-\000\000\000\000\000\000\000H�\227*\000\000\000\030�\227*\000\000\000P�\177\000\000\000X)\0248\000\000\000\232\a",
    "\000\000\000\000i,\0248\000\000\000`\005�0238\000\000\000\000X\225\226*\000\000\000\220�\177\000\000\000P�\177\000\000\000\232\a\000\000\000\000i,\0248", '\0' <repeats 11 times>, "\236x�0238\000\000\000\030�\227",
    "*\000\000\000\001\000\000\0008", '\0' <repeats 11 times>, "\001", '\0' <repeats 11 times>, "\177\000\000\000\230\036@", '\0' <repeats 17 times>, "\001\000\000\000\030�\227*\000\000\000\000X\225\226*\000\000\000�",
    "\177\000\000\000\037�0238\000\000\000�0\227*\000\000\000\0010\227*\000\000\000�\020\227*\000\000\000��0238\000\000\000�201 \227*\000\000\000\037�0238\000\000\000\002\000 \227*\000\000\000\0010\227*\000\000\000�\020\227",
    "*\000\000\000��0238\000\000\000t0�0238\000\000\000��0238\000\000\000\002\000�0238\000\000\000-\000\000\000t)\222\b\002\000\000\000\000\000\000\000��0238", '\0' <repeats 11 times>, "\210�\023t)\222\b\002\000\223\026",
    "8\000\000\000o\221\0268", '\0' <repeats 11 times>, "-\000\000\000\000\000\000\000\205\223\0268\000\000\000��0238\000\000\000xC\220\0268\000\000\000\037�0238\000\000\000\002\0000\227*\000\000\000\0010\227*\000\000\000\t\220\031",
    "8\000\000\000��0238\000\000\000\205\223\0268\000\000\000o\221\026u\032i\t\002\000\220\0268\000\000\000-", '\0' <repeats 15 times>, "0�\227\000\000\000\000t0�0238\000\000\000\210�\0238\000\000\000\210)�023", "8\000\000\000-\000\000\000\000\000\000\000H�\227*\000\000\000�\227*\000\000\000`�\177\000\000\000\211u�0238\000\000\000y:<\a\000\000\000\000\037�0238", '\0' <repeats 11 times>, "\037�0238\000\000\000\204\n�023",
    "8\000\000\000\001\000\000\000\000\000\000\000�201 \227*\000\000\000��0238\000\000\000\002\000d\226*\000\000\000-\000\000\000u\032i\t\002", '\0' <repeats 23 times>, "o\221\026\000\000\000\000t0�023",
    "8\000\000\000\210�\0238\000\000\000\210)�0238\000\000\000-\000\000\000\000\000\000\000H�\227*\000\000\000\210�\227*\000\000\000\020�\177\000\000\000\037�0238\000\000\000ta�003\000\000\000\000\0010\227*\000\000\000�\020\227",
    "*\000\000\000��0238\000\000\000P�\177\000\000\000\020�u\032i\t\002\000�003\000\000\000\000@�\225*",
'\0' <repeats 11 times>, "\236x�023\000\000\000\000t0�0238\000\000\000\210�\0238\000\000\000\210)�023",---Type <return> to continue, or q <return> to quit---

    "8\000\000\000-\000\000\000\000\000\000\000H�\227*\000\000\000�0\227*\000\000\000�\177\000\000\0000\a@\000\000\000\000\000\216w\001\000\000\000\000\220\032@\000\000\000\000\000x�\177\000\000\000�\�0238\000\000\000�",
    "\177\000\000\000�\177\000\000\000\216w\001\000\000\000\000\220\032@", '\0' <repeats 13 times>, "\236x�0238\000\000\000�0\227*\000\000\000\001", '\0' <repeats 15 times>, "\001\000\000\000*\000\000\000\025\000\000",
    "\000\000\000\000�i\226*\000\000\000\020\220\0268\000\000\000\000\000\000\000\001\000\000\000�0\227*\000\000\000�\�0238\000\000\000\b�\177\000\000\000Y�0238\000\000\000\b\000\000\000\000\000\000\000H\237\t\226*\000\000\000Y�023",
    "8\000\000\000@\006\003\0248\000\000\000\020\004\000\000\000\000\000\000\200\215U\226*\000\000\000H\237\t\226*\000\000\000Y�0238\000\000\000�\177", '\0' <repeats 11 times>, "@L�0238\000\000\000C&@\000\000\000\000\0002@"}}
(gdb)

As usually in 64bit problems, I am lost...

Markus

Markus Neteler wrote:

when using r.flow on 64bit, it crashes (Spearfish example):
r.flow elevation.dem flout=flout lgout=lgout dsout=dsout
Reading input files: elevation
Precomputing: tangents
Precomputing: e/w distances
Precomputing: quantization tolerances
Precomputing: interpolated border elevations
Precomputing: aspects
Calculating maps ...
Segmentation fault

It dies in calc.c:223.

A backtrace:

Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 182925195200 (LWP 26627)]
0x0000000000403e3f in next_point (p=0x7fbfffdf20, a=0x7fbfffdf10, b=0x7fbfffdf00, l=0x7fbfffdec0)
    at calc.c:223
223 if (oldtheta != 90 && oldtheta != 270 && /* north/south */
(gdb) bt full
#0 0x0000000000403e3f in next_point (p=0x7fbfffdf20, a=0x7fbfffdf10, b=0x7fbfffdf00, l=0x7fbfffdec0)
    at calc.c:223
        sub = 0
        cut = 2.356693130662746e-321
        horiz = 2
        semi = 1
        length = 1.1899763912722237e-312
        delta = 0
        deltaz = 0
        oldz = -nan(0xfffffffffffff)
        oldtheta = -2147483648

oldtheta (initialised from p->theta) is used as an index into the
"tang" array, which has size 361 (i.e. valid indices are 0 to 360
inclusive). The value here is 0x80000000 (i.e. -2^31).

AFAICT, p->theta gets initialised from the result of the aspect()
macro (in mem.h), which uses aspect_fly() (from aspect.c) plus some
buffering via the segment library.

I can't really follow it beyond that. The code is quite poorly
written, making extensive use of macros containing free variables.
Also, there seems to be some confusion between integer and FP values
(e.g. the result of aspect() is explicitly cast to a double before
being stored in an integer field).

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