I am attempting to return a server structure pointer in this function in C. There's no issues when I compile this code, but when during execution, the line test->port is causing an AddressSanitizer issue.
---header file---
struct gfserver_t{ //fxw
int port;
int max_npending;
};
---c file---
gfserver_t* gfserver_create(){
struct gfserver_t* test;
memset(&test, 0, sizeof(test));
test->port=22;//==30022==ERROR: AddressSanitizer: SEGV on unknown address
return test;
}
I tried gdb, looking up the causes of AddressSanitizer (dereferencing a null pointer), and how to set pointer structure members and still don't understand how I am running into this issue. Any pointers would be great.