summaryrefslogtreecommitdiff
path: root/src/common/util.c
diff options
context:
space:
mode:
authorMansour Moufid <mansourmoufid@gmail.com>2014-10-19 13:12:11 -0400
committerNick Mathewson <nickm@torproject.org>2014-11-02 11:54:42 -0500
commit81b452d245c19e9a16681567b9dbcf0f7a71ac78 (patch)
treeae0987557d7f85fb359effcc741746de12e54cd8 /src/common/util.c
parent06b1ef7b76feb93243affd0ac7b62b03caf9a27d (diff)
downloadtor-81b452d245c19e9a16681567b9dbcf0f7a71ac78.tar.gz
tor-81b452d245c19e9a16681567b9dbcf0f7a71ac78.zip
Document the calloc function overflow check.
Diffstat (limited to 'src/common/util.c')
-rw-r--r--src/common/util.c4
1 files changed, 4 insertions, 0 deletions
diff --git a/src/common/util.c b/src/common/util.c
index 013a501dbc..74a538ed2f 100644
--- a/src/common/util.c
+++ b/src/common/util.c
@@ -195,8 +195,10 @@ tor_malloc_zero_(size_t size DMALLOC_PARAMS)
return result;
}
+/* Estimate the square root of SIZE_MAX. */
#define SQRT_SIZE_MAX (((size_t) SIZE_MAX) >> (sizeof(size_t) * 8 / 2))
+/** Return non-zero if and only if the product of the arguments is exact. */
static INLINE int
size_mul_check(const size_t x, const size_t y)
{
@@ -208,6 +210,8 @@ size_mul_check(const size_t x, const size_t y)
* the memory with zero bytes, and return a pointer to the result.
* Log and terminate the process on error. (Same as
* calloc(<b>nmemb</b>,<b>size</b>), but never returns NULL.)
+ * The second argument (<b>size</b>) should preferably be non-zero
+ * and a compile-time constant.
*/
void *
tor_calloc_(size_t nmemb, size_t size DMALLOC_PARAMS)