diff options
author | Kevin Newton <[email protected]> | 2023-10-26 22:04:54 -0400 |
---|---|---|
committer | git <[email protected]> | 2023-10-27 14:23:17 +0000 |
commit | 26a05c42173f0f6ad188a28c3ea508b18b376d6b (patch) | |
tree | bc3d301cf6eb5954cec8b7d1c6189ce2a84cf653 /prism | |
parent | 15ee9c7c1b693f29b6b2dbe7b47488bf154e481c (diff) |
[ruby/prism] Use printf attribute and then fix warnings
https://github.com/ruby/prism/commit/3193902c43
Diffstat (limited to 'prism')
-rw-r--r-- | prism/defines.h | 9 | ||||
-rw-r--r-- | prism/templates/src/prettyprint.c.erb | 4 | ||||
-rw-r--r-- | prism/util/pm_buffer.h | 2 |
3 files changed, 12 insertions, 3 deletions
diff --git a/prism/defines.h b/prism/defines.h index 6037ae7e26..531462a560 100644 --- a/prism/defines.h +++ b/prism/defines.h @@ -23,6 +23,15 @@ # endif #endif +// PRISM_ATTRIBUTE_FORMAT +#if defined(__GNUC__) +# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((format(printf, string_index, argument_index))) +#elif defined(__clang__) +# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) __attribute__((__format__(__printf__, string_index, argument_index))) +#else +# define PRISM_ATTRIBUTE_FORMAT(string_index, argument_index) +#endif + // PRISM_ATTRIBUTE_UNUSED #if defined(__GNUC__) # define PRISM_ATTRIBUTE_UNUSED __attribute__((unused)) diff --git a/prism/templates/src/prettyprint.c.erb b/prism/templates/src/prettyprint.c.erb index ecd2c227df..2309a86f1f 100644 --- a/prism/templates/src/prettyprint.c.erb +++ b/prism/templates/src/prettyprint.c.erb @@ -39,7 +39,7 @@ static inline void prettyprint_location(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm_location_t *location) { pm_line_column_t start = pm_newline_list_line_column(&parser->newline_list, location->start); pm_line_column_t end = pm_newline_list_line_column(&parser->newline_list, location->end); - pm_buffer_append_format(output_buffer, "(%d,%d)-(%d,%d)", start.line + 1, start.column, end.line + 1, end.column); + pm_buffer_append_format(output_buffer, "(%lu,%lu)-(%lu,%lu)", (unsigned long) (start.line + 1), (unsigned long) start.column, (unsigned long) (end.line + 1), (unsigned long) end.column); } static inline void @@ -95,7 +95,7 @@ prettyprint_node(pm_buffer_t *output_buffer, const pm_parser_t *parser, const pm prettyprint_source(output_buffer, pm_string_source(&cast-><%= field.name %>), pm_string_length(&cast-><%= field.name %>)); pm_buffer_append_string(output_buffer, "\"\n", 2); <%- when Prism::NodeListField -%> - pm_buffer_append_format(output_buffer, " (length: %d)\n", cast-><%= field.name %>.size); + pm_buffer_append_format(output_buffer, " (length: %lu)\n", (unsigned long) (cast-><%= field.name %>.size)); size_t last_index = cast-><%= field.name %>.size; for (uint32_t index = 0; index < last_index; index++) { diff --git a/prism/util/pm_buffer.h b/prism/util/pm_buffer.h index b8b7c41a10..69edb1525a 100644 --- a/prism/util/pm_buffer.h +++ b/prism/util/pm_buffer.h @@ -37,7 +37,7 @@ PRISM_EXPORTED_FUNCTION size_t pm_buffer_length(pm_buffer_t *buffer); void pm_buffer_append_zeroes(pm_buffer_t *buffer, size_t length); // Append a formatted string to the buffer. -void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...); +void pm_buffer_append_format(pm_buffer_t *buffer, const char *format, ...) PRISM_ATTRIBUTE_FORMAT(2, 3); // Append a string to the buffer. void pm_buffer_append_string(pm_buffer_t *buffer, const char *value, size_t length); |