diff options
Diffstat (limited to 'src/test/test_util.c')
-rw-r--r-- | src/test/test_util.c | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/test/test_util.c b/src/test/test_util.c index e80201737a..3e4d45d35b 100644 --- a/src/test/test_util.c +++ b/src/test/test_util.c @@ -3340,6 +3340,13 @@ test_util_memarea(void *arg) void *malloced_ptr = NULL; int i; +#ifdef DISABLE_MEMORY_SENTINELS + /* If memory sentinels are disabled, this whole module is just an alias for + malloc(), which is free to lay out memory most any way it wants. */ + if (1) + tt_skip(); +#endif + (void)arg; tt_assert(area); @@ -3965,47 +3972,50 @@ test_util_fgets_eagain(void *ptr) /* Send in a partial line */ retlen = write(test_pipe[1], "A", 1); tt_int_op(retlen, OP_EQ, 1); - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, EAGAIN); - tt_ptr_op(retptr, OP_EQ, buf); + tt_ptr_op(retptr, OP_EQ, NULL); tt_str_op(buf, OP_EQ, "A"); errno = 0; /* Send in the rest */ retlen = write(test_pipe[1], "B\n", 2); tt_int_op(retlen, OP_EQ, 2); - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, 0); tt_ptr_op(retptr, OP_EQ, buf); tt_str_op(buf, OP_EQ, "B\n"); errno = 0; + memset(buf, '\0', sizeof(buf)); /* Send in a full line */ retlen = write(test_pipe[1], "CD\n", 3); tt_int_op(retlen, OP_EQ, 3); - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, 0); tt_ptr_op(retptr, OP_EQ, buf); tt_str_op(buf, OP_EQ, "CD\n"); errno = 0; + memset(buf, '\0', sizeof(buf)); /* Send in a partial line */ retlen = write(test_pipe[1], "E", 1); tt_int_op(retlen, OP_EQ, 1); - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, EAGAIN); - tt_ptr_op(retptr, OP_EQ, buf); + tt_ptr_op(retptr, OP_EQ, NULL); tt_str_op(buf, OP_EQ, "E"); errno = 0; /* Send in the rest */ retlen = write(test_pipe[1], "F\n", 2); tt_int_op(retlen, OP_EQ, 2); - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, 0); tt_ptr_op(retptr, OP_EQ, buf); tt_str_op(buf, OP_EQ, "F\n"); errno = 0; + memset(buf, '\0', sizeof(buf)); /* Send in a full line and close */ retlen = write(test_pipe[1], "GH", 2); @@ -4013,14 +4023,14 @@ test_util_fgets_eagain(void *ptr) retval = close(test_pipe[1]); tt_int_op(retval, OP_EQ, 0); test_pipe[1] = -1; - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, 0); tt_ptr_op(retptr, OP_EQ, buf); tt_str_op(buf, OP_EQ, "GH"); errno = 0; /* Check for EOF */ - retptr = fgets(buf, sizeof(buf), test_stream); + retptr = tor_fgets(buf, sizeof(buf), test_stream); tt_int_op(errno, OP_EQ, 0); tt_ptr_op(retptr, OP_EQ, NULL); retval = feof(test_stream); @@ -4029,6 +4039,7 @@ test_util_fgets_eagain(void *ptr) /* Check that buf is unchanged according to C99 and C11 */ tt_str_op(buf, OP_EQ, "GH"); + memset(buf, '\0', sizeof(buf)); done: if (test_stream != NULL) |