From 55468798bea3099c4db890d0a533826cbc8118f7 Mon Sep 17 00:00:00 2001 From: Neal Cardwell <ncardwell@google.com> Date: Thu, 14 Nov 2013 09:44:09 -0500 Subject: [PATCH] packetdrill: fix clang compilation error on FreeBSD 10.x Rewrite an if conditional that clang complained about on FreeBSD 10.x. Signed-off-by: Neal Cardwell <ncardwell@google.com> --- gtests/net/packetdrill/script.c | 11 ++++++++--- gtests/net/packetdrill/script.h | 1 + 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/gtests/net/packetdrill/script.c b/gtests/net/packetdrill/script.c index 7d452476..f6692030 100644 --- a/gtests/net/packetdrill/script.c +++ b/gtests/net/packetdrill/script.c @@ -52,6 +52,7 @@ struct expression_type_entry { const char *name; }; struct expression_type_entry expression_type_table[] = { + { EXPR_NONE, "none" }, { EXPR_ELLIPSIS, "ellipsis" }, { EXPR_INTEGER, "integer" }, { EXPR_WORD, "word" }, @@ -64,7 +65,7 @@ struct expression_type_entry expression_type_table[] = { { EXPR_IOVEC, "iovec" }, { EXPR_MSGHDR, "msghdr" }, { EXPR_POLLFD, "pollfd" }, - {-1, NULL} + { NUM_EXPR_TYPES, NULL} }; const char *expression_type_to_string(enum expression_t type) @@ -261,7 +262,8 @@ void free_expression(struct expression *expression) { if (expression == NULL) return; - if ((expression->type < 0) || (expression->type >= NUM_EXPR_TYPES)) + if ((expression->type <= EXPR_NONE) || + (expression->type >= NUM_EXPR_TYPES)) assert(!"bad expression type"); switch (expression->type) { case EXPR_ELLIPSIS: @@ -313,6 +315,7 @@ void free_expression(struct expression *expression) free_expression(expression->value.pollfd->events); free_expression(expression->value.pollfd->revents); break; + case EXPR_NONE: case NUM_EXPR_TYPES: break; /* missing default case so compiler catches missing cases */ @@ -460,7 +463,8 @@ static int evaluate(struct expression *in, *out_ptr = out; out->type = in->type; /* most types of expression stay the same */ - if ((in->type < 0) || (in->type >= NUM_EXPR_TYPES)) { + if ((in->type <= EXPR_NONE) || + (in->type >= NUM_EXPR_TYPES)) { asprintf(error, "bad expression type: %d", in->type); return STATUS_ERR; } @@ -513,6 +517,7 @@ static int evaluate(struct expression *in, case EXPR_POLLFD: result = evaluate_pollfd_expression(in, out, error); break; + case EXPR_NONE: case NUM_EXPR_TYPES: break; /* missing default case so compiler catches missing cases */ diff --git a/gtests/net/packetdrill/script.h b/gtests/net/packetdrill/script.h index c4797c59..ac14e65b 100644 --- a/gtests/net/packetdrill/script.h +++ b/gtests/net/packetdrill/script.h @@ -32,6 +32,7 @@ /* The types of expressions in a script */ enum expression_t { + EXPR_NONE, EXPR_ELLIPSIS, /* ... but no value */ EXPR_INTEGER, /* integer in 'num' */ EXPR_LINGER, /* struct linger for SO_LINGER */ -- GitLab