Giter VIP home page Giter VIP logo

huffmancode's People

Contributors

bogdasar1985 avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

huffmancode's Issues

Valgrind screaming!

$ valgrind --track-origins=yes -s ./coder ../sample-2mb-text-file.txt ../res.txt
==18668== Memcheck, a memory error detector
==18668== Copyright (C) 2002-2017, and GNU GPL'd, by Julian Seward et al.
==18668== Using Valgrind-3.15.0 and LibVEX; rerun with -h for copyright info
==18668== Command: ./coder ../sample-2mb-text-file.txt ../res.txt
==18668== 
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x485548A: get_code (huffman.c:68)
==18668==    by 0x1095DA: main (coder.c:53)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x485544E: get_code (huffman.c:70)
==18668==    by 0x1095DA: main (coder.c:53)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x1096DA: main (coder.c:59)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== 
==18668== HEAP SUMMARY:
==18668==     in use at exit: 944 bytes in 2 blocks
==18668==   total heap usage: 16 allocs, 14 frees, 15,504 bytes allocated
==18668== 
==18668== LEAK SUMMARY:
==18668==    definitely lost: 0 bytes in 0 blocks
==18668==    indirectly lost: 0 bytes in 0 blocks
==18668==      possibly lost: 0 bytes in 0 blocks
==18668==    still reachable: 944 bytes in 2 blocks
==18668==         suppressed: 0 bytes in 0 blocks
==18668== Rerun with --leak-check=full to see details of leaked memory
==18668== 
==18668== ERROR SUMMARY: 14 errors from 3 contexts (suppressed: 0 from 0)
==18668== 
==18668== 3 errors in context 1 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x485544E: get_code (huffman.c:70)
==18668==    by 0x1095DA: main (coder.c:53)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== 
==18668== 4 errors in context 2 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x485548A: get_code (huffman.c:68)
==18668==    by 0x1095DA: main (coder.c:53)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== 
==18668== 7 errors in context 3 of 3:
==18668== Conditional jump or move depends on uninitialised value(s)
==18668==    at 0x483EFB8: __strlen_sse2 (in /usr/lib/x86_64-linux-gnu/valgrind/vgpreload_memcheck-amd64-linux.so)
==18668==    by 0x1096DA: main (coder.c:59)
==18668==  Uninitialised value was created by a stack allocation
==18668==    at 0x10933D: main (coder.c:6)
==18668== 
==18668== ERROR SUMMARY: 14 errors from 3 contexts (suppressed: 0 from 0)

Fix memory leaks

Valgrind found a memory leaks, made by merge() function. This function return a pointer received from malloc().

Clean code.

At the moment, design is so bad. I should fix it, while complexity is not too big!

Debug info.

Add a macro for debug information with different levels, such as:

  1. Start and end of different stages of the program.
  2. Size of read/write info.

Very bad interfaces.

We have to design interfaces whose methods can be combined, i.e. a combination of small methods is better than writing one big one.

Add decoder.

To add a decoder, we should write a Huffman Tree at the beginning of file.
When we decode the file, we will have to read and build the tree.

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.