-
Joao Gramacho authored
Problem: ======= The get_string_length() function is failing to assert the correct string length of numbers with 19 digits. Analysis: ======== The get_string_length() function returns the length a string must have in order to store a given number. It is used to calculate the string length of a GTID set. Because this function is static at rpl_gtid_set.cc, it is not trivial to make unit tests to verify its functionality. So, there is an assert executed only in debug enabled versions that checks if the value to be returned is equal to the length of printing the number in a string with snprintf(). Because of the precision of the rpl_gno data type (int64), an auxiliary variable may overflow when the number to be evaluated has 19 digits. The currently implemented code doesn't take into account this overflow possibility, making that every 19 digit number be evaluated as having 20 digits in length. This divergence cause the assert to fail. Fix: === Changed the function code replacing the length calculation algorithm with one that is simple, easy to read and overflow free.
Joao Gramacho authoredProblem: ======= The get_string_length() function is failing to assert the correct string length of numbers with 19 digits. Analysis: ======== The get_string_length() function returns the length a string must have in order to store a given number. It is used to calculate the string length of a GTID set. Because this function is static at rpl_gtid_set.cc, it is not trivial to make unit tests to verify its functionality. So, there is an assert executed only in debug enabled versions that checks if the value to be returned is equal to the length of printing the number in a string with snprintf(). Because of the precision of the rpl_gno data type (int64), an auxiliary variable may overflow when the number to be evaluated has 19 digits. The currently implemented code doesn't take into account this overflow possibility, making that every 19 digit number be evaluated as having 20 digits in length. This divergence cause the assert to fail. Fix: === Changed the function code replacing the length calculation algorithm with one that is simple, easy to read and overflow free.
Loading