From: Junio C Hamano Date: Tue, 17 Nov 2026 18:11:31 GMT Subject: Re: [PATCH 1/2] utf8: respect bounds in utf8_strnwidth() Message-ID: In-Reply-To: Dirk Gouders writes: >> An update to display_mode_esc_sequence_len() to take the length >> limit, including its fallout, is shown below, and it does not look >> too bad. Not even compile-tested, but it should be sufficient as an >> illustration of the idea. >> >> This does not make your "after display_mode_esc_sequence_len() >> skips, make sure if we still have remaining string to grab one UTF-8 >> character" change unnecessary, as I said. > > My v2 would have introduced two new functions (see attached) to replace > display_mode_esc_sequence_len(): A two-function arrangement would be a good idea for maintainability. Add display_mode_esc_sequence_len_counted() to use the counted string API, with display_mode_esc_sequence_len() keeping the original calling convention (i.e., we call strlen(s) then call the new helper). I was too lazy to do the function pair in the illustration patch, which caused all existing callers to be affected, but given that there is another topic or two that are just being proposed that would add more callers to this function, it probably makes sense to keep a function with the NUL-terminated string API as before, and add the counted interface for callers that care, like the one you are fixing. Thanks.