mirror of
https://github.com/rkd77/elinks.git
synced 2024-11-04 08:17:17 -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).
This commit is contained in:
parent
eecba4a96c
commit
db13653fb0
@ -1132,9 +1132,16 @@ justify_line(struct html_context *html_context, int y)
|
|||||||
word_shift = (word * diff) / (spaces - 1);
|
word_shift = (word * diff) / (spaces - 1);
|
||||||
new_start = word_start + word_shift;
|
new_start = word_start + word_shift;
|
||||||
|
|
||||||
/* Copy the original word, without any spaces. */
|
/* Assert that the realloc_line() above
|
||||||
copy_chars(html_context, new_start, y, word_len,
|
* allocated enough memory for the word
|
||||||
&line[word_start]);
|
* 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,
|
/* Copy the space that preceded the word,
|
||||||
* duplicating it as many times as necessary.
|
* duplicating it as many times as necessary.
|
||||||
@ -1146,10 +1153,6 @@ justify_line(struct html_context *html_context, int y)
|
|||||||
if (word) {
|
if (word) {
|
||||||
int spacex;
|
int spacex;
|
||||||
|
|
||||||
/* realloc_line() was called above. */
|
|
||||||
assert(LEN(y) >= new_start);
|
|
||||||
if_assert_failed continue;
|
|
||||||
|
|
||||||
for (spacex = prev_end; spacex < new_start;
|
for (spacex = prev_end; spacex < new_start;
|
||||||
++spacex) {
|
++spacex) {
|
||||||
copy_screen_chars(&POS(spacex, y),
|
copy_screen_chars(&POS(spacex, y),
|
||||||
|
Loading…
Reference in New Issue
Block a user