Code Monkey home page Code Monkey logo

chip-8's Introduction

Leonardo Folgoni

Computer science engineering student and software developer at Gulliver

chip-8's People

Contributors

f0lg0 avatar guijan avatar khengari77 avatar themilkies avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

chip-8's Issues

Many bugs at main.c lines 20 and 25

At line 20 of main.c, check_rom() is called. Soon after, load_rom() is called at line 25.
This causes several problems:

check_rom() fopen()s a file and doesn't close it before returning, causing the open FILE to leak. Additionally, it unnecessarily makes any further attempt at opening the file implementation-defined behavior, although I don't know of a C implementation where opening the same file multiple times doesn't just work.

The load_rom() call also fopen()s the same file, without any checking of return values. A non-existing file is not the only cause for an error return of fopen().

Even if the above issues are fixed, there is an inherent TOCTTOU error in doing this. There is no guarantee that the file will still exist by the time load_rom() is called.

The fix is to get rid of the check_rom() function and check the return value of fopen() in load_rom().

Improving load_rom()

As suggested by a oh5nxo on Reddit, the function load_rom() could be improved in the following way:

void load_rom(char* filename) {
    FILE* fp = fopen(filename, "rb");

    // read program size into memory
    fread(memory + 0x200, 1, sizeof(memory) - 0x200, fp);

    fclose(fp);
}

From a quick first test, it seems good. Waiting to update to give it a better look.

A mistake in implementing 0xFX55

`
// FX55: Stores V0 through Vx (Vx included) in memory starting
// at addr I.
case 0x0055:
debug_print("[OK] 0x%X: FX55\n", op);

                for (int i = 0; i <= x; i++) {
                    V[i] = memory[I + i];
                }

                pc += 2;
                break;

`

shouldn't this segment of code be like this:

`// FX55: Stores V0 through Vx (Vx included) in memory starting
// at addr I.
case 0x0055:
debug_print("[OK] 0x%X: FX55\n", op);

                for (int i = 0; i <= x; i++) {
                    memory[I + i] = V[i];
                }

                pc += 2;
                break;`

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.