From c2606028900b878220de9ce6e66fcc4975161c67 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nils=20O=2E=20Sel=C3=A5sdal?= Date: Sun, 18 Nov 2012 14:12:05 +0100 Subject: [PATCH] Add gcc printf attribute to gbuf_printf. More gbuf tests --- include/ucore/ucore_buffer.h | 3 ++- test/test_buffer.c | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/include/ucore/ucore_buffer.h b/include/ucore/ucore_buffer.h index 851d72d..f49f339 100644 --- a/include/ucore/ucore_buffer.h +++ b/include/ucore/ucore_buffer.h @@ -70,7 +70,8 @@ int uc_gbuf_append(GBuf *buf,const void *data,size_t len); * @return The number of chars written excluding the terminating nul * character , or negative if an error occurs */ -int uc_gbuf_printf(GBuf *buf, const char *fmt, ...); +int uc_gbuf_printf(GBuf *buf, const char *fmt, ...) + __attribute__((format(printf, 2, 3))); /** Expand the capacity of the GBuf. * diff --git a/test/test_buffer.c b/test/test_buffer.c index a74ad55..7151f52 100644 --- a/test/test_buffer.c +++ b/test/test_buffer.c @@ -69,6 +69,19 @@ START_TEST (test_gbuf_printf2) END_TEST +START_TEST (test_gbuf_printf_empty_string) + int rc; + GBuf *buf = uc_new_gbuf(1); + const char *fmt = ""; //tricks gcc to not warn about empty format string + + fail_if(buf == NULL); + + rc = uc_gbuf_printf(buf, fmt); + fail_if(rc != 0); + fail_if(buf->used != 0); + +END_TEST + Suite *buffer_suite(void) { @@ -79,6 +92,7 @@ Suite *buffer_suite(void) tcase_add_test(tc, test_gbuf_grow); tcase_add_test(tc, test_gbuf_printf1); tcase_add_test(tc, test_gbuf_printf2); + tcase_add_test(tc, test_gbuf_printf_empty_string); suite_add_tcase(s, tc);