Code Monkey home page Code Monkey logo

datastructs-c's People

Contributors

marekweb 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

Watchers

 avatar  avatar  avatar  avatar  avatar

datastructs-c's Issues

arraylist_remove: wrong length argument for arraylist_memshift

As arraylist_remove is written, it reads memory from one position where it might not be readable.

The code is:

void* value = l->body[index];
arraylist_memshift(l->body + index + 1, -1, l->size - index);
l->size--;
return value;

Let say I have this body: {0, 1, 2, 3, 4}, with size = capacity = 5.
if I do arraylist_remove(l, 2), it will try to do:
arraylist_memshift(l->body + 3, -1, 3)
That will try to copy body[3] into body[2], body[4] into body[3], and body[5] into body[4].
But we can't access body[5], because capacity < 6.
This might not throw an error, but it's not correct.

Also, it could just be me misunderstanding the code

hashtable_remove disrupts hashtable_find_slot

If you remove an entry using hashtable_remove, you set its key = NULL. But if you then call hashtable_find_slot, and it linearly probes to the site of the deleted entry, seeing key = NULL will make the routine think this is the end of the linear probing chain, and the routine will falsely return the claim that the key was not found, instead of continuing to search past the removed entry.

A quick fix is to set a removed entry's key to some arbitrary value, say "XYZZY" or "\0", and to ban both NULL and "\0" from being permissible keys in the hashtable.

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.