GithubHelp home page GithubHelp logo

Comments (3)

jnmartin84 avatar jnmartin84 commented on July 26, 2024

The following is a small test program that can demonstrate the aforementioned bug in a reproducible fashion.

uint8_t *memory_to_test = n64_malloc(127);

for (uint8_t i=0;i<127;i++) {
    memory_to_test[i] = i+1;
}

uint8_t *second_buffer = n64_malloc(127);
n64_memmove(second_buffer, memory_to_test, 127);

for (uint8_t i=0;i<127;i++) {
    if(memory_to_test[i] != second_buffer[i]) {
        printf("%d != %d @ %d\n", memory_to_test[i], second_buffer[i], i);
    }
}

n64_free(second_buffer);
n64_free(memory_to_test);

The output of the test program is:

125 != 0 @ 124
126 != 0 @ 125
127 != 0 @ 126

from 64doom.

jnmartin84 avatar jnmartin84 commented on July 26, 2024

The following is a corrected version of the "n64_memmove" function.

I will push this change to the GIT repository by 2016-05-05 00:00:00 EST.

void *n64_memmove(void *dest, const void *src, size_t size)
{
    int i;
    void *tmp = (void *)n64_malloc(size);

    if (ALIGNED(dest) && ALIGNED(src))
    {
        uint32_t *wd = (uint32_t*)dest;
        uint32_t *ws = (uint32_t*)src;

        int size_in_uint32_ts = size >> 2;
        int size_in_bytes = size % 4;

        uint8_t *bd = (uint8_t*)(dest + (size_in_uint32_ts << 2));
        uint8_t *bs = (uint8_t*)(src + (size_in_uint32_ts << 2));

        uint32_t *wtmp;
        uint8_t *btmp;

        wtmp = (uint32_t*)tmp;

        for (i=0;i<size_in_uint32_ts;i++)
        {
            wtmp[i] = ws[i];
        }

        for (i=0;i<size_in_uint32_ts;i++)
        {
            wd[i] = wtmp[i];
        }

        btmp = (uint8_t*)(tmp + (size_in_uint32_ts << 2));

        for (i=0;i<size_in_bytes;i++)
        {
            btmp[i] = bs[i];
        }

        for (i=0;i<size_in_bytes;i++)
        {
            bd[i] = btmp[i];
        }
    }
    else
    {
        uint8_t *d = (uint8_t*)dest;
        uint8_t *s = (uint8_t*)src;

        uint8_t *btmp = (uint8_t*)tmp;

        for (i=0;i<size;i++)
        {
            btmp[i] = s[i];
        }

        for (i=0;i<size;i++)
        {
            d[i] = btmp[i];
        }
    }

    n64_free(tmp);

    return dest;
}

from 64doom.

jnmartin84 avatar jnmartin84 commented on July 26, 2024

resolved, no longer using

from 64doom.

Related Issues (20)

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.