mazaczysko / krusgen Goto Github PK
View Code? Open in Web Editor NEWKruskal's algorithm maze generator
License: GNU General Public License v3.0
Kruskal's algorithm maze generator
License: GNU General Public License v3.0
I wanted to profile Krusgen and after running for more than an hour it crashed.
$ sudo perf stat -B -e cache-references,cache-misses ./krusgen -x 65533 -y 1023 > /dev/null
./krusgen: Segmentation fault
Performance counter stats for './krusgen -x 65533 -y 1023':
197 639 084 285 cache-references
118 016 289 503 cache-misses # 59,713 % of all cache refs
4507,111402809 seconds time elapsed
By the way, the 60% cache miss rate isn't great.
The error messages are misleading:
$ ./krusgen -x -y 9
./krusgen: bad value for -y
Here the value for -x
is clearly the invalid one. It works the other way around too:
$ ./krusgen -y -x 9
./krusgen: bad value for -x
I think you broke something again
$ ./krusgen -x
./krusgen: bad value for ./krusgen
There seems to be a problem with FLAG_FRAME
flag handling. Logical operator is used instead of bitwise one.
Related code fragment:
Lines 59 to 60 in 8478f0b
I cannot use krusgen to generate 100 mazes at once, because all of them turn out to be identical.
To reproduce:
mkdir mazes
for i in {1..100}; do ./krusgen -t mazes/$i.txt -x 15 -y 15; done;
When -t <filename> -h
are both passed to Krusgen in that specific order, the output file is created before the help message appears. The output file contains no data, which is an unusual and unexpected behavior. This bug affects -b
option too.
Things get even worse when both -b
and -t
options are used. Then program doesn't even output proper error message (krusgen: cannot export to .bmp and .txt files at once
) and both files are created.
Memory allocated in mazeInit()
is never freed.
If I want to generate many labyrinths using a bash for loop, all of them are identical:
for i in {1..10}; do ./krusgen > "out/$i.txt"; done
This makes the program unusable in cases where more than one maze is needed. The program doesn't support multiple files output and produces unsatisfactory results when it's repeatedly called instead.
Now it leaks even when no maze is generated.
$ ./krusgen -x 100 -y 100
./krusgen: dimensions must be odd!
=================================================================
==3335==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 800 byte(s) in 1 object(s) allocated from:
#0 0x7f6443c7e639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x562e620a32b0 in mazeInit (/home/j/Desktop/krusgen/krusgen+0x42b0)
#2 0x562e620a16e5 in main (/home/j/Desktop/krusgen/krusgen+0x26e5)
#3 0x7f6443a26b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
Indirect leak of 12400 byte(s) in 100 object(s) allocated from:
#0 0x7f6443c7e639 in __interceptor_calloc /build/gcc/src/gcc/libsanitizer/asan/asan_malloc_linux.cpp:154
#1 0x562e620a32fd in mazeInit (/home/j/Desktop/krusgen/krusgen+0x42fd)
#2 0x562e620a16e5 in main (/home/j/Desktop/krusgen/krusgen+0x26e5)
#3 0x7f6443a26b24 in __libc_start_main (/usr/lib/libc.so.6+0x27b24)
SUMMARY: AddressSanitizer: 13200 byte(s) leaked in 101 allocation(s).
Did you actually check if you fixed the leaks or just thought you fixed them?
For example, this invocation produces only one file named c
:
$ ./krusgen -x 15 -y 15 -w 3 -t a -t b -t c
Krusgen crashes when given maze dimensions are too big. Affects both -x
and -y
options.
This behavior is likely caused by ignoring calloc
errors returned by mazeInit
routine.
Also, some reasonable upper maze size limit should be introduced.
who can I take in parameters odd and even size of maze
thanks
The provided makefile just doesn't work
cd libobos && make clean
make[1]: Entering directory '/home/j/Desktop/krusgen/libobos'
rm -rf obj
rm -rf lib
make[1]: Leaving directory '/home/j/Desktop/krusgen/libobos'
rm krusgen
rm: cannot remove 'krusgen': No such file or directory
make: [makefile:35: clean] Error 1 (ignored)
cd libobos && make all
make[1]: Entering directory '/home/j/Desktop/krusgen/libobos'
mkdir obj
mkdir lib
gcc -c src/obos.c -o obj/obos.o
ar -cvq lib/libobos.a obj/obos.o
a - obj/obos.o
ar -t lib/libobos.a
obos.o
make[1]: Leaving directory '/home/j/Desktop/krusgen/libobos'
gcc -o krusgen ./src/*.c -Ilibobos/include -lobos -Llibobos/lib -Wall
/usr/bin/ld: /tmp/ccgrei2I.o:(.bss+0x0): multiple definition of `maze'; /tmp/cckw6CE3.o:(.bss+0x0): first defined here
collect2: error: ld returned 1 exit status
make: *** [makefile:28: all] Error 1
Address sanitizer tells me that there are memory leaks in your program. You should probably check that:
$ ./krusgen -x 25 -y 25 > /dev/null
=================================================================
==14318==ERROR: LeakSanitizer: detected memory leaks
Direct leak of 200 byte(s) in 1 object(s) allocated from:
#0 0x4d9f88 in calloc (/home/j/Projects/C/mess/milosz/krusgen/krusgen+0x4d9f88)
#1 0x518477 in mazeInit /home/j/Projects/C/mess/milosz/krusgen/./src/maze.c:40:34
#2 0x51332b in main /home/j/Projects/C/mess/milosz/krusgen/./src/krusgen.c:71:8
#3 0x7f0ba14e6b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
Direct leak of 200 byte(s) in 1 object(s) allocated from:
#0 0x4d9f88 in calloc (/home/j/Projects/C/mess/milosz/krusgen/krusgen+0x4d9f88)
#1 0x518477 in mazeInit /home/j/Projects/C/mess/milosz/krusgen/./src/maze.c:40:34
#2 0x512bf3 in main /home/j/Projects/C/mess/milosz/krusgen/./src/krusgen.c:54:8
#3 0x7f0ba14e6b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
Indirect leak of 3100 byte(s) in 25 object(s) allocated from:
#0 0x4d9f88 in calloc (/home/j/Projects/C/mess/milosz/krusgen/krusgen+0x4d9f88)
#1 0x518615 in mazeInit /home/j/Projects/C/mess/milosz/krusgen/./src/maze.c:42:37
#2 0x512bf3 in main /home/j/Projects/C/mess/milosz/krusgen/./src/krusgen.c:54:8
#3 0x7f0ba14e6b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
Indirect leak of 2500 byte(s) in 25 object(s) allocated from:
#0 0x4d9f88 in calloc (/home/j/Projects/C/mess/milosz/krusgen/krusgen+0x4d9f88)
#1 0x518615 in mazeInit /home/j/Projects/C/mess/milosz/krusgen/./src/maze.c:42:37
#2 0x51332b in main /home/j/Projects/C/mess/milosz/krusgen/./src/krusgen.c:71:8
#3 0x7f0ba14e6b96 in __libc_start_main /build/glibc-OTsEL5/glibc-2.27/csu/../csu/libc-start.c:310
SUMMARY: AddressSanitizer: 6000 byte(s) leaked in 52 allocation(s).
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.