test/buffer_tests.c

changeset 230
4044131874f9
parent 227
740fbd7bab71
child 250
b7d1317b138e
equal deleted inserted replaced
229:9db71925eaa8 230:4044131874f9
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE. 26 * POSSIBILITY OF SUCH DAMAGE.
27 */ 27 */
28 28
29 #include "buffer_tests.h" 29 #include "buffer_tests.h"
30 #include <stdint.h>
30 31
31 UCX_TEST(test_ucx_buffer_new) { 32 UCX_TEST(test_ucx_buffer_new) {
32 UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND); 33 UcxBuffer *b = ucx_buffer_new(NULL, 16, UCX_BUFFER_AUTOEXTEND);
33 UcxBuffer *b2 = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT); 34 UcxBuffer *b2 = ucx_buffer_new(NULL, 32, UCX_BUFFER_DEFAULT);
34 UCX_TEST_BEGIN 35 UCX_TEST_BEGIN
95 UCX_TEST_ASSERT(r != 0, "seek cur overflow"); 96 UCX_TEST_ASSERT(r != 0, "seek cur overflow");
96 UCX_TEST_ASSERT(b->pos == bigpos, 97 UCX_TEST_ASSERT(b->pos == bigpos,
97 "failed seek shall leave pos unchanged"); 98 "failed seek shall leave pos unchanged");
98 99
99 b->pos = 0; 100 b->pos = 0;
100 b->size = sizemax / 2 + 32; 101 b->size = (sizemax >> 1) + 32;
101 off_t bigoff = sizemax / 2 - 16; 102
103 // we don't want to risk overflows in implicit constant casts
104 const size_t bigoff_comp = (sizemax >> 1) - 16;
105 off_t bigoff = (off_t)bigoff_comp;
106
102 r = ucx_buffer_seek(b, -bigoff, SEEK_CUR); 107 r = ucx_buffer_seek(b, -bigoff, SEEK_CUR);
103 UCX_TEST_ASSERT(r != 0, "seek cur underflow"); 108 UCX_TEST_ASSERT(r != 0, "seek cur underflow");
104 UCX_TEST_ASSERT(b->pos == 0, 109 UCX_TEST_ASSERT(b->pos == 0,
105 "failed seek shall leave pos unchanged"); 110 "failed seek shall leave pos unchanged");
106 111

mercurial