Coder Social home page Coder Social logo

Comments (3)

MarkChenYutian avatar MarkChenYutian commented on June 8, 2024

const arrPtr: C0Pointer = mem.malloc(4 + 4 * ints.length);
arrPtr.setInt32(0, 4); // sizeof(int) = 4
for (let i = 0; i < ints.length; i ++) {
arrPtr.setInt32(4 * (i + 1), ints[i]);
}

Turns out in the native_parse.ts (the implementation of native parse library), when filling an allocated C0 int array with parsed JS value, I'm writing to the pointer instead of the heap memory (ArrayBuffer) the pointer is pointing to.

Going to fix this in next deployment.

from c0vm-ts.

MarkChenYutian avatar MarkChenYutian commented on June 8, 2024

Correct implementation should be:

    // Create a c0 array and fill ints inside it
    const arrPtr: C0Pointer = mem.malloc(4 + 4 * ints.length);
    const arrMem: DataView  = mem.deref(arrPtr);
    arrMem.setInt32(0, 4);      // sizeof(int) = 4
    for (let i = 0; i < ints.length; i ++) {
        arrMem.setInt32(4 * (i + 1), ints[i]);
    }

instead.

from c0vm-ts.

MarkChenYutian avatar MarkChenYutian commented on June 8, 2024

Similar bug in the same file:

const arrPtr: C0Pointer = mem.malloc(4 + 8 * tokens.length);
arrPtr.setInt32(0, 8);
for (let i = 0; i < tokens.length; i ++) {
const tokenPtr = allocate_js_string(mem, tokens[i]);
// Sadly, Safari does not support BigInt (Uint64), so we have
// to do this in two steps
arrPtr.setUint32(4 + 8 * i, tokenPtr.getUint32(0));
arrPtr.setUint32(4 + 8 * i + 4, tokenPtr.getUint32(4));
}
return arrPtr;

Fixed.

from c0vm-ts.

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.