Skip to content
Open
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
17 changes: 7 additions & 10 deletions ext/random/random.c
Original file line number Diff line number Diff line change
Expand Up @@ -315,32 +315,29 @@ PHPAPI void *php_random_default_status(void)
}
/* }}} */

/* this is read-only, so it's ok */
ZEND_SET_ALIGNED(16, static const char hexconvtab[]) = "0123456789abcdef";

/* {{{ php_random_bin2hex_le */
/* stolen from standard/string.c */
PHPAPI zend_string *php_random_bin2hex_le(const void *ptr, const size_t len)
{
#ifdef WORDS_BIGENDIAN
Comment thread
LamentXU123 marked this conversation as resolved.
ZEND_SET_ALIGNED(16, static const char hexconvtab[]) = "0123456789abcdef";
zend_string *str;
size_t i;

str = zend_string_safe_alloc(len, 2 * sizeof(char), 0, 0);

i = 0;
#ifdef WORDS_BIGENDIAN
/* force little endian */
for (size_t h = len; 0 < h; h--) {
size_t j = h-1;
#else
for (size_t j = 0; j < len; j++) {
#endif
ZSTR_VAL(str)[i++] = hexconvtab[((unsigned char *) ptr)[j] >> 4];
ZSTR_VAL(str)[i++] = hexconvtab[((unsigned char *) ptr)[j] & 15];
ZSTR_VAL(str)[i++] = hexconvtab[((const unsigned char *) ptr)[j] >> 4];
ZSTR_VAL(str)[i++] = hexconvtab[((const unsigned char *) ptr)[j] & 15];
}
ZSTR_VAL(str)[i] = '\0';

return str;
#else
return zend_bin2hex_str(ptr, len);
#endif
}
/* }}} */

Expand Down
Loading