Valgrind mir gibt Bedingter Sprung oder bewegen, hängt von uninitialised Wert (e) und Uninitialised Wert wurde auf meinem aktuellen Code Fehler durch eine Heapzuordnung erstellt:Valgrind: Bedingter Sprung oder bewegen, hängt von uninitialised Wert (e)
Valgrind zeigt auf nr = malloc (sizeof (Kreatur) * c); Was mache ich also falsch?
typedef struct creature_st {
char name[20]; // name of the monster
char sign; // character that represents monster on the game display
Point pos; // location of the monster
float hp; // current hitpoints
unsigned int maxhp; // maximum hitpoints
void (*move)(struct game_st *, struct creature_st *); // current movement algorithm for monster
void (*attack)(struct game_st *, struct creature_st *); // current attack algorithm for monster
} Creature;
Voll valgrind Fehler:
== == 386 Bedingter Sprung oder Bewegung hängt von uninitialised Wert (e) == == 386 bei 0x4C2C1B8: Strlen (in/usr/lib/valgrind/vgpreload_memcheck -amd64-linux.so) == 386 == von 0x403F54: test_createMonsters (test_source.c: 179) == 386 == von 0x409377: srunner_run (in/tmc/test/test) == 386 == von 0x4057C9: tmc_run_tests (tmc-check.c: 134) == 386 == von 0x405464: main (test_source.c: 529) == 386 == Der nicht initialisierte Wert wurde durch eine Heap-Zuweisung erstellt == 386 == bei 0x4C28C20: malloc (in/usr/lib/valgrind/vgpreload_memcheck-amd64-linux.so) == 386 == von 0x4026C2: createMonsters (mon ster.c: 288) == 386 == von 0x403ADF: test_createMonsters (test_source.c: 119) == 386 == von 0x409377: srunner_run (in/tmc/test/test) == 386 == von 0x4057C9: tmc_run_tests (tmc-check.c: 134) == 386 == von 0x405464: main (test_source.c: 529) == 386 ==
typedef struct game_st {
Map map;
unsigned int numMonsters; // number of elements in 'monsters' array
Creature *monsters; // dynamic array of all monsters
Point position; // current position of the player
float hp; // hit points, should never be higher than 'maxhp'
unsigned int maxhp; // maximum hit points
Options opts;
} Game;
ist Creature ein vollständiger Typ hier? Wenn dies ein typedef auf einer Struktur ist, ist die Definition enthalten? – 4pie0
Hinzugefügt def von Creature struct –
Was ich fragen ist, ob diese Datei Zugriff auf diese Definition von struct hat? – 4pie0