diff options
author | David Robillard <d@drobilla.net> | 2020-07-15 20:35:12 +0200 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2020-07-17 15:42:20 +0200 |
commit | 444cfd7b8fa1066ae77a92e7466b0320eacab720 (patch) | |
tree | 782f4aa483dbe72d5ee7fcbf5347168813b5e074 /src | |
parent | 616517f44ceeacb26592e50e2bf914aad2d93b90 (diff) | |
download | sord-444cfd7b8fa1066ae77a92e7466b0320eacab720.tar.gz sord-444cfd7b8fa1066ae77a92e7466b0320eacab720.tar.bz2 sord-444cfd7b8fa1066ae77a92e7466b0320eacab720.zip |
Fix incorrect printf format specifiers
Diffstat (limited to 'src')
-rw-r--r-- | src/sord.c | 9 | ||||
-rw-r--r-- | src/sord_test.c | 18 | ||||
-rw-r--r-- | src/sord_validate.c | 9 |
3 files changed, 29 insertions, 7 deletions
@@ -30,6 +30,12 @@ #include "sord_config.h" #include "sord_internal.h" +#ifdef __GNUC__ +# define SORD_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +# define SORD_LOG_FUNC(fmt, arg1) +#endif + #define SORD_LOG(prefix, ...) fprintf(stderr, "[Sord::" prefix "] " __VA_ARGS__) #ifdef SORD_DEBUG_ITER @@ -173,6 +179,7 @@ sord_node_hash_equal(const void* a, const void* b) (serd_node_equals(&a_node->node, &b_node->node))); } +SORD_LOG_FUNC(3, 4) static void error(SordWorld* world, SerdStatus st, const char* fmt, ...) { @@ -803,7 +810,7 @@ sord_find(SordModel* model, const SordQuad pat) int n_prefix; const SordOrder index_order = sord_best_index(model, pat, &mode, &n_prefix); - SORD_FIND_LOG("Find " TUP_FMT " index=%s mode=%d n_prefix=%d\n", + SORD_FIND_LOG("Find " TUP_FMT " index=%s mode=%u n_prefix=%d\n", TUP_FMT_ARGS(pat), order_names[index_order], mode, n_prefix); if (pat[0] && pat[1] && pat[2] && pat[3]) { diff --git a/src/sord_test.c b/src/sord_test.c index 1ab350a..3553d4c 100644 --- a/src/sord_test.c +++ b/src/sord_test.c @@ -14,6 +14,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#include <inttypes.h> #include <stdarg.h> #include <stdio.h> #include <stdlib.h> @@ -21,6 +22,12 @@ #include "sord/sord.h" +#ifdef __GNUC__ +# define SORD_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +# define SORD_LOG_FUNC(fmt, arg1) +#endif + static const int DIGITS = 3; static const unsigned n_objects_per = 2; @@ -46,6 +53,7 @@ uri(SordWorld* world, int num) return sord_new_uri(world, (const uint8_t*)str); } +SORD_LOG_FUNC(1, 2) static int test_fail(const char* fmt, ...) { @@ -280,7 +288,7 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g, return test_fail("Fail: Expected %d results, got %d\n", test.expected_num_results, num_results); } - fprintf(stderr, "OK (%u matches)\n", test.expected_num_results); + fprintf(stderr, "OK (%i matches)\n", test.expected_num_results); } // Query blank node subject @@ -320,7 +328,7 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g, SordQuad subpat = { id[0], 0, 0 }; SordIter* subiter = sord_find(sord, subpat); - uint64_t num_sub_results = 0; + unsigned num_sub_results = 0; if (sord_iter_get_node(subiter, SORD_SUBJECT) != id[0]) { return test_fail("Fail: Incorrect initial submatch\n"); } @@ -339,14 +347,14 @@ test_read(SordWorld* world, SordModel* sord, SordNode* g, if (num_sub_results != n_objects_per) { return test_fail( "Fail: Nested query " TUP_FMT " failed" - " (%d results, expected %d)\n", + " (%u results, expected %u)\n", TUP_FMT_ARGS(subpat), num_sub_results, n_objects_per); } uint64_t count = sord_count(sord, id[0], 0, 0, 0); if (count != num_sub_results) { - return test_fail("Fail: Query " TUP_FMT " sord_count() %d" - "does not match result count %d\n", + return test_fail("Fail: Query " TUP_FMT " sord_count() %" PRIu64 + "does not match result count %u\n", TUP_FMT_ARGS(subpat), count, num_sub_results); } diff --git a/src/sord_validate.c b/src/sord_validate.c index a5c8d45..037629c 100644 --- a/src/sord_validate.c +++ b/src/sord_validate.c @@ -33,6 +33,12 @@ # include <pcre.h> #endif +#ifdef __GNUC__ +# define SORD_LOG_FUNC(fmt, arg1) __attribute__((format(printf, fmt, arg1))) +#else +# define SORD_LOG_FUNC(fmt, arg1) +#endif + #define USTR(s) ((const uint8_t*)(s)) #define NS_foaf (const uint8_t*)"http://xmlns.com/foaf/0.1/" @@ -127,6 +133,7 @@ absolute_path(const uint8_t* path) #endif } +SORD_LOG_FUNC(2, 3) static int errorf(const SordQuad quad, const char* fmt, ...) { @@ -491,7 +498,7 @@ check_properties(SordModel* model, URIs* uris) if (is_FunctionalProperty) { SordIter* o = sord_search(model, subj, pred, NULL, NULL); - const uint64_t n = count_non_blanks(o, SORD_OBJECT); + const unsigned n = count_non_blanks(o, SORD_OBJECT); if (n > 1) { st = errorf(quad, "Functional property with %u objects", n); } |