Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

gcd_ crashes for zero $-variables #191

Closed
tueda opened this issue Jun 6, 2017 · 13 comments
Closed

gcd_ crashes for zero $-variables #191

tueda opened this issue Jun 6, 2017 · 13 comments
Labels
bug Something isn't working

Comments

@tueda
Copy link
Collaborator

tueda commented Jun 6, 2017

gcd_ has a memory bug when the first argument is a zero $-variable.

#$a = 0;
#$b = 1;
#$c = gcd_($a,$b);  * must be 1
.end
FORM 4.1 (May 24 2017, v4.1-20131025-346-gcf71752) 64-bits  Run: Tue Jun  6 10:05:01 2017
    #$a = 0;
    #$b = 1;
*** glibc detected *** form: free(): invalid next size (fast): 0x0000000002518430 ***
======= Backtrace: =========
/lib64/libc.so.6[0x32e1275f3e]
/lib64/libc.so.6[0x32e1278dd0]
form[0x5406fd]
form[0x52c4cf]
form[0x447eb3]
form[0x51e275]
form[0x4032e8]
/lib64/libc.so.6(__libc_start_main+0xfd)[0x32e121ed1d]
form[0x403325]
======= Memory map: ========
00400000-0060f000 r-xp 00000000 fd:03 7088816                            /localstore/theorie/tueda/build/linuxbrew/Cellar/form/HEAD-cf71752/bin/form
0080f000-00810000 r--p 0020f000 fd:03 7088816                            /localstore/theorie/tueda/build/linuxbrew/Cellar/form/HEAD-cf71752/bin/form
00810000-00814000 rw-p 00210000 fd:03 7088816                            /localstore/theorie/tueda/build/linuxbrew/Cellar/form/HEAD-cf71752/bin/form
00814000-0086d000 rw-p 00000000 00:00 0
024ea000-02569000 rw-p 00000000 00:00 0                                  [heap]
32e0e00000-32e0e20000 r-xp 00000000 fd:00 651535                         /lib64/ld-2.12.so
32e101f000-32e1021000 r--p 0001f000 fd:00 651535                         /lib64/ld-2.12.so
32e1021000-32e1022000 rw-p 00021000 fd:00 651535                         /lib64/ld-2.12.so
32e1022000-32e1023000 rw-p 00000000 00:00 0
32e1200000-32e138a000 r-xp 00000000 fd:00 651536                         /lib64/libc-2.12.so
32e138a000-32e158a000 ---p 0018a000 fd:00 651536                         /lib64/libc-2.12.so
32e158a000-32e158e000 r--p 0018a000 fd:00 651536                         /lib64/libc-2.12.so
32e158e000-32e1590000 rw-p 0018e000 fd:00 651536                         /lib64/libc-2.12.so
32e1590000-32e1594000 rw-p 00000000 00:00 0
32e1600000-32e1683000 r-xp 00000000 fd:00 651538                         /lib64/libm-2.12.so
32e1683000-32e1882000 ---p 00083000 fd:00 651538                         /lib64/libm-2.12.so
32e1882000-32e1883000 r--p 00082000 fd:00 651538                         /lib64/libm-2.12.so
32e1883000-32e1884000 rw-p 00083000 fd:00 651538                         /lib64/libm-2.12.so
32e8600000-32e8656000 r-xp 00000000 fd:00 807941                         /usr/lib64/libgmp.so.3.5.0
32e8656000-32e8856000 ---p 00056000 fd:00 807941                         /usr/lib64/libgmp.so.3.5.0
32e8856000-32e885b000 rw-p 00056000 fd:00 807941                         /usr/lib64/libgmp.so.3.5.0
7ff3c8000000-7ff3c8021000 rw-p 00000000 00:00 0
7ff3c8021000-7ff3cc000000 ---p 00000000 00:00 0
7ff3cc9c8000-7ff3e54b5000 rw-p 00000000 00:00 0
7ff3e54b5000-7ff3e54c6000 r-xp 00000000 fd:03 17969798                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libgcc_s.so.1
7ff3e54c6000-7ff3e56c6000 ---p 00011000 fd:03 17969798                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libgcc_s.so.1
7ff3e56c6000-7ff3e56c7000 rw-p 00011000 fd:03 17969798                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libgcc_s.so.1
7ff3e56c7000-7ff3e56c8000 rw-p 00000000 00:00 0
7ff3e56c8000-7ff3e57f4000 r-xp 00000000 fd:03 17971137                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libstdc++.so.6.0.21
7ff3e57f4000-7ff3e59f4000 ---p 0012c000 fd:03 17971137                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libstdc++.so.6.0.21
7ff3e59f4000-7ff3e59fe000 r--p 0012c000 fd:03 17971137                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libstdc++.so.6.0.21
7ff3e59fe000-7ff3e5a02000 rw-p 00136000 fd:03 17971137                   /localstore/theorie/tueda/build/linuxbrew/Cellar/gcc/5.3.0/lib/libstdc++.so.6.0.21
7ff3e5a02000-7ff3e5a06000 rw-p 00000000 00:00 0
7ff3e5a26000-7ff3e5a38000 r-xp 00000000 fd:03 20726621                   /localstore/theorie/tueda/build/linuxbrew/Cellar/zlib/1.2.11/lib/libz.so.1.2.11
7ff3e5a38000-7ff3e5c37000 ---p 00012000 fd:03 20726621                   /localstore/theorie/tueda/build/linuxbrew/Cellar/zlib/1.2.11/lib/libz.so.1.2.11
7ff3e5c37000-7ff3e5c38000 rw-p 00011000 fd:03 20726621                   /localstore/theorie/tueda/build/linuxbrew/Cellar/zlib/1.2.11/lib/libz.so.1.2.11
7ff3e5c38000-7ff3e5c39000 rw-p 00000000 00:00 0
7ffd711fe000-7ffd71219000 rw-p 00000000 00:00 0                          [stack]
7ffd71349000-7ffd7134a000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Aborted (core dumped)

