mirror of
https://github.com/rkd77/elinks.git
synced 2025-02-02 15:09:23 -05:00
Bug 968: Don't use copy_chars in justify_line.
All the needed memory has been allocated before the loop so we can use copy_screen_chars() directly. This avoids the assertion failure in copy_chars() for width==0 and should be a bit faster too. According to ISO/IEC 9899:1999 7.21.1p2, memcpy() doesn't copy anything if n==0 (but the pointers must be valid). (original 'git cherry-pick' arguments: cherry-pick bug968-att394)
This commit is contained in:
parent
fd902e81da
commit
0cb047b298
@ -1132,9 +1132,16 @@ justify_line(struct html_context *html_context, int y)
|
||||
word_shift = (word * diff) / (spaces - 1);
|
||||
new_start = word_start + word_shift;
|
||||
|
||||
/* Copy the original word, without any spaces. */
|
||||
copy_chars(html_context, new_start, y, word_len,
|
||||
&line[word_start]);
|
||||
/* Assert that the realloc_line() above
|
||||
* allocated enough memory for the word
|
||||
* and the preceding spaces. */
|
||||
assert(LEN(y) >= new_start + word_len);
|
||||
if_assert_failed continue;
|
||||
|
||||
/* Copy the original word, without any spaces.
|
||||
* word_len may be 0 here. */
|
||||
copy_screen_chars(&POS(new_start, y),
|
||||
&line[word_start], word_len);
|
||||
|
||||
/* Copy the space that preceded the word,
|
||||
* duplicating it as many times as necessary.
|
||||
@ -1146,10 +1153,6 @@ justify_line(struct html_context *html_context, int y)
|
||||
if (word) {
|
||||
int spacex;
|
||||
|
||||
/* realloc_line() was called above. */
|
||||
assert(LEN(y) >= new_start);
|
||||
if_assert_failed continue;
|
||||
|
||||
for (spacex = prev_end; spacex < new_start;
|
||||
++spacex) {
|
||||
copy_screen_chars(&POS(spacex, y),
|
||||
|
Loading…
x
Reference in New Issue
Block a user