aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2012-06-22 22:17:24 -0400
committerNick Mathewson <nickm@torproject.org>2012-06-22 22:21:20 -0400
commit4a7e4129af6db990b9672b6d4f013b2e59aa81b7 (patch)
treebf1cadee30f6ae7847b2f3a61f7174679fae8383 /src
parent770374a6b3e6a60b65cf9616755b018f93a17d26 (diff)
downloadtor-4a7e4129af6db990b9672b6d4f013b2e59aa81b7.tar
tor-4a7e4129af6db990b9672b6d4f013b2e59aa81b7.tar.gz
Style tweaks and add a warning about NUL-termination
Diffstat (limited to 'src')
-rw-r--r--src/common/util.c12
1 files changed, 9 insertions, 3 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 79e7a7041..cb8ff85b4 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -3197,6 +3197,9 @@ tor_join_win_cmdline(const char *argv[])
* buf, up to max_len digits, and returns the actual number of digits written.
* If there is insufficient space, it will write nothing and return 0.
*
+ * This function DOES NOT add a terminating NUL character to its output: be
+ * careful!
+ *
* This accepts an unsigned int because format_helper_exit_status() needs to
* call it with a signed int and an unsigned char, and since the C standard
* does not guarantee that an int is wider than a char (an int must be at
@@ -3204,8 +3207,11 @@ tor_join_win_cmdline(const char *argv[])
* can't assume a signed int is sufficient to accomodate an unsigned char.
* Thus, format_helper_exit_status() will still need to emit any require '-'
* on its own.
+ *
+ * For most purposes, you'd want to use tor_snprintf("%x") instead of this
+ * function; it's designed to be used in code paths where you can't call
+ * arbitrary C functions.
*/
-
int
format_hex_number_for_helper_exit_status(unsigned int x, char *buf,
int max_len)
@@ -3226,8 +3232,9 @@ format_hex_number_for_helper_exit_status(unsigned int x, char *buf,
tmp >>= 4;
++len;
}
+ } else {
+ len = 1;
}
- else len = 1;
/* Bail if we would go past the end of the buffer */
if (len > max_len)
@@ -3258,7 +3265,6 @@ format_hex_number_for_helper_exit_status(unsigned int x, char *buf,
* CHILD_STATE_* macros for definition), and SAVED_ERRNO is the value of
* errno when the failure occurred.
*/
-
void
format_helper_exit_status(unsigned char child_state, int saved_errno,
char *hex_errno)