aboutsummaryrefslogtreecommitdiff
path: root/src/common
diff options
context:
space:
mode:
authorNick Mathewson <nickm@torproject.org>2013-04-17 10:45:45 -0400
committerNick Mathewson <nickm@torproject.org>2013-04-17 10:45:45 -0400
commit42731f69efc1f7b0614a33cd6ea7a70903bfc98b (patch)
tree3b5d5e5eedb704f116d26367546c002ebf02d0ca /src/common
parenta6545d6335cd7829cdc9c0d7ce2e61b775bcca1d (diff)
parent0cf2c01dbd9b86d396a55186e0656db33c7929d8 (diff)
downloadtor-42731f69efc1f7b0614a33cd6ea7a70903bfc98b.tar
tor-42731f69efc1f7b0614a33cd6ea7a70903bfc98b.tar.gz
Merge branch 'bug8037_squashed' into maint-0.2.4
Diffstat (limited to 'src/common')
-rw-r--r--src/common/util.c14
-rw-r--r--src/common/util.h3
2 files changed, 17 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 2f1bc6171..db160fdf0 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -281,6 +281,20 @@ tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS)
return dup;
}
+/** As tor_memdup(), but add an extra 0 byte at the end of the resulting
+ * memory. */
+void *
+tor_memdup_nulterm(const void *mem, size_t len DMALLOC_PARAMS)
+{
+ char *dup;
+ tor_assert(len < SIZE_T_CEILING+1);
+ tor_assert(mem);
+ dup = tor_malloc_(len+1 DMALLOC_FN_ARGS);
+ memcpy(dup, mem, len);
+ dup[len] = '\0';
+ return dup;
+}
+
/** Helper for places that need to take a function pointer to the right
* spelling of "free()". */
void
diff --git a/src/common/util.h b/src/common/util.h
index 712352b03..96a02dd77 100644
--- a/src/common/util.h
+++ b/src/common/util.h
@@ -83,6 +83,8 @@ char *tor_strndup_(const char *s, size_t n DMALLOC_PARAMS)
ATTR_MALLOC ATTR_NONNULL((1));
void *tor_memdup_(const void *mem, size_t len DMALLOC_PARAMS)
ATTR_MALLOC ATTR_NONNULL((1));
+void *tor_memdup_nulterm_(const void *mem, size_t len DMALLOC_PARAMS)
+ ATTR_MALLOC ATTR_NONNULL((1));
void tor_free_(void *mem);
#ifdef USE_DMALLOC
extern int dmalloc_free(const char *file, const int line, void *pnt,
@@ -116,6 +118,7 @@ extern int dmalloc_free(const char *file, const int line, void *pnt,
#define tor_strdup(s) tor_strdup_(s DMALLOC_ARGS)
#define tor_strndup(s, n) tor_strndup_(s, n DMALLOC_ARGS)
#define tor_memdup(s, n) tor_memdup_(s, n DMALLOC_ARGS)
+#define tor_memdup_nulterm(s, n) tor_memdup_nulterm_(s, n DMALLOC_ARGS)
void tor_log_mallinfo(int severity);