A
A
Alexey Yarkov2017-01-19 17:54:19
linux
Alexey Yarkov, 2017-01-19 17:54:19

Why does the "Segmentation Fault" pop up?

I look in the direction of mastering C (the first day). I decided to write a password generator utility.
By tradition, I opened Google and go: https://github.com/yarkovaleksei/passgen
It compiles fine:

$ make
gcc -c ./source/passgen.c
gcc -c ./source/main.c
gcc -o ./bin/passgen passgen.o main.o
Ошибка сегментирования

But instead of a password, it outputs to the console:
$ ./bin/passgen -l 25
Ошибка сегментирования

UPDATE: Friends! Thanks for answers! So how do you fix it all? :D

Answer the question

In order to leave comments, you need to log in

3 answer(s)
C
CityCat4, 2017-01-19
@yarkov

Well, that's right, that's how it should be. SIGSEGV occurs when a program tries to modify data in a region that does not belong to it, that is, not in a static buffer and not in a dynamic region obtained through malloc ().
will create a variable containing a pointer to the sign. The variable is not initialized, so it contains garbage. If this garbage is interpreted as a write address, what is done here:
SIGSEGV is guaranteed :D

D
Dmitry, 2017-01-19
@dmtrrr

Deal with pointers and memory allocation, what do you think you returned here: return result ?

N
nirvimel, 2017-01-19
@nirvimel

Scientifically, this kind of error is called Undefined behavior .
In practice, this looks like a Segmentation fault in 99% of cases.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question