thsmale / addy

1 stars 0 forks source link

stack memory warning for response #2

Open thsmale opened 1 year ago

thsmale commented 1 year ago
$ ./server
addy.c:132:9: warning: address of stack memory associated with local variable 'response' returned [-Wreturn-stack-address]
        return response;
               ^~~~~~~~
thsmale commented 1 year ago

This is not good. You are returning a pointer to an automatic (scoped) variable, which will be destroyed when the function returns. The pointer will be left pointing at a destroyed variable, which will almost certainly produce "strange" results (undefined behaviour).

You should be allocating the string with malloc (e.g. char *rtnPtr = malloc(length)), then freeing it later in main.

source

thsmale commented 1 year ago

going to add a parameter, request will now accept request and response. this gives user the ability to specify the size of the request they wish to receive

thsmale commented 1 year ago

although char *response = request(struct Http options); than check if response is NULL is cleaner

thsmale commented 1 year ago

update example request in documentation to reflect these changes