8000 Merge pull request #912 from yatsukhnenko/php7 · jrtkcoder/phpredis@b3193f1 · GitHub
[go: up one dir, main page]

Skip to content
10000

Commit b3193f1

Browse files
authored
Merge pull request phpredis#912 from yatsukhnenko/php7
replace emalloc+memcpy with estrndup
2 parents 074995a + 10f0b59 commit b3193f1

File tree

1 file changed

+4
-12
lines changed

1 file changed

+4
-12
lines changed

redis_array_impl.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -398,9 +398,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
398398
}
399399

400400
*out_len = Z_STRLEN(z_ret);
401-
out = emalloc(*out_len + 1);
402-
out[*out_len] = 0;
403-
memcpy(out, Z_STRVAL(z_ret), *out_len);
401+
out = estrndup(Z_STRVAL(z_ret), *out_len);
404402

405403
zval_dtor(&z_argv0);
406404
zval_dtor(&z_ret);
@@ -410,7 +408,7 @@ ra_call_extractor(RedisArray *ra, const char *key, int key_len, int *out_len TSR
410408
static char *
411409
ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS_DC) {
412410

413-
char *start, *end, *out;
411+
char *start, *end;
414412
*out_len = key_len;
415413

416414
if(Z_TYPE(ra->z_fun) != IS_UNDEF)
@@ -426,11 +424,7 @@ ra_extract_key(RedisArray *ra, const char *key, int key_len, int *out_len TSRMLS
426424

427425
/* found substring */
428426
*out_len = end - start - 1;
429-
out = emalloc(*out_len + 1);
430-
out[*out_len] = 0;
431-
memcpy(out, start+1, *out_len);
432-
433-
return out;
427+
return estrndup(start + 1, *out_len);
434428
}
435429

436430
/* call userland key distributor function */
@@ -737,10 +731,8 @@ ra_rehash_scan(zval *z_redis, char ***keys, int **key_lens, const char *cmd, con
737731
key_len = Z_STRLEN_P(z_data_p);
738732

739733
/* copy key and length */
740-
(*keys)[i] = emalloc(1 + key_len);
741-
memcpy((*keys)[i], key, key_len);
734+
(*keys)[i] = estrndup(key, key_len);
742735
(*key_lens)[i] = key_len;
743-
(*keys)[i][key_len] = 0; /* null-terminate string */
744736
}
745737

746738
/* cleanup */

0 commit comments

Comments
 (0)
0