#Segmentation fault (core dumped)

24 messages · Page 1 of 1 (latest)

dim mica
#

Ok idk if the title is correct 'cause when I run it in the Bash shell it shows Segmentation fault (core dumped) and
when I run in Fish shell it shows fish: Job 1, 'build/main' terminated by signal SIGSEGV (Address boundary error).

My code is very simple, I was just trying to make an ascii game, I didn't even started well yet.
My code is here: https://github.com/pandasoli/simple-cpp-rpg

I'm a C++ beginner so I got no idea what this error's.

But Ik that the error probably is in character.cpp line 33 and 38, 'cause when I comment them or just put a cout the program runs normally.

junior crestBOT
#

When your question is answered use !solved to mark the question as resolved.

Remember to ask specific questions, provide necessary details, and reduce your question to its simplest form. For tips on how to ask a good question run !howto ask.

daring wharf
#

Add -g to compiler flags and run it under a debugger to see where it crashed and how it got there. Alternatively add -fsanitize=undefined,address and the program should give you better output.

tacit helm
#

If you use the fsanitize you still want the -g aswell

dim mica
#

Nothing much helpful ig

#

Could you read the code pleasee, it has no much lines

#

and its organizated ofc

tacit helm
#

Sure, may I see character.cpp around line 33

dim mica
junior crestBOT
#

@dim mica Has your question been resolved? If so, run !solved :)

dim mica
tacit helm
#

okay so whenever you are accessing data from a vector or a string, don't use [] and instead use .at(), at that will yell at you if you do some sort of out of bounds access

#

;compile

#include <iostream>
#include <vector>
int main() {
  std::vector v{1, 2, 3};
  std::cout << v.at(5);
}
hearty hearthBOT
#
Compiler Output
terminate called after throwing an instance of 'std::out_of_range'
  what():  vector::_M_range_check: __n (which is 5) >= this->size() (which is 3)
dim mica
#

❤️ gonna try

dim mica
#

it makes no sense

tacit helm
#

Welp at least you have a lead now

dim mica
#

oh okay

#

this->buff.resize was making it. idk why

dim mica
dim mica
#

stupid

dim mica
#

!solved