Valgrind output:

==30839== Memcheck, a memory error detector
==30839== Copyright (C) 2002-2015, and GNU GPL'd, by Julian Seward et al.
==30839== Using Valgrind-3.12.0 and LibVEX; rerun with -h for copyright info
==30839== Command: vorm 1
==30839==
FORM 4.1 (May 24 2017, v4.1-20131025-346-gcf71752) 64-bits  Run: Tue Jun  6 10:05:51 2017
    #$a = 0;
    #$b = 1;
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4BFADB: GCDterms (ratio.c:2063)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C0082: GCDterms (ratio.c:2066)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C009F: GCDterms (ratio.c:2225)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C00B8: GCDterms (ratio.c:2225)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4CA7C9: AccumGCD (reken.c:653)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C4FE1: UnPack (reken.c:104)
==30839==    by 0x4CA80D: AccumGCD (reken.c:655)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C4FF2: UnPack (reken.c:106)
==30839==    by 0x4CA80D: AccumGCD (reken.c:655)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C502E: UnPack (reken.c:114)
==30839==    by 0x4CA80D: AccumGCD (reken.c:655)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C79DA: GcdLong (reken.c:2275)
==30839==    by 0x4CA83D: AccumGCD (reken.c:657)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C79E4: GcdLong (reken.c:2276)
==30839==    by 0x4CA83D: AccumGCD (reken.c:657)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C7A01: GcdLong (reken.c:2283)
==30839==    by 0x4CA83D: AccumGCD (reken.c:657)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4CA85C: AccumGCD (reken.c:659)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C79DA: GcdLong (reken.c:2275)
==30839==    by 0x4CA88D: AccumGCD (reken.c:660)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C79E4: GcdLong (reken.c:2276)
==30839==    by 0x4CA88D: AccumGCD (reken.c:660)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C7A01: GcdLong (reken.c:2283)
==30839==    by 0x4CA88D: AccumGCD (reken.c:660)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4CA8B2: AccumGCD (reken.c:662)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C4FAB: Pack (reken.c:86)
==30839==    by 0x4CA8CF: AccumGCD (reken.c:663)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C4FAE: Pack (reken.c:86)
==30839==    by 0x4CA8CF: AccumGCD (reken.c:663)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid write of size 4
==30839==    at 0x4C4FAE: Pack (reken.c:86)
==30839==    by 0x4CA8CF: AccumGCD (reken.c:663)
==30839==    by 0x4C00F6: GCDterms (ratio.c:2228)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x5708928 is 0 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C0148: GCDterms (ratio.c:2235)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid write of size 4
==30839==    at 0x4C0148: GCDterms (ratio.c:2235)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x570892c is 4 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid write of size 4
==30839==    at 0x4C015C: GCDterms (ratio.c:2236)
==30839==    by 0x4C1211: GCDfunction (ratio.c:1000)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x5708930 is 8 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C121E: GCDfunction (ratio.c:1001)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid read of size 4
==30839==    at 0x4C1228: GCDfunction (ratio.c:1001)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x5708928 is 0 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid read of size 4
==30839==    at 0x4C1230: GCDfunction (ratio.c:1001)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x570892c is 4 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C1260: GCDfunction (ratio.c:1007)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid read of size 4
==30839==    at 0x4C1260: GCDfunction (ratio.c:1007)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x570892c is 4 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C1274: GCDfunction (ratio.c:1008)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid read of size 4
==30839==    at 0x4C1274: GCDfunction (ratio.c:1008)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x570892c is 4 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Conditional jump or move depends on uninitialised value(s)
==30839==    at 0x4C12B8: GCDfunction (ratio.c:1010)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C9827: MulRat (reken.c:382)
==30839==    by 0x4C131F: GCDfunction (ratio.c:1015)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Use of uninitialised value of size 8
==30839==    at 0x4C982E: MulRat (reken.c:382)
==30839==    by 0x4C131F: GCDfunction (ratio.c:1015)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
==30839== Invalid read of size 4
==30839==    at 0x4C982E: MulRat (reken.c:382)
==30839==    by 0x4C131F: GCDfunction (ratio.c:1015)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==  Address 0x5708928 is 0 bytes after a block of size 72 alloc'd
==30839==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==30839==    by 0x4FE1DF: Malloc1 (tools.c:2236)
==30839==    by 0x42FDFC: DolToTerms (dollar.c:1539)
==30839==    by 0x4C10C2: GCDfunction (ratio.c:969)
==30839==    by 0x4B7455: Generator (proces.c:3686)
==30839==    by 0x42E4CE: CatchDollar (dollar.c:112)
==30839==    by 0x4AF440: PreProcessor (pre.c:1050)
==30839==    by 0x4E770F: main (startup.c:1605)
==30839==
    #$c = gcd_($a,$b);  * must be 1
    .end
  0.08 sec out of 0.08 sec
