Tue, 02 Jan 2018 17:00:21 +0100
ucx_buffere_getc should return an unsigned char (0-255) or EOF (-1)
src/buffer.c | file | annotate | diff | comparison | revisions | |
test/buffer_tests.c | file | annotate | diff | comparison | revisions |
1.1 --- a/src/buffer.c Mon Nov 20 18:06:32 2017 +0100 1.2 +++ b/src/buffer.c Tue Jan 02 17:00:21 2018 +0100 1.3 @@ -225,7 +225,7 @@ 1.4 if (ucx_buffer_eof(buffer)) { 1.5 return EOF; 1.6 } else { 1.7 - int c = buffer->space[buffer->pos]; 1.8 + int c = ((unsigned char*)buffer->space)[buffer->pos]; 1.9 buffer->pos++; 1.10 return c; 1.11 }
2.1 --- a/test/buffer_tests.c Mon Nov 20 18:06:32 2017 +0100 2.2 +++ b/test/buffer_tests.c Tue Jan 02 17:00:21 2018 +0100 2.3 @@ -342,6 +342,10 @@ 2.4 2.5 UcxBuffer *b = ucx_buffer_new(buffer, 16, UCX_BUFFER_DEFAULT); 2.6 b->size = b->capacity; 2.7 + 2.8 + unsigned char ubuffer[] = {127, 128, 129, 130}; 2.9 + UcxBuffer *ub = ucx_buffer_new(ubuffer, 4, UCX_BUFFER_DEFAULT); 2.10 + ub->size = 4; 2.11 2.12 UCX_TEST_BEGIN 2.13 2.14 @@ -360,10 +364,21 @@ 2.15 UCX_TEST_ASSERT(ucx_buffer_getc(b) == EOF, 2.16 "out of bounds read does not return EOF"); 2.17 UCX_TEST_ASSERT(b->pos == 16, "wrong position after out of bounds read"); 2.18 + 2.19 + int uc[5]; 2.20 + for(int i=0;i<5;i++) { 2.21 + uc[i] = ucx_buffer_getc(ub); 2.22 + } 2.23 + UCX_TEST_ASSERT(uc[0] == 127, "wrong unsigned value(0)"); 2.24 + UCX_TEST_ASSERT(uc[1] == 128, "wrong unsigned value(0)"); 2.25 + UCX_TEST_ASSERT(uc[2] == 129, "wrong unsigned value(0)"); 2.26 + UCX_TEST_ASSERT(uc[3] == 130, "wrong unsigned value(0)"); 2.27 + UCX_TEST_ASSERT(uc[4] == EOF, "EOF not set after last ub read"); 2.28 2.29 UCX_TEST_END 2.30 2.31 ucx_buffer_free(b); 2.32 + ucx_buffer_free(ub); 2.33 free(buffer); 2.34 } 2.35