Seg fault :(
On line 50 in server.c
I have
fd_set readfds;
which is causing a segmentation fault. fd_set macro is imported from <sys/time.h>
.
--
Makefile:11: recipe for target 'all' failed
make: *** [all] Segmentation fault (core dumped)
exit status 2
@xxpertHacker no bully pls
Voters
xxpertHacker (768)
Why did you think line 50 was the problem?
programmeruser (521)
Well, running with GDB gives me this:
[WARNING] ~ SIFI: Master socket initalization failed
Program received signal SIGSEGV, Segmentation fault.
__GI___libc_realloc (bytes=4, oldmem=0x3) at malloc.c:3165
3165 malloc.c: No such file or directory.
realTronsi (901)
@programmeruser by clicking the run button?
programmeruser (521)
@realTronsi no, gdb main.o
then run
programmeruser (521)
@realTronsi and here's the backtrace:
#0 __GI___libc_realloc (bytes=4, oldmem=0x3) at malloc.c:3165
#1 realloc_hook_ini (ptr=0x3, sz=4, caller=<optimized out>) at hooks.c:41
#2 0x000056441c0c9972 in create_server (PORT=80) at server/server.c:35
#3 0x000056441c0c97fb in main () at examples/main.c:9
realTronsi (901)
@programmeruser doesn't really tell me much
xxpertHacker (768)
@programmeruser He's calling realloc on a bad pointer, https://repl.it/talk/ask/Im-getting-a-realloc-abortion-but-I-do/87284/397310.
CodeLongAndPros (1564)
Try using -g
and gdb?
I'm getting a realloc abortion, but I don't see it directly called anywhere... oh, nvm, line 35 server.c, realloc is failing.
You can't realloc a pointer that didn't even come from alloc!
And even then, you're not always able to realloc a pointer from alloc anyways!
(Also, doesn't realloc invalidate old pointers?)
Also, I told you that you were on your own, I can't help you out here.
Isn't
server.clients
garbage memory right now?@xxpertHacker thought line 50 was the problem since removing it stopped the seg faults.
But just realized I wrote realloc instead of calloc :|
@realTronsi calloc makes so much more sense there, I thought you were just writing nonsense.
@xxpertHacker I am writing nonsense :D
@xxpertHacker wow great putting it in a struct leads to another seg fault :|
@realTronsi yay, go make another question so I could easily get 5 more useless internet points, lol
@xxpertHacker just answer it in 5 different comments :D
@realTronsi Then I'll want 25 useless internet points.
@xxpertHacker that makes no sense, just answer :(
@xxpertHacker okay answer word by word so you get #word free internet points
@realTronsi did you mean to call
calloc(server.client_t
?Go add this too:
@xxpertHacker wdym i'm not callocing the client_t
@realTronsi Yes, that's the point.
This is bad code:
It literally makes no sense, and it's a type error.
And it's undefined behavior.
Look at GCC's pedantic warning:
Simply put, that is a type error.
Next,
You're passing the address of a pointer, which is currently initialized by random memory, as a size_t.
For all you know, you're doing
calloc(0x3434238935, ...)
.(btw, use a code formatter)
wait wtf lmao yeah I see
server.clients = calloc(1, (server.client_t)*sizeof(*server.clients));
idek why I put the address there, when I wrote this 2 days ago I must've been thinking of realloc and thought I calloced b4
@realTronsi omg, finally you see why I saw that code as nonsense.
Also, this is why I dislike weakly-typed languages, noobs run into errors too often, and implicit casts even screw me over.
@xxpertHacker
._.
idk what happened for this one but I'm not normally this autistic