==30839==
==30839== HEAP SUMMARY:
==30839==     in use at exit: 391,558,976 bytes in 132 blocks
==30839==   total heap usage: 545 allocs, 413 frees, 414,465,023 bytes allocated
==30839==
==30839== LEAK SUMMARY:
==30839==    definitely lost: 0 bytes in 0 blocks
==30839==    indirectly lost: 0 bytes in 0 blocks
==30839==      possibly lost: 0 bytes in 0 blocks
==30839==    still reachable: 391,558,976 bytes in 132 blocks
==30839==         suppressed: 0 bytes in 0 blocks
==30839== Rerun with --leak-check=full to see details of leaked memory
==30839==
==30839== For counts of detected and suppressed errors, rerun with: -v
==30839== Use --track-origins=yes to see where uninitialised values come from
==30839== ERROR SUMMARY: 33 errors from 33 contexts (suppressed: 4 from 4)
@spj101
Copy link
Contributor

spj101 commented Jun 6, 2017

gcd_ also crashes occasionally on mac os x (though not on my linux machine) when a zero expression is in the first argument.
Input:

#-
off statistics;
L p1 = 0;
L p2 = 1;
#do i = 1,100000
*L gcd = gcd_(p2,p1); * Works
L gcd = gcd_(p1,p2);  * Fails
.sort
#enddo
.end

Output of form (on mac):

FORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits  Run: Wed Jun  7 00:07:13 2017
    #-
Program terminating at bug.frm Line 7 -->
  0.00 sec out of 0.00 sec

Output of tform (on mac):

TFORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits 0 workers  Run: Wed Jun  7 00:14:06 2017
    #-
Term too complex during normalization
Called from GCDfunction
Program terminating in thread 0 at bug.frm Line 7 -->
tform(4759,0x7fff774eb000) malloc: *** error for object 0x7fe370d00250: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Abort trap: 6

@spj101
Copy link
Contributor

spj101 commented Jun 6, 2017

I think gcd_ also gives wrong results when called with a zero.
Input:

#-
off statistics;
S x;
L p1 = 0;
L p2 = x+x^2;
L gcd = gcd_(p2,p1);
print;
.end

Output:

TFORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits 0 workers  Run: Wed Jun  7 00:17:22 2017
    #-

   p1 = 0;

   p2 =
      x + x^2;

   gcd =
      1;

Should we not expect gcd = x+x^2?

