diff options
author | David Robillard <d@drobilla.net> | 2024-06-22 13:41:32 -0400 |
---|---|---|
committer | David Robillard <d@drobilla.net> | 2024-06-22 13:41:32 -0400 |
commit | 5d9addc9acc41890b34a2d53d1115394a0d145a5 (patch) | |
tree | 139a9412b78017e24d847589770cf50abb708d04 | |
parent | 459886c42ed114d951a3cf3d1f61d02ec90456b5 (diff) | |
download | serd-5d9addc9acc41890b34a2d53d1115394a0d145a5.tar.gz serd-5d9addc9acc41890b34a2d53d1115394a0d145a5.tar.bz2 serd-5d9addc9acc41890b34a2d53d1115394a0d145a5.zip |
Avoid non-enum switches with missing default cases
-rw-r--r-- | src/.clang-tidy | 1 | ||||
-rw-r--r-- | src/n3.c | 49 |
2 files changed, 25 insertions, 25 deletions
diff --git a/src/.clang-tidy b/src/.clang-tidy index b6882d38..ea728e33 100644 --- a/src/.clang-tidy +++ b/src/.clang-tidy @@ -4,7 +4,6 @@ Checks: > -*-magic-numbers, -bugprone-easily-swappable-parameters, - -bugprone-switch-missing-default-case, -cert-err33-c, -clang-analyzer-security.insecureAPI.DeprecatedOrUnsafeBufferHandling, -clang-analyzer-valist.Uninitialized, @@ -935,8 +935,8 @@ read_literal(SerdReader* const reader, return st; } - switch (peek_byte(reader)) { - case '@': + const int next = peek_byte(reader); + if (next == '@') { skip_byte(reader, '@'); if ((st = read_LANGTAG(reader, lang))) { *datatype = pop_node(reader, *datatype); @@ -944,8 +944,7 @@ read_literal(SerdReader* const reader, *dest = pop_node(reader, *dest); return r_err(reader, st, "bad language tag\n"); } - break; - case '^': + } else if (next == '^') { skip_byte(reader, '^'); if (!eat_byte_check(reader, '^')) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "expected '^'\n"); @@ -957,7 +956,6 @@ read_literal(SerdReader* const reader, *dest = pop_node(reader, *dest); return r_err(reader, st, "bad datatype\n"); } - break; } return SERD_SUCCESS; @@ -1282,14 +1280,16 @@ read_predicateObjectList(SerdReader* const reader, int c = 0; do { read_ws_star(reader); - switch (c = peek_byte(reader)) { - case EOF: + c = peek_byte(reader); + if (c < 0) { return r_err(reader, SERD_ERR_BAD_SYNTAX, "unexpected end of file\n"); - case '.': - case ']': - case '}': + } + + if (c == '.' || c == ']' || c == '}') { return SERD_SUCCESS; - case ';': + } + + if (c == ';') { skip_byte(reader, c); ate_semi = true; } @@ -1443,13 +1443,16 @@ read_triples(SerdReader* const reader, ReadContext ctx, bool* const ate_dot) SerdStatus st = SERD_FAILURE; if (ctx.subject) { read_ws_star(reader); - switch (peek_byte(reader)) { - case '.': + const int c = peek_byte(reader); + if (c == '.') { *ate_dot = eat_byte_safe(reader, '.'); return SERD_FAILURE; - case '}': + } + + if (c == '}') { return SERD_FAILURE; } + st = read_predicateObjectList(reader, ctx, ate_dot); } @@ -1528,22 +1531,20 @@ read_directive(SerdReader* const reader) const bool sparql = peek_byte(reader) != '@'; if (!sparql) { skip_byte(reader, '@'); - switch (peek_byte(reader)) { - case 'B': - case 'P': + const int next = peek_byte(reader); + if (next == 'B' || next == 'P') { return r_err(reader, SERD_ERR_BAD_SYNTAX, "uppercase directive\n"); } } - switch (peek_byte(reader)) { - case 'B': - case 'b': + const int next = peek_byte(reader); + + if (next == 'B' || next == 'b') { return read_base(reader, sparql, true); - case 'P': - case 'p': + } + + if (next == 'P' || next == 'p') { return read_prefixID(reader, sparql, true); - default: - break; } return r_err(reader, SERD_ERR_BAD_SYNTAX, "invalid directive\n"); |