Coder Social home page Coder Social logo

libtga's Introduction

libtga

libtga is a library to read and write TGA images.

Building and installing

Libtga uses the CMake build system.

Bugs

Please open an issue at https://github.com/madebr/libtga/issues.

License

  • Libtga is released under the GNU Lesser General Public License.
  • The example programs are released under the GNU General Public License.

For more information on the licenses see the file COPYING in the project's root directory and the corresponding sub directories.

Online

Authors

See the AUTHORS file.

libtga's People

Contributors

madebr avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

libtga's Issues

Quite a few bugs throughout the code

I'm leaving this issue as a warning to those who want to use this library. This library has a lot of fundamental design issues and bugs that make it unusable, except in the absolute best of cases, without fixing it up yourself.

To list a few of the issues:

  1. TGAReadImage() and multiple other functions returns 0 when an error occurs, but they also return TGA_OK when no error has occurred which is a macro that resolves to 0. Thus, the affected functions never return anything but TGA_OK to outside code even if an error occurs which is very misleading. All return statements should return tga->last or the functions should return void to partially fix this and prevent misuse.
  2. Some branches within TGAReadHeader() free the TGA* pointer passed into the function when an error occurs, but not all of them. When it does free the pointer, it is difficult to avoid double freeing due to the function always returning TGA_OK and when it freed the structure which would have otherwise contained the last error code. It's not really feasible for a developer using the library to know whether or not the pointer was freed without accessing freed memory. When there are open functions in a library it's usually best practice to only free their returned structure with an explicit close function which is not the case with libtga. If freeing the pointer inside the function is necessary, then a pointer reference should be passed in which should become nulled after freeing the pointer and can then be tested externally.
  3. TGAReadImage() and TGAWriteImage() accept a TGAData* pointer, but there's no corresponding library function to allocate, initialize, and free such a structure. It's up to the user of the library to zero the structure and handle the freeing of pointers that functions like TGAReadImage() internally assign. Not having a good design pattern for TGAData can introduce quite a few misuses, for example calling TGAReadImage() with the same structure twice will leak memory unless pointers are freed from outside between calls. Another potential misuse is the freeing of memory that was allocated by the library but from outside the library which may attempt to do so using a different allocator, such can be the case if compiling libtga as a shared library using a different runtime library than the program that imports or links against the library.
  4. Certain locations within the library misuse its own functions. For example TGAReadImage() calls TGAReadHeader() and tests for an error by its return code, but that function never returns anything but TGA_OK even of an error occurred.
  5. TGAOpen() does not fully initialize the returned TGA* pointer. For example its 'error' field is left uninitialized, which will likely cause a segmentation fault when an error is handled by TGA_ERROR() elsewhere. This is not intuitive that the developer has to figure this out and null that field themself. If TGAOpen() accepted a TGA* pointer that was allocated and zeroed by the user of the library that would be one thing, but the returned pointer cannot by zeroed easily since it already has some fields populated so the user must explicitly zero only some of the fields.

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.