Skip to content
This repository has been archived by the owner on Jun 30, 2021. It is now read-only.

Commit

Permalink
more return normalization
Browse files Browse the repository at this point in the history
  • Loading branch information
NathanFrench committed Jul 12, 2017
1 parent bf59eb1 commit 91008a6
Showing 1 changed file with 29 additions and 23 deletions.
52 changes: 29 additions & 23 deletions evhtp.c
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,9 @@ htp__path_new_(evhtp_path_t ** out, const char * data, size_t len)
}

path = strndup(data, path_len);
file = strndup(&data[i + 1], file_len);

evhtp_alloc_assert(path);

file = strndup(&data[i + 1], file_len);
evhtp_alloc_assert(file);

break;
Expand Down Expand Up @@ -854,19 +854,21 @@ htp__path_free_(evhtp_path_t * path)
/**
* @brief create an authority structure
*
* @return evhtp_authority_t
* @return 0 on success, -1 on error
*/
static evhtp_authority_t *
htp__authority_new_(void)
static int
htp__authority_new_(evhtp_authority_t ** out)
{
evhtp_authority_t * authority;

if (!(authority = calloc(1, sizeof(*authority))))
{
return NULL;
return -1;
}

return authority;
*out = authority;

return 0;
}

/**
Expand Down Expand Up @@ -915,28 +917,31 @@ htp__uri_free_(evhtp_uri_t * uri)
/**
* @brief create an overlay URI structure
*
* @return evhtp_uri_t
* @return 0 on success, -1 on error.
*/
static evhtp_uri_t *
htp__uri_new_(void)
static int
htp__uri_new_(evhtp_uri_t ** out)
{
evhtp_uri_t * uri;

if (!(uri = calloc(sizeof(evhtp_uri_t), 1)))
{
return NULL;
return -1;
}

uri->authority = htp__authority_new_();
uri->authority = NULL;

if (!uri->authority)
if (htp__authority_new_(&uri->authority) == -1)
{
htp__uri_free_(uri);
evhtp_safe_free(uri, htp__uri_free_);

return NULL;
return -1;
}

return uri;

*out = uri;

return 0;
}

/**
Expand Down Expand Up @@ -1417,10 +1422,11 @@ htp__request_parse_hostname_(htparser * p, const char * data, size_t len)
static int
htp__require_uri_(evhtp_connection_t * c)
{
if (c && c->request && !c->request->uri)
if (c != NULL && c->request != NULL && c->request->uri == NULL)
{
c->request->uri = htp__uri_new_();
evhtp_alloc_assert(c->request->uri);
evhtp_assert(htp__uri_new_(&c->request->uri) == 0);

return -1;
}

return 0;
Expand All @@ -1432,15 +1438,15 @@ htp__request_parse_host_(htparser * p, const char * data, size_t len)
evhtp_connection_t * c = htparser_get_userdata(p);
evhtp_authority_t * authority;

if (htp__require_uri_(c) != 0)
if (htp__require_uri_(c) == -1)
{
return -1;
}

authority = c->request->uri->authority;
authority->hostname = malloc(len + 1);

if (!authority->hostname)
if (authority->hostname == NULL)
{
c->request->status = EVHTP_RES_FATAL;

Expand All @@ -1461,7 +1467,7 @@ htp__request_parse_port_(htparser * p, const char * data, size_t len)
char * endptr;
unsigned long port;

if (htp__require_uri_(c) != 0)
if (htp__require_uri_(c) == -1)
{
return -1;
}
Expand All @@ -1487,7 +1493,7 @@ htp__request_parse_path_(htparser * p, const char * data, size_t len)
evhtp_connection_t * c = htparser_get_userdata(p);
evhtp_path_t * path;

if (htp__require_uri_(c) != 0)
if (htp__require_uri_(c) == -1)
{
return -1;
}
Expand Down

0 comments on commit 91008a6

Please sign in to comment.