If the polynomial has only 1 term the result seems fine.
Input:

#-
off statistics;
S x;
L p1 = 0;
L p2 = x^2;
L gcd = gcd_(p2,p1);
print;
.end

Output:

FORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits  Run: Wed Jun  7 00:19:24 2017
    #-

   p1 = 0;

   p2 =
      x^2;

   gcd =
      x^2;

@tueda
Copy link
Collaborator Author

tueda commented Jun 6, 2017

gcd_ also crashes occasionally on mac os x (though not on my linux machine) when a zero expression is in the first argument.

I think gcd_ also gives wrong results when called with a zero.

Actually Valgrind tells us something goes wrong at ratio.c:2063 in these cases, too:

FORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits  Run: Wed Jun  7 00:49:52 2017
    L p1 = 0;
    L p2 = 1;
    L gcd = gcd_(p1,p2);
    .end

Time =       0.06 sec    Generated terms =          0
              p1         Terms in output =          0
                         Bytes used      =          4

Time =       0.08 sec    Generated terms =          1
              p2         Terms in output =          1
                         Bytes used      =         20
==23356== Invalid read of size 4
==23356==    at 0x4BFDDD: GCDterms (ratio.c:2063)
==23356==    by 0x4C1518: GCDfunction (ratio.c:1000)
==23356==    by 0x4B7725: Generator (proces.c:3688)
==23356==    by 0x4B7C7A: Generator (proces.c:3886)
==23356==    by 0x4B93FA: Processor (proces.c:404)
==23356==    by 0x437480: DoExecute (execute.c:812)
==23356==    by 0x44D8FE: ExecModule (module.c:274)
==23356==    by 0x4AF44B: PreProcessor (pre.c:962)
==23356==    by 0x4E7A30: main (startup.c:1605)
==23356==  Address 0x570977c is 4 bytes before a block of size 96 alloc'd
==23356==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==23356==    by 0x4FE510: Malloc1 (tools.c:2236)
==23356==    by 0x4E230B: EndSort (sort.c:741)
==23356==    by 0x4BFD85: CreateExpression (ratio.c:2037)
==23356==    by 0x4C141C: GCDfunction (ratio.c:977)
==23356==    by 0x4B7725: Generator (proces.c:3688)
==23356==    by 0x4B7C7A: Generator (proces.c:3886)
==23356==    by 0x4B93FA: Processor (proces.c:404)
==23356==    by 0x437480: DoExecute (execute.c:812)
==23356==    by 0x44D8FE: ExecModule (module.c:274)
==23356==    by 0x4AF44B: PreProcessor (pre.c:962)
==23356==    by 0x4E7A30: main (startup.c:1605)
==23356==
==23356== Invalid read of size 4
==23356==    at 0x4C0392: GCDterms (ratio.c:2224)
==23356==    by 0x4C1518: GCDfunction (ratio.c:1000)
==23356==    by 0x4B7725: Generator (proces.c:3688)
==23356==    by 0x4B7C7A: Generator (proces.c:3886)
==23356==    by 0x4B93FA: Processor (proces.c:404)
==23356==    by 0x437480: DoExecute (execute.c:812)
==23356==    by 0x44D8FE: ExecModule (module.c:274)
==23356==    by 0x4AF44B: PreProcessor (pre.c:962)
==23356==    by 0x4E7A30: main (startup.c:1605)
==23356==  Address 0x570977c is 4 bytes before a block of size 96 alloc'd
==23356==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==23356==    by 0x4FE510: Malloc1 (tools.c:2236)
==23356==    by 0x4E230B: EndSort (sort.c:741)
==23356==    by 0x4BFD85: CreateExpression (ratio.c:2037)
==23356==    by 0x4C141C: GCDfunction (ratio.c:977)
==23356==    by 0x4B7725: Generator (proces.c:3688)
==23356==    by 0x4B7C7A: Generator (proces.c:3886)
==23356==    by 0x4B93FA: Processor (proces.c:404)
==23356==    by 0x437480: DoExecute (execute.c:812)
==23356==    by 0x44D8FE: ExecModule (module.c:274)
==23356==    by 0x4AF44B: PreProcessor (pre.c:962)
==23356==    by 0x4E7A30: main (startup.c:1605)
==23356==

Time =       0.09 sec    Generated terms =          1
             gcd         Terms in output =          1
                         Bytes used      =         20
