Comments (8)
This project has been fairly widely used, including in several products in at least two companies, so I hesitate to suspect there >is a fundamental issue with the code.
You can add my company, PercayAI . We use it extensively in both our academic and commercial bioinformatics tool backends.
from hashmap.
Make sure to call hashmap_init()
and ensure no error is returned prior to using the hashmap. Does that resolve your issue?
from hashmap.
Yes, I do. hashmap_base_init() will clear the struct but the table pointer is never allocated. It's just null.
from hashmap.
The data structure doesn't allocate any memory until you put or reserve. This is by design. If you are referring to this code in rehash()
Line 187 in dcf30be
What compiler are you using? This code has been tested on GCC and Clang, but I suppose it is possible that it could run into an issue with another compiler. This project has been fairly widely used, including in several products in at least two companies, so I hesitate to suspect there is a fundamental issue with the code.
from hashmap.
Yes that is the code in question. Compiler is clang and the error comes from the memory debugging I have turned on (in Xcode) so it's not a compiler or building problem. With no diagnostics enabled it would run just fine. Personally I prefer 'clean' code in that regard so it would be nice if a null pointer was handled differently here. I changed it to return early if the pointer is null without doing the comparison.
from hashmap.
I would argue that there is nothing unclean about &old_table[old_size]
, since it is identical to &(*(old_table + old_size))
. Nothing actually attempts to access the memory at old_table + old_size
= 0 + 0
= 0
.
That said, we could certainly change the code to avoid triggering static analysis tools that aren't aware of this.
for (entry = old_table; entry < old_table + old_size; ++entry) {
Would you like to put up a pull request with the changes needed to satisfy your tool?
from hashmap.
Yeah I don't really claim the code is unclean, just that the memory diagnostic is warning about it when running the code and I like to avoid that even though it's something that would be turned off in a release build. Same as I prefer to get any compiler warnings fixed when building.
Overall I like the hashmap so far. I was looking for something that is simple, I can provide the key, hash and compare functions and does not depend on lots of STL stuff.
The simple fix that works is to return right before the for-loop if old_table is NULL. That is the end result even if the for-loop comparison is done.
if (old_table == NULL) return 0;
from hashmap.
The data structure doesn't allocate any memory until you put or reserve. This is by design. If you are referring to this code in
rehash()
Line 187 in dcf30be
, the operation on the null pointer is not an issue, because we are never accessing memory at that location. It is just calculating an offset.What compiler are you using? This code has been tested on GCC and Clang, but I suppose it is possible that it could run into an issue with another compiler. This project has been fairly widely used, including in several products in at least two companies, so I hesitate to suspect there is a fundamental issue with the code.
UBSan detect that bit of code as undefined behaviour and should be changed
from hashmap.
Related Issues (13)
- Is this hashmap thread-safe? HOT 1
- A way to use a pointer as key? without compiler warnings HOT 2
- modifying key interface requirements HOT 4
- global hashmap can't be seen outside of where it's declared HOT 6
- Suggestion: Consider add this library to clib https://github.com/clibs/clib? HOT 4
- Traversal error while adding HOT 1
- Add save and load from file HOT 1
- incovenient function type in hashmap_set_key_alloc_funcs HOT 1
- Multiple errors with typeof HOT 1
- Random iteration? HOT 1
- Declaration of non-local variable in 'for' loop HOT 5
- How to build in nodebug mode HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from hashmap.