Skip to content
Snippets Groups Projects
Commit 55468798 authored by Neal Cardwell's avatar Neal Cardwell
Browse files

packetdrill: fix clang compilation error on FreeBSD 10.x


Rewrite an if conditional that clang complained about on FreeBSD 10.x.

Signed-off-by: default avatarNeal Cardwell <ncardwell@google.com>
parent c08c793e
No related branches found
No related tags found
No related merge requests found
...@@ -52,6 +52,7 @@ struct expression_type_entry { ...@@ -52,6 +52,7 @@ struct expression_type_entry {
const char *name; const char *name;
}; };
struct expression_type_entry expression_type_table[] = { struct expression_type_entry expression_type_table[] = {
{ EXPR_NONE, "none" },
{ EXPR_ELLIPSIS, "ellipsis" }, { EXPR_ELLIPSIS, "ellipsis" },
{ EXPR_INTEGER, "integer" }, { EXPR_INTEGER, "integer" },
{ EXPR_WORD, "word" }, { EXPR_WORD, "word" },
...@@ -64,7 +65,7 @@ struct expression_type_entry expression_type_table[] = { ...@@ -64,7 +65,7 @@ struct expression_type_entry expression_type_table[] = {
{ EXPR_IOVEC, "iovec" }, { EXPR_IOVEC, "iovec" },
{ EXPR_MSGHDR, "msghdr" }, { EXPR_MSGHDR, "msghdr" },
{ EXPR_POLLFD, "pollfd" }, { EXPR_POLLFD, "pollfd" },
{-1, NULL} { NUM_EXPR_TYPES, NULL}
}; };
const char *expression_type_to_string(enum expression_t type) const char *expression_type_to_string(enum expression_t type)
...@@ -261,7 +262,8 @@ void free_expression(struct expression *expression) ...@@ -261,7 +262,8 @@ void free_expression(struct expression *expression)
{ {
if (expression == NULL) if (expression == NULL)
return; return;
if ((expression->type < 0) || (expression->type >= NUM_EXPR_TYPES)) if ((expression->type <= EXPR_NONE) ||
(expression->type >= NUM_EXPR_TYPES))
assert(!"bad expression type"); assert(!"bad expression type");
switch (expression->type) { switch (expression->type) {
case EXPR_ELLIPSIS: case EXPR_ELLIPSIS:
...@@ -313,6 +315,7 @@ void free_expression(struct expression *expression) ...@@ -313,6 +315,7 @@ void free_expression(struct expression *expression)
free_expression(expression->value.pollfd->events); free_expression(expression->value.pollfd->events);
free_expression(expression->value.pollfd->revents); free_expression(expression->value.pollfd->revents);
break; break;
case EXPR_NONE:
case NUM_EXPR_TYPES: case NUM_EXPR_TYPES:
break; break;
/* missing default case so compiler catches missing cases */ /* missing default case so compiler catches missing cases */
...@@ -460,7 +463,8 @@ static int evaluate(struct expression *in, ...@@ -460,7 +463,8 @@ static int evaluate(struct expression *in,
*out_ptr = out; *out_ptr = out;
out->type = in->type; /* most types of expression stay the same */ 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); asprintf(error, "bad expression type: %d", in->type);
return STATUS_ERR; return STATUS_ERR;
} }
...@@ -513,6 +517,7 @@ static int evaluate(struct expression *in, ...@@ -513,6 +517,7 @@ static int evaluate(struct expression *in,
case EXPR_POLLFD: case EXPR_POLLFD:
result = evaluate_pollfd_expression(in, out, error); result = evaluate_pollfd_expression(in, out, error);
break; break;
case EXPR_NONE:
case NUM_EXPR_TYPES: case NUM_EXPR_TYPES:
break; break;
/* missing default case so compiler catches missing cases */ /* missing default case so compiler catches missing cases */
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
/* The types of expressions in a script */ /* The types of expressions in a script */
enum expression_t { enum expression_t {
EXPR_NONE,
EXPR_ELLIPSIS, /* ... but no value */ EXPR_ELLIPSIS, /* ... but no value */
EXPR_INTEGER, /* integer in 'num' */ EXPR_INTEGER, /* integer in 'num' */
EXPR_LINGER, /* struct linger for SO_LINGER */ EXPR_LINGER, /* struct linger for SO_LINGER */
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment