From 35db90c5d10ad50579d3aa3752f8517d9d3c1887 Mon Sep 17 00:00:00 2001 From: "Jonah H. Harris" Date: Fri, 5 Jun 2020 10:50:32 -0400 Subject: [PATCH] 64-bit integer printf uses C99 format specifiers --- src/betree.c | 10 +++++----- src/betree.h | 2 ++ src/debug.c | 12 ++++++------ src/printer.c | 20 ++++++++++---------- src/tree.c | 2 +- 5 files changed, 24 insertions(+), 22 deletions(-) diff --git a/src/betree.c b/src/betree.c index 0c214da..1ab0766 100644 --- a/src/betree.c +++ b/src/betree.c @@ -522,17 +522,17 @@ bool betree_insert_with_constants(struct betree* tree, { struct ast_node* node; if(parse(expr, &node) != 0) { - fprintf(stderr, "Can't parse %ld\n", id); + fprintf(stderr, "Can't parse %"PRIbst"\n", id); return false; } assign_variable_id(tree->config, node); if(!is_valid(tree->config, node)) { - fprintf(stderr, "Can't validate %ld\n", id); + fprintf(stderr, "Can't validate %"PRIbst"\n", id); free_ast_node(node); return false; } if(!assign_constants(constant_count, constants, node)) { - fprintf(stderr, "Can't assign constants %ld\n", id); + fprintf(stderr, "Can't assign constants %"PRIbst"\n", id); return false; } assign_str_id(tree->config, node, false); @@ -548,7 +548,7 @@ const struct betree_sub* betree_make_sub(struct betree* tree, betree_sub_t id, s { struct ast_node* node; if(parse(expr, &node) != 0) { - fprintf(stderr, "Can't parse %ld\n", id); + fprintf(stderr, "Can't parse %"PRIbst"\n", id); return false; } assign_variable_id(tree->config, node); @@ -561,7 +561,7 @@ const struct betree_sub* betree_make_sub(struct betree* tree, betree_sub_t id, s return false; } if(!assign_constants(constant_count, constants, node)) { - fprintf(stderr, "Can't assign constants %ld\n", id); + fprintf(stderr, "Can't assign constants %"PRIbst"\n", id); return false; } assign_str_id(tree->config, node, true); diff --git a/src/betree.h b/src/betree.h index 63be8b5..1a93a74 100644 --- a/src/betree.h +++ b/src/betree.h @@ -3,8 +3,10 @@ #include #include #include +#include typedef uint64_t betree_sub_t; +#define PRIbst PRIu64 struct config; struct cnode; diff --git a/src/debug.c b/src/debug.c index 772c554..8ceee3a 100644 --- a/src/debug.c +++ b/src/debug.c @@ -210,7 +210,7 @@ static void write_dot_file_lnode_names( fprintf(f, ", "); } } - fprintf(f, "S%lu", lnode->subs[i]->id); + fprintf(f, "S%"PRIbst"", lnode->subs[i]->id); } fprintf(f, "\\}>, color=lightblue1, fillcolor=lightblue1, style=filled, shape=record]\n"); } @@ -241,7 +241,7 @@ static void write_dot_file_cdir_td(FILE* f, if(current_depth == 0) { print_spaces(f, level); if(cdir == NULL) { - fprintf(f, "\n", colspan); + fprintf(f, "\n", colspan); } else { const char* name = get_name_cdir(config, cdir); @@ -249,7 +249,7 @@ static void write_dot_file_cdir_td(FILE* f, case(BETREE_INTEGER): case(BETREE_INTEGER_LIST): fprintf(f, - "[%ld, %ld]\n", + "[%"PRIi64", %"PRIi64"]\n", colspan, name, cdir->bound.imin, @@ -257,7 +257,7 @@ static void write_dot_file_cdir_td(FILE* f, break; case(BETREE_FLOAT): { fprintf(f, - "[%.0f, %.0f]\n", + "[%.0f, %.0f]\n", colspan, name, cdir->bound.fmin, @@ -268,7 +268,7 @@ static void write_dot_file_cdir_td(FILE* f, const char* min = cdir->bound.bmin ? "true" : "false"; const char* max = cdir->bound.bmax ? "true" : "false"; fprintf(f, - "[%s, %s]\n", + "[%s, %s]\n", colspan, name, min, @@ -280,7 +280,7 @@ static void write_dot_file_cdir_td(FILE* f, case(BETREE_INTEGER_ENUM): case(BETREE_INTEGER_LIST_ENUM): fprintf(f, - "[%zu, %zu]\n", + "[%zu, %zu]\n", colspan, name, cdir->bound.smin, diff --git a/src/printer.c b/src/printer.c index e2b5b96..b7e27eb 100644 --- a/src/printer.c +++ b/src/printer.c @@ -393,7 +393,7 @@ void print_variable(const struct betree_variable* v) printf("%s", v->value.boolean_value ? "true" : "false"); break; case BETREE_INTEGER: - printf("%ld", v->value.integer_value); + printf("%"PRIi64, v->value.integer_value); break; case BETREE_FLOAT: printf("%.2f", v->value.float_value); @@ -410,7 +410,7 @@ void print_variable(const struct betree_variable* v) printf("%s", inner); break; case BETREE_INTEGER_ENUM: - printf("%ld", v->value.integer_enum_value.integer); + printf("%"PRIi64, v->value.integer_enum_value.integer); break; case BETREE_INTEGER_LIST_ENUM: inner = integer_enum_list_value_to_string(v->value.integer_enum_list_value); @@ -450,13 +450,13 @@ void print_attr_domain(const struct attr_domain* domain) printf("INT64_MIN, "); } else { - printf("%ld, ", domain->bound.imin); + printf("%"PRIi64", ", domain->bound.imin); } if(domain->bound.imax == INT64_MAX) { printf("INT64_MAX]\n"); } else { - printf("%ld]\n", domain->bound.imax); + printf("%"PRIi64"]\n", domain->bound.imax); } break; case BETREE_FLOAT: @@ -492,13 +492,13 @@ void print_attr_domain(const struct attr_domain* domain) printf("INT64_MIN, "); } else { - printf("%ld, ", domain->bound.imin); + printf("%"PRIi64", ", domain->bound.imin); } if(domain->bound.imax == INT64_MAX) { printf("INT64_MAX]\n"); } else { - printf("%ld]\n", domain->bound.imax); + printf("%"PRIi64"]\n", domain->bound.imax); } break; case BETREE_STRING_LIST: @@ -558,13 +558,13 @@ void print_cdir(const struct cdir* cdir) printf("INT64_MIN, "); } else { - printf("%ld, ", cdir->bound.imin); + printf("%"PRIi64", ", cdir->bound.imin); } if(cdir->bound.imax == INT64_MAX) { printf("INT64_MAX]\n"); } else { - printf("%ld]\n", cdir->bound.imax); + printf("%"PRIi64"]\n", cdir->bound.imax); } break; case BETREE_FLOAT: @@ -597,13 +597,13 @@ void print_cdir(const struct cdir* cdir) printf("INT64_MIN, "); } else { - printf("%ld, ", cdir->bound.imin); + printf("%"PRIi64", ", cdir->bound.imin); } if(cdir->bound.imax == INT64_MAX) { printf("INT64_MAX]\n"); } else { - printf("%ld]\n", cdir->bound.imax); + printf("%"PRIi64"]\n", cdir->bound.imax); } break; case BETREE_STRING_LIST: diff --git a/src/tree.c b/src/tree.c index 1978004..10dec14 100644 --- a/src/tree.c +++ b/src/tree.c @@ -1682,7 +1682,7 @@ void event_to_string(const struct betree_event* event, char* buffer) break; } case(BETREE_INTEGER_ENUM): { - length += sprintf(buffer + length, "%s = %ld", attr, pred->value.integer_enum_value.integer); + length += sprintf(buffer + length, "%s = %"PRIi64, attr, pred->value.integer_enum_value.integer); break; } case(BETREE_INTEGER_LIST_ENUM): {