8000 replace emalloc+memcpy with estrndup by yatsukhnenko · Pull Request #911 · phpredis/phpredis · GitHub
[go: up one dir, main page]

Skip to content

replace emalloc+memcpy with estrndup #911

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 30, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 4 additions & 12 deletions redis_array_impl.c
Original file line number Diff line number Diff line change
Expand Up @@ -413,9 +413,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
}

*out_len = Z_STRLEN(z_ret);
out = emalloc(*out_len + 1);
out[*out_len] = 0;
memcpy(out, Z_STRVAL(z_ret), *out_len);
out = estrndup(Z_STRVAL(z_ret), *out_len);

zval_dtor(&z_ret);
return out;
Expand All @@ -424,7 +422,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
static char *
ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS_DC) {

char *start, *end, *out;
char *start, *end;
*out_len = key_len;

if(ra->z_fun)
Expand All @@ -440,11 +438,7 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS

/* found substring */
*out_len = end - start - 1;
out = emalloc(*out_len + 1);
out[*out_len] = 0;
memcpy(out, start+1, *out_len);

return out;
return estrndup(start + 1, *out_len);
}

/* call userland key distributor function */
Expand Down Expand Up @@ -764,10 +758,8 @@ ra_rehash_scan(zval *z_redis, char ***keys, int **key_lens, const char *cmd, con
key_len = Z_STRLEN_PP(z_data_pp);

/* copy key and length */
(*keys)[i] = emalloc(1 + key_len);
memcpy((*keys)[i], key, key_len);
(*keys)[i] = estrndup(key, key_len);
(*key_lens)[i] = key_len;
(*keys)[i][key_len] = 0; /* null-terminate string */
}

/* cleanup */
Expand Down
0