From a720310c28ef0f491a81f69dfa83a538fdbc1d79 Mon Sep 17 00:00:00 2001 From: Bruno Haible Date: Sat, 8 Sep 2018 15:36:36 +0200 Subject: [PATCH] Correct width of columns when outputting the asso_values array. Patch by Frank Wojcik . * src/output.cc (Output::output_hash_function): Increase the field_width by 1 if _max_hash_value+1 is a power of 10. --- ChangeLog | 7 +++++++ src/output.cc | 6 ++++-- 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/ChangeLog b/ChangeLog index 0f84fee..2cccbc7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +2018-09-08 Bruno Haible + + Correct width of columns when outputting the asso_values array. + Patch by Frank Wojcik . + * src/output.cc (Output::output_hash_function): Increase the + field_width by 1 if _max_hash_value+1 is a power of 10. + 2018-07-25 Bruno Haible Avoid "implicit fallthrough" warnings in the generated code. diff --git a/src/output.cc b/src/output.cc index 2e95a31..e8370b1 100644 --- a/src/output.cc +++ b/src/output.cc @@ -851,6 +851,8 @@ Output::output_hash_function () const /* First the asso_values array. */ if (_key_positions.get_size() > 0) { + /* The values in the asso_values array are all unsigned integers + <= MAX_HASH_VALUE + 1. */ printf (" static %s%s asso_values[] =\n" " {", const_readonly_array, @@ -858,9 +860,9 @@ Output::output_hash_function () const const int columns = 10; - /* Calculate maximum number of digits required for MAX_HASH_VALUE. */ + /* Calculate maximum number of digits required for MAX_HASH_VALUE + 1. */ int field_width = 2; - for (int trunc = _max_hash_value; (trunc /= 10) > 0;) + for (int trunc = _max_hash_value + 1; (trunc /= 10) > 0;) field_width++; for (unsigned int count = 0; count < _alpha_size; count++)