mirror of
https://gitlab.torproject.org/tpo/core/tor.git
synced 2024-11-30 23:53:32 +01:00
Expose format_hex_number_..., and rename it to ..._sigsafe().
There are some other places in the code that will want a signal-safe way to format numbers, so it shouldn't be static to util.c.
This commit is contained in:
parent
449b2b7c58
commit
22977b7c1d
@ -3402,9 +3402,8 @@ tor_join_win_cmdline(const char *argv[])
|
|||||||
* function; it's designed to be used in code paths where you can't call
|
* function; it's designed to be used in code paths where you can't call
|
||||||
* arbitrary C functions.
|
* arbitrary C functions.
|
||||||
*/
|
*/
|
||||||
STATIC int
|
int
|
||||||
format_hex_number_for_helper_exit_status(unsigned int x, char *buf,
|
format_hex_number_sigsafe(unsigned int x, char *buf, int max_len)
|
||||||
int max_len)
|
|
||||||
{
|
{
|
||||||
int len;
|
int len;
|
||||||
unsigned int tmp;
|
unsigned int tmp;
|
||||||
@ -3490,8 +3489,8 @@ format_helper_exit_status(unsigned char child_state, int saved_errno,
|
|||||||
cur = hex_errno;
|
cur = hex_errno;
|
||||||
|
|
||||||
/* Emit child_state */
|
/* Emit child_state */
|
||||||
written = format_hex_number_for_helper_exit_status(child_state,
|
written = format_hex_number_sigsafe(child_state, cur, left);
|
||||||
cur, left);
|
|
||||||
if (written <= 0)
|
if (written <= 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
|
||||||
@ -3520,8 +3519,7 @@ format_helper_exit_status(unsigned char child_state, int saved_errno,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Emit unsigned_errno */
|
/* Emit unsigned_errno */
|
||||||
written = format_hex_number_for_helper_exit_status(unsigned_errno,
|
written = format_hex_number_sigsafe(unsigned_errno, cur, left);
|
||||||
cur, left);
|
|
||||||
|
|
||||||
if (written <= 0)
|
if (written <= 0)
|
||||||
goto err;
|
goto err;
|
||||||
|
@ -518,11 +518,12 @@ int32_t tor_weak_random_range(tor_weak_rng_t *rng, int32_t top);
|
|||||||
* <b>n</b> */
|
* <b>n</b> */
|
||||||
#define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n)))
|
#define tor_weak_random_one_in_n(rng, n) (0==tor_weak_random_range((rng),(n)))
|
||||||
|
|
||||||
|
int format_hex_number_sigsafe(unsigned int x, char *buf, int max_len);
|
||||||
|
|
||||||
#ifdef UTIL_PRIVATE
|
#ifdef UTIL_PRIVATE
|
||||||
/* Prototypes for private functions only used by util.c (and unit tests) */
|
/* Prototypes for private functions only used by util.c (and unit tests) */
|
||||||
|
|
||||||
STATIC int format_hex_number_for_helper_exit_status(unsigned int x, char *buf,
|
#ifndef _WIN32
|
||||||
int max_len);
|
|
||||||
STATIC int format_helper_exit_status(unsigned char child_state,
|
STATIC int format_helper_exit_status(unsigned char child_state,
|
||||||
int saved_errno, char *hex_errno);
|
int saved_errno, char *hex_errno);
|
||||||
|
|
||||||
@ -532,6 +533,8 @@ STATIC int format_helper_exit_status(unsigned char child_state,
|
|||||||
1 + sizeof(int) * 2 + 1)
|
1 + sizeof(int) * 2 + 1)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
const char *libor_get_digests(void);
|
const char *libor_get_digests(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
@ -2627,7 +2627,7 @@ test_util_spawn_background_partial_read(void *ptr)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Test for format_hex_number_for_helper_exit_status()
|
* Test for format_hex_number_sigsafe()
|
||||||
*/
|
*/
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -2653,8 +2653,7 @@ test_util_format_hex_number(void *ptr)
|
|||||||
(void)ptr;
|
(void)ptr;
|
||||||
|
|
||||||
for (i = 0; test_data[i].str != NULL; ++i) {
|
for (i = 0; test_data[i].str != NULL; ++i) {
|
||||||
len = format_hex_number_for_helper_exit_status(test_data[i].x,
|
len = format_hex_number_sigsafe(test_data[i].x, buf, HEX_ERRNO_SIZE);
|
||||||
buf, HEX_ERRNO_SIZE);
|
|
||||||
test_neq(len, 0);
|
test_neq(len, 0);
|
||||||
buf[len] = '\0';
|
buf[len] = '\0';
|
||||||
test_streq(buf, test_data[i].str);
|
test_streq(buf, test_data[i].str);
|
||||||
|
Loading…
Reference in New Issue
Block a user