FORM 4.1 (Jun  6 2017, v4.1-20131025-347-g76561be) 64-bits  Run: Wed Jun  7 00:51:07 2017
    S x;
    L p1 = 0;
    L p2 = x+x^2;
    L gcd = gcd_(p2,p1);
    .end

Time =       0.06 sec    Generated terms =          0
              p1         Terms in output =          0
                         Bytes used      =          4

Time =       0.08 sec    Generated terms =          2
              p2         Terms in output =          2
                         Bytes used      =         60
==23416== Invalid read of size 4
==23416==    at 0x4BFDDD: GCDterms (ratio.c:2063)
==23416==    by 0x4C1518: GCDfunction (ratio.c:1000)
==23416==    by 0x4B7725: Generator (proces.c:3688)
==23416==    by 0x4B7C7A: Generator (proces.c:3886)
==23416==    by 0x4B93FA: Processor (proces.c:404)
==23416==    by 0x437480: DoExecute (execute.c:812)
==23416==    by 0x44D8FE: ExecModule (module.c:274)
==23416==    by 0x4AF44B: PreProcessor (pre.c:962)
==23416==    by 0x4E7A30: main (startup.c:1605)
==23416==  Address 0x1c9a566c is 4 bytes before a block of size 96 alloc'd
==23416==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==23416==    by 0x4FE510: Malloc1 (tools.c:2236)
==23416==    by 0x4E230B: EndSort (sort.c:741)
==23416==    by 0x4BFD85: CreateExpression (ratio.c:2037)
==23416==    by 0x4C141C: GCDfunction (ratio.c:977)
==23416==    by 0x4B7725: Generator (proces.c:3688)
==23416==    by 0x4B7C7A: Generator (proces.c:3886)
==23416==    by 0x4B93FA: Processor (proces.c:404)
==23416==    by 0x437480: DoExecute (execute.c:812)
==23416==    by 0x44D8FE: ExecModule (module.c:274)
==23416==    by 0x4AF44B: PreProcessor (pre.c:962)
==23416==    by 0x4E7A30: main (startup.c:1605)
==23416==
==23416== Invalid read of size 4
==23416==    at 0x4C0392: GCDterms (ratio.c:2224)
==23416==    by 0x4C1518: GCDfunction (ratio.c:1000)
==23416==    by 0x4B7725: Generator (proces.c:3688)
==23416==    by 0x4B7C7A: Generator (proces.c:3886)
==23416==    by 0x4B93FA: Processor (proces.c:404)
==23416==    by 0x437480: DoExecute (execute.c:812)
==23416==    by 0x44D8FE: ExecModule (module.c:274)
==23416==    by 0x4AF44B: PreProcessor (pre.c:962)
==23416==    by 0x4E7A30: main (startup.c:1605)
==23416==  Address 0x1c9a566c is 4 bytes before a block of size 96 alloc'd
==23416==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==23416==    by 0x4FE510: Malloc1 (tools.c:2236)
==23416==    by 0x4E230B: EndSort (sort.c:741)
==23416==    by 0x4BFD85: CreateExpression (ratio.c:2037)
==23416==    by 0x4C141C: GCDfunction (ratio.c:977)
==23416==    by 0x4B7725: Generator (proces.c:3688)
==23416==    by 0x4B7C7A: Generator (proces.c:3886)
==23416==    by 0x4B93FA: Processor (proces.c:404)
==23416==    by 0x437480: DoExecute (execute.c:812)
==23416==    by 0x44D8FE: ExecModule (module.c:274)
==23416==    by 0x4AF44B: PreProcessor (pre.c:962)
==23416==    by 0x4E7A30: main (startup.c:1605)
==23416==

Time =       0.10 sec    Generated terms =          1
             gcd         Terms in output =          1
                         Bytes used      =         20

@tueda tueda added the bug Something isn't working label Jun 7, 2017
@vermaseren
Copy link
Owner

vermaseren commented Jun 7, 2017 via email

@crmafra
Copy link

crmafra commented Jun 7, 2017 via email

@tueda
Copy link
Collaborator Author

tueda commented Jun 7, 2017

The gcd of 0 and any other number makes no sense.

It seems that mathematically it makes sense or at least there is some convention.

Mathematica 11.0.1

In[1]:= PolynomialGCD[0, 1+x]

Out[1] = 1 + x

In[2]:= PolynomialGCD[0, 0]

Out[2] = 0

Python 3.6.1

In [1]: import math

