Code Monkey home page Code Monkey logo

algorithm-interpretor's People

Contributors

mr-monster-0248 avatar

Stargazers

 avatar  avatar

Watchers

 avatar  avatar

algorithm-interpretor's Issues

Valgrind detects many errors (at commit ca9d34ecf6bdc6ee96e99b1ff4a0dc9d722881e1) (added support of parentheses elements in calculus)

So, after implementing the function compute_numeric_line() in operations.c I tried debugging the program using Valgrind.
There are still a lot of errors that occurs, here is what I got:

Welcome to the algorithmic interpreter
Type "exit" to exit the interpreter or "help" to see the manual

>>> 1 + ((2 * 3) + 15) + (12 * 12)
==9404== Invalid read of size 1
==9404==    at 0x402504: get_line_elements (analyze.c:121)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x520427d is 0 bytes after a block of size 13 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4023EA: get_line_elements (analyze.c:378)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x402504: get_line_elements (analyze.c:121)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x4046EB: compute_numeric_line (operations.c:566)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5204a56 is 0 bytes after a block of size 6 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4023EA: get_line_elements (analyze.c:378)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x402EB6: main (main.c:85)
==9404== 
==9404== Invalid read of size 4
==9404==    at 0x4047B7: compute_numeric_line (operations.c:579)
==9404==    by 0x4046EB: compute_numeric_line (operations.c:566)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5205120 is 0 bytes inside a block of size 16 free'd
==9404==    at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4047B2: compute_numeric_line (operations.c:577)
==9404==    by 0x4046EB: compute_numeric_line (operations.c:566)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Block was alloc'd at
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x401685: get_line_elements (analyze.c:194)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x4046EB: compute_numeric_line (operations.c:566)
==9404==    by 0x402EB6: main (main.c:85)
==9404== 
==9404== Invalid read of size 4
==9404==    at 0x4047B7: compute_numeric_line (operations.c:579)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5204c50 is 0 bytes inside a block of size 16 free'd
==9404==    at 0x4C2EDEB: free (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4047B2: compute_numeric_line (operations.c:577)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Block was alloc'd at
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x401685: get_line_elements (analyze.c:194)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x402EB6: main (main.c:85)
==9404== 
==9404== Invalid write of size 1
==9404==    at 0x4EAA1D9: vsprintf (iovsprintf.c:43)
==9404==    by 0x4E8F9C6: sprintf (sprintf.c:32)
==9404==    by 0x403C41: compute__int_operation (operations.c:419)
==9404==    by 0x40482D: compute_numeric_line (operations.c:592)
==9404==    by 0x4046EB: compute_numeric_line (operations.c:566)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5205533 is 0 bytes after a block of size 3 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x402EB6: main (main.c:85)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x4C31063: strcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x404789: compute_numeric_line (operations.c:573)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5205533 is 0 bytes after a block of size 3 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x404560: compute_numeric_line (operations.c:532)
==9404==    by 0x402EB6: main (main.c:85)
==9404== 
==9404== Invalid write of size 1
==9404==    at 0x4EAA1D9: vsprintf (iovsprintf.c:43)
==9404==    by 0x4E8F9C6: sprintf (sprintf.c:32)
==9404==    by 0x403F08: compute__int_operation (operations.c:451)
==9404==    by 0x40482D: compute_numeric_line (operations.c:592)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x4E75654: ____strtol_l_internal (strtol_l.c:433)
==9404==    by 0x40301D: convertTo_int (operations.c:40)
==9404==    by 0x40316A: int_addition (operations.c:84)
==9404==    by 0x403ED7: compute__int_operation (operations.c:451)
==9404==    by 0x40482D: compute_numeric_line (operations.c:592)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid write of size 1
==9404==    at 0x4EB567B: _IO_default_xsputn (genops.c:450)
==9404==    by 0x4E87DFF: vfprintf (vfprintf.c:1631)
==9404==    by 0x4EAA1CA: vsprintf (iovsprintf.c:42)
==9404==    by 0x4E8F9C6: sprintf (sprintf.c:32)
==9404==    by 0x403F08: compute__int_operation (operations.c:451)
==9404==    by 0x40482D: compute_numeric_line (operations.c:592)
==9404==    by 0x402EB6: main (main.c:85)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x4C30F74: strlen (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4EA969B: puts (ioputs.c:35)
==9404==    by 0x402EC9: main (main.c:87)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x4EB32ED: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1301)
==9404==    by 0x4EA9737: puts (ioputs.c:40)
==9404==    by 0x402EC9: main (main.c:87)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
==9404== Invalid read of size 1
==9404==    at 0x4C35086: __GI_mempcpy (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4EB3241: _IO_file_xsputn@@GLIBC_2.2.5 (fileops.c:1319)
==9404==    by 0x4EA9737: puts (ioputs.c:40)
==9404==    by 0x402EC9: main (main.c:87)
==9404==  Address 0x5203cb2 is 0 bytes after a block of size 2 alloc'd
==9404==    at 0x4C2FD5F: realloc (in /usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so)
==9404==    by 0x4017F6: get_line_elements (analyze.c:217)
==9404==    by 0x402DBF: main (main.c:52)
==9404== 
166

>>> 

So, the result seems to be good, here is the heap summary (I typed "exit" just after the previous calculus to exit the program properly):

>>> exit

Goodbye!

==9404== 
==9404== HEAP SUMMARY:
==9404==     in use at exit: 0 bytes in 0 blocks
==9404==   total heap usage: 103 allocs, 103 frees, 3,302 bytes allocated
==9404== 
==9404== All heap blocks were freed -- no leaks are possible
==9404== 
==9404== For counts of detected and suppressed errors, rerun with: -v
==9404== ERROR SUMMARY: 16 errors from 12 contexts (suppressed: 0 from 0)

So, these issues remains to solve, even if the program seems to work with no memory leaks

Program crashing when launched on a UNIX based system

When using a UNIX based system, the program may eventually crash after having entered a line with at least two elements.
Here is what I got when the program crashed:

*** Error in `./ExeTest': free(): invalid next size (fast): 0x00000000011ef9f0 ***
======= Backtrace: =========
/lib/x86_64-linux-gnu/libc.so.6(+0x777e5)[0x7f6db53747e5]
/lib/x86_64-linux-gnu/libc.so.6(+0x7fe0a)[0x7f6db537ce0a]
/lib/x86_64-linux-gnu/libc.so.6(cfree+0x4c)[0x7f6db538098c]
./ExeTest[0x401040]
./ExeTest[0x40264f]
/lib/x86_64-linux-gnu/libc.so.6(__libc_start_main+0xf0)[0x7f6db531d830]
./ExeTest[0x400b19]
======= Memory map: ========
00400000-00404000 r-xp 00000000 08:05 1843670                            /home/camboy/.git/C-project-3/ExeTest
00603000-00604000 r--p 00003000 08:05 1843670                            /home/camboy/.git/C-project-3/ExeTest
00604000-00605000 rw-p 00004000 08:05 1843670                            /home/camboy/.git/C-project-3/ExeTest
011ef000-01210000 rw-p 00000000 00:00 0                                  [heap]
7f6db0000000-7f6db0021000 rw-p 00000000 00:00 0 
7f6db0021000-7f6db4000000 ---p 00000000 00:00 0 
7f6db50e7000-7f6db50fd000 r-xp 00000000 08:05 1315938                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f6db50fd000-7f6db52fc000 ---p 00016000 08:05 1315938                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f6db52fc000-7f6db52fd000 rw-p 00015000 08:05 1315938                    /lib/x86_64-linux-gnu/libgcc_s.so.1
7f6db52fd000-7f6db54bc000 r-xp 00000000 08:05 1316022                    /lib/x86_64-linux-gnu/libc-2.23.so
7f6db54bc000-7f6db56bc000 ---p 001bf000 08:05 1316022                    /lib/x86_64-linux-gnu/libc-2.23.so
7f6db56bc000-7f6db56c0000 r--p 001bf000 08:05 1316022                    /lib/x86_64-linux-gnu/libc-2.23.so
7f6db56c0000-7f6db56c2000 rw-p 001c3000 08:05 1316022                    /lib/x86_64-linux-gnu/libc-2.23.so
7f6db56c2000-7f6db56c6000 rw-p 00000000 00:00 0 
7f6db56c6000-7f6db56ec000 r-xp 00000000 08:05 1315917                    /lib/x86_64-linux-gnu/ld-2.23.so
7f6db58d1000-7f6db58d4000 rw-p 00000000 00:00 0 
7f6db58e8000-7f6db58eb000 rw-p 00000000 00:00 0 
7f6db58eb000-7f6db58ec000 r--p 00025000 08:05 1315917                    /lib/x86_64-linux-gnu/ld-2.23.so
7f6db58ec000-7f6db58ed000 rw-p 00026000 08:05 1315917                    /lib/x86_64-linux-gnu/ld-2.23.so
7f6db58ed000-7f6db58ee000 rw-p 00000000 00:00 0 
7ffc8fcc5000-7ffc8fce6000 rw-p 00000000 00:00 0                          [stack]
7ffc8fdb6000-7ffc8fdb8000 r--p 00000000 00:00 0                          [vvar]
7ffc8fdb8000-7ffc8fdba000 r-xp 00000000 00:00 0                          [vdso]
ffffffffff600000-ffffffffff601000 r-xp 00000000 00:00 0                  [vsyscall]
Abandon (core dumped)

Memory leaks

There are a lot of memory leaks that occurs when running the program.
Since the program is looping on itself, the leaks are bigger at each lap.

We have to fix these memory leaks so that the program will be 100% optimized!

We may use valgrind for this:
gcc sources/*.c -o ExeTest -Wall -g
valgrind --leak-check=full --track-origins=yes --show-leak-kinds=all ./ExeTest
These lines may be the ones that will help us to track all leaks

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.