Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

Weird pointer issues

Aperta
#3 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
35/100
Tipo di issue
Bug
Chiarezza
Da chiarire
Stato di attività
Attiva
Stack tecnologico
c
Ambito
backend

Direzione di ricerca

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.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

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?

Lingua principale
C++
Stelle
360
Fork
2
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Preparare l'ambiente

Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di tsoding/ht.h

Tutte le issue di tsoding/ht.h

Issue simili

Altre issue su C++

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.