In [2]: math.gcd(0, 12)
Out[2]: 12

In [3]: math.gcd(0, 0)
Out[2]: 0

ginsh 1.7.2

> gcd(0, 1+x);
1+x
> gcd(0, 0);
0

gp/pari 2.9.2

? gcd(0, 1+x)
%1 = x + 1
? gcd(0, 0)
%2 = 0

GCD(0,0) = 0 would be true in mathematics, e.g., https://math.stackexchange.com/questions/495119/what-is-gcd0-0, but in practice I'm happy with the fact that FORM gives a wrong answer for gcd_(0,0) -> 1 because usually what we want to do after taking a GCD is dividing by the GCD:

$gcd = gcd_($a,$b);
$a = div_($a,$gcd);
$b = div_($b,$gcd);

If gcd_(0,0) gives 0, I need to put more code to check if the GCD is 0 before the divisions.

@vermaseren
Copy link
Owner

vermaseren commented Jun 7, 2017 via email

@crmafra
Copy link

crmafra commented Jun 7, 2017 via email

@spj101
Copy link
Contributor

spj101 commented Jun 7, 2017

I believe @tueda and @crmafra are correct that gcd(0,a)=a when a !=0. This follows from 0/a=0 (i.e... a is a divisor of 0) this is not a convention.

That gcd(0,0)=0 is a (popular) convention. Perhaps this is convenient for polynomial gcd since we can compute gcd(0,a)=a with general a then set a=0 consistently.

@tueda
Copy link
Collaborator Author

tueda commented Jun 8, 2017

After applying the patch 615cbcd, still broken...

FORM 4.1 (Jun  8 2017, v4.1-20131025-348-g615cbcd) 64-bits  Run: Thu Jun  8 14:59:51 2017
    S x;
    #$a = 0;
    #$b = 1+x;
    #$c = gcd_($a,$b);
==28608== Invalid read of size 4
==28608==    at 0x4BFDDD: GCDterms (ratio.c:2073)
==28608==    by 0x4C0519: GCDfunction3 (ratio.c:1146)
==28608==    by 0x4C1850: GCDfunction (ratio.c:1051)
==28608==    by 0x4B7725: Generator (proces.c:3688)
==28608==    by 0x42E4CE: CatchDollar (dollar.c:112)
==28608==    by 0x4AF710: PreProcessor (pre.c:1050)
==28608==    by 0x4E7B4B: main (startup.c:1605)
==28608==  Address 0x57094cc is 4 bytes before a block of size 8 alloc'd
==28608==    at 0x4A05A57: malloc (vg_replace_malloc.c:299)
==28608==    by 0x4FE62B: Malloc1 (tools.c:2236)
==28608==    by 0x4C04E6: GCDfunction3 (ratio.c:1142)
==28608==    by 0x4C1850: GCDfunction (ratio.c:1051)
==28608==    by 0x4B7725: Generator (proces.c:3688)
==28608==    by 0x42E4CE: CatchDollar (dollar.c:112)
==28608==    by 0x4AF710: PreProcessor (pre.c:1050)
==28608==    by 0x4E7B4B: main (startup.c:1605)

... (many errors) ...

Full Log...

tueda added a commit that referenced this issue Jun 8, 2017
@tueda
Copy link
Collaborator Author

tueda commented Jun 8, 2017

I found cases that are still broken...

FORM 4.1 (Jun  8 2017, v4.1-20131025-351-g31c5798) 64-bits  Run: Thu Jun  8 22:13:09 2017
    S x;
    L F1 = gcd_(100000000000000000000,0);
    L F2 = gcd_(-x,0);
    P;
    .end

Time =       0.00 sec    Generated terms =          0
              F1         Terms in output =          0
                         Bytes used      =          4

Time =       0.00 sec    Generated terms =          0
              F2         Terms in output =          0
                         Bytes used      =          4

   F1 = 0;

   F2 = 0;

tueda added a commit to tueda/form that referenced this issue Jun 8, 2017
@tueda
Copy link
Collaborator Author

tueda commented Jun 10, 2017

It seems that 7cf7c42 finally fixes bugs for gcd_(0,0), gcd_(a,0) and gcd_(0,a). I close this issue. (But still we have #196.)

@tueda tueda closed this as completed Jun 10, 2017
@spj101
Copy link
Contributor

spj101 commented Jun 22, 2017

Thanks a lot for quickly fixing this. With 541f847 on Mac everything runs as expected.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants