Weird pointer issues
Nobody has claimed this yet.
Assessment
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Newbie friendliness
- 35/100
Research direction
Reproduce the call at src/mapgenerator.c:1322 under gdb, then read the ht_put expansion and implementation around src/ht.h:563. Compare how start reaches ht__put and determine why the observed key differs; done means the pointer behavior is explained and the reported segmentation fault or argument discrepancy is corrected.
Written by the indexing model from the issue text.
Description
I'm having a very strange issue and I don't know how to further debug. I'm trying to implement this hashtable into some code I wrote (in my "sprites" repo branch "htbroken") and the key pointer argument is changing when I step into the "ht__put" function with a debugger. Here's the relevant section of code just copy pasted:
struct coord
{
int x;
int y;
};
Ht(struct coord *, struct coord *) camefrom =
{
.count = 0,
.hasheq = ht_mem_hasheq,
.impl_filled_slots = 0,
.impl_capacity = 0,
};
Ht(struct coord *, float *) costsofar =
{
.count = 0,
.hasheq = ht_mem_hasheq,
.impl_filled_slots = 0,
.impl_capacity = 0,
};
float *dist = NULL;
int i;
*no = 0;
pq_insert(frontier, 0, start);
*ht_put(&camefrom, start) = start;
I put the initializations for the ht structs (i.e. .count = 0, .impl_filled_slots = 0) because it was seg faulting after picking up some garbage from memory I guess.
I run this in gdb and add a break point at that first "ht_put":
(gdb) break mapgenerator.c:1322
Breakpoint 1 at 0x1817a: file src/mapgenerator.c, line 1322.
(gdb) run
...
1322 *ht_put(&camefrom, start) = start;
(gdb) print start
$1 = (struct coord *) 0x7fffffffd670
(gdb) s
ht__put (ht=0x7fffffffd530, key=0x7fffffffd590, l=...) at src/ht.h:563
563 ht__expand(ht, l);
You can see I put "start" in as a key, it ends in d670. Then the "key" argument comes out ending with d590. I am totally at a loss here. Maybe there some macro stuff I'm not understanding?
- Dominant language
- C++
- Stars
- 359
- Forks
- 2
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from tsoding/ht.h
Similar issues
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
good first issue
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
ros2/message_filters#338 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
subsurface/subsurface#4984 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
flutter-webrtc/flutter-webrtc#2206 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
google-ai-edge/LiteRT-LM#3739 ·