The left_size and right_size variables are no longer maintained. The allocated size of each string is simply strlen(left) + 1 and strlen(right) + 1, respectively. This removes the possibility for state drifting out of sync.
The system allocator is now aware of the exact extent of these strings. This should help ASan/Valgrind/etc catch misuses.
We possibly lose some optimisation in this change, but it is not relevant as all this code is in logic where the user is interacting with the system. That is, we spend most of our time waiting for the user to type a character anyway.
This change has two primary motivations:
The
left_size
andright_size
variables are no longer maintained. The allocated size of each string is simplystrlen(left) + 1
andstrlen(right) + 1
, respectively. This removes the possibility for state drifting out of sync.The system allocator is now aware of the exact extent of these strings. This should help ASan/Valgrind/etc catch misuses.
We possibly lose some optimisation in this change, but it is not relevant as all this code is in logic where the user is interacting with the system. That is, we spend most of our time waiting for the user to type a character anyway.