Wed, 10 Oct 2012 09:32:06 +0200
discarded memprintf / memscanf
Reason: memscanf has no chance to get the amount of bytes read
test/main.c | file | annotate | diff | comparison | revisions | |
test/memstream_tests.c | file | annotate | diff | comparison | revisions | |
test/memstream_tests.h | file | annotate | diff | comparison | revisions | |
ucx/memstream.c | file | annotate | diff | comparison | revisions | |
ucx/memstream.h | file | annotate | diff | comparison | revisions |
1.1 --- a/test/main.c Tue Oct 09 16:46:29 2012 +0200 1.2 +++ b/test/main.c Wed Oct 10 09:32:06 2012 +0200 1.3 @@ -169,8 +169,6 @@ 1.4 ucx_test_register(suite, test_ucx_memgetc); 1.5 ucx_test_register(suite, test_ucx_memwrite); 1.6 ucx_test_register(suite, test_ucx_memread); 1.7 - ucx_test_register(suite, test_ucx_memprintf); 1.8 - ucx_test_register(suite, test_ucx_memscanf); 1.9 1.10 ucx_test_run(suite, stdout); 1.11 fflush(stdout);
2.1 --- a/test/memstream_tests.c Tue Oct 09 16:46:29 2012 +0200 2.2 +++ b/test/memstream_tests.c Wed Oct 10 09:32:06 2012 +0200 2.3 @@ -62,7 +62,6 @@ 2.4 ucx_memputc(m, 48); ucx_memputc(m, 48); ucx_memputc(m, 48); 2.5 UCX_TEST_ASSERT(ucx_memtell(m) == 16, "pos wrong after last 3 puts"); 2.6 UCX_TEST_ASSERT(ucx_memeof(m), "eof not set"); 2.7 - UCX_TEST_ASSERT(!ucx_memoverflow(m), "overflow shall not be set"); 2.8 UCX_TEST_ASSERT(ucx_memputc(m, 48) == EOF, "put shall return EOF on memof"); 2.9 UCX_TEST_ASSERT(memcmp(buffer, "000 000", 16) == 0, 2.10 "buffer contains incorrect content"); 2.11 @@ -121,7 +120,6 @@ 2.12 UCX_TEST_ASSERT(memcmp(buffer, teststring, 16) == 0, 2.13 "buffer data incorrect"); 2.14 UCX_TEST_ASSERT(ucx_memeof(m), "eof shall be set"); 2.15 - UCX_TEST_ASSERT(!ucx_memoverflow(m), "no overflow shall be caused"); 2.16 2.17 ucx_memseek(m, 8, SEEK_SET); 2.18 r = ucx_memwrite("not", 1, 3, m); 2.19 @@ -186,46 +184,3 @@ 2.20 ucx_memclose(m); 2.21 free(buffer); 2.22 } 2.23 - 2.24 -UCX_TEST_IMPLEMENT(test_ucx_memprintf) { 2.25 - char *buffer = malloc(32); 2.26 - UcxMemstream *m = ucx_memopen(buffer, 16); 2.27 - 2.28 - UCX_TEST_BEGIN 2.29 - int r = ucx_memprintf(m, "number: %d char: %c", 15, '6'); 2.30 - UCX_TEST_ASSERT(r == 18, "incorrect number of bytes written"); 2.31 - UCX_TEST_ASSERT(ucx_memoverflow(m), "overflow shall be detected"); 2.32 - UCX_TEST_ASSERT(memcmp(buffer, "number: 15 char:", 16) == 0, 2.33 - "incorrect buffer content"); 2.34 - 2.35 - ucx_memseek(m, 0, SEEK_SET); 2.36 - ucx_memprintf(m, "a: %d - b: %d", 1, 2); 2.37 - UCX_TEST_ASSERT(!ucx_memoverflow(m), "no overflow shall be deteceted"); 2.38 - UCX_TEST_ASSERT(memcmp(buffer, "a: 1 - b: 2char:", 16), 2.39 - "incorrect modified buffer content"); 2.40 - UCX_TEST_ASSERT(ucx_memtell(m) == 11, "incorrect position"); 2.41 - 2.42 - UCX_TEST_END 2.43 - 2.44 - ucx_memclose(m); 2.45 - free(buffer); 2.46 -} 2.47 - 2.48 -UCX_TEST_IMPLEMENT(test_ucx_memscanf) { 2.49 - char *buffer = "string 3.5 1 stuff"; 2.50 - UcxMemstream *m = ucx_memopen(buffer, 16); 2.51 - 2.52 - char s[6]; 2.53 - float f; 2.54 - int d; 2.55 - UCX_TEST_BEGIN 2.56 - int r = ucx_memscanf(m, "%s %f %d", s, &f, &d); 2.57 - UCX_TEST_ASSERT(r == 3, "3 arguments shall be read"); 2.58 - UCX_TEST_ASSERT(strncmp(s, "string", 6) == 0, "incorrect string"); 2.59 - UCX_TEST_ASSERT(f == 3.5, "incorrect float"); 2.60 - UCX_TEST_ASSERT(d == 1, "incorrect integer"); 2.61 - UCX_TEST_ASSERT(ucx_memtell(m) == 12, "incorrect position"); 2.62 - UCX_TEST_END 2.63 - 2.64 - ucx_memclose(m); 2.65 -}
3.1 --- a/test/memstream_tests.h Tue Oct 09 16:46:29 2012 +0200 3.2 +++ b/test/memstream_tests.h Wed Oct 10 09:32:06 2012 +0200 3.3 @@ -19,8 +19,6 @@ 3.4 UCX_TEST_DECLARE(test_ucx_memgetc) 3.5 UCX_TEST_DECLARE(test_ucx_memwrite) 3.6 UCX_TEST_DECLARE(test_ucx_memread) 3.7 -UCX_TEST_DECLARE(test_ucx_memprintf) 3.8 -UCX_TEST_DECLARE(test_ucx_memscanf) 3.9 3.10 #ifdef __cplusplus 3.11 }
4.1 --- a/ucx/memstream.c Tue Oct 09 16:46:29 2012 +0200 4.2 +++ b/ucx/memstream.c Wed Oct 10 09:32:06 2012 +0200 4.3 @@ -69,10 +69,6 @@ 4.4 return stream->pos >= stream->length; 4.5 } 4.6 4.7 -int ucx_memoverflow(UcxMemstream *stream) { 4.8 - return stream->pos > stream->length; 4.9 -} 4.10 - 4.11 size_t ucx_memtell(UcxMemstream *stream) { 4.12 return stream->pos; 4.13 } 4.14 @@ -80,12 +76,8 @@ 4.15 size_t ucx_memio(void* d, size_t s, size_t n, UcxMemstream *m, _Bool read) { 4.16 size_t len; 4.17 if (m->pos + s*n > m->length) { 4.18 - if (ucx_memoverflow(m)) { 4.19 - len = 0; 4.20 - } else { 4.21 - len = m->length - m->pos; 4.22 - if (s > 1) len -= len%s; 4.23 - } 4.24 + len = m->length - m->pos; 4.25 + if (s > 1) len -= len%s; 4.26 } else { 4.27 len = s*n; 4.28 } 4.29 @@ -124,29 +116,3 @@ 4.30 return c; 4.31 } 4.32 } 4.33 - 4.34 -int ucx_memprintf(UcxMemstream *stream, const char* format, ...) { 4.35 - va_list v; 4.36 - va_start(v, format); 4.37 - int r = vsprintf((char*)stream->space+stream->pos, format, v); 4.38 - va_end(v); 4.39 - 4.40 - stream->pos += r; 4.41 - 4.42 - return r; 4.43 -} 4.44 - 4.45 -int ucx_memscanf(UcxMemstream *stream, const char* format, ...) { 4.46 - 4.47 - /* TODO: vsscanf returns the number of fields read, 4.48 - * we need the number of bytes */ 4.49 - 4.50 - va_list v; 4.51 - va_start(v, format); 4.52 - int r = vsscanf((char*)stream->space+stream->pos, format, v); 4.53 - va_end(v); 4.54 - 4.55 - stream->pos += r; 4.56 - 4.57 - return r; 4.58 -}
5.1 --- a/ucx/memstream.h Tue Oct 09 16:46:29 2012 +0200 5.2 +++ b/ucx/memstream.h Wed Oct 10 09:32:06 2012 +0200 5.3 @@ -37,16 +37,6 @@ 5.4 * 5.5 */ 5.6 int ucx_memeof(UcxMemstream *stream); 5.7 -/* 5.8 - * returns non-zero, iff the current stream position has exceeded the length 5.9 - * of the underlying buffer 5.10 - * 5.11 - * in contrast to ucx_memeof this function will return zero, if the current 5.12 - * position exactly matches the buffer length 5.13 - * 5.14 - * this function should be called after any ucx_memprintf/ucx_memscanf call 5.15 - */ 5.16 -int ucx_memoverflow(UcxMemstream *stream); 5.17 5.18 /* memwrite, memread, memputc and memreadc shall not generate overflows */ 5.19 size_t ucx_memio(void *d, size_t s, size_t n, UcxMemstream* m, _Bool read); 5.20 @@ -57,10 +47,6 @@ 5.21 int ucx_memputc(UcxMemstream *stream, int c); 5.22 int ucx_memgetc(UcxMemstream *stream); 5.23 5.24 -/* printf / scanf may generate overflows */ 5.25 -int ucx_memprintf(UcxMemstream *stream, const char* format, ...); 5.26 -int ucx_memscanf(UcxMemstream *stream, const char* format, ...); 5.27 - 5.28 #ifdef __cplusplus 5.29 } 5.30 #endif