Fix warnings: screen.c: screen_puts_len(): Various (4): FP/MI.

Problems   : Assigned value is garbage or undefined @ 5363.
             Result of operation is garbage or undefined @ 5356.
             Result of operation is garbage or undefined @ 5320.
             Result of operation is garbage or undefined @ 5192.
Diagnostic : False positives / Multithreading issues.
Rationale  : Suggested error paths contain incoherent values for
             has_mbyte, enc_utf8, and enc_dbcs, which should always hold
             the relationship has_mbyte = enc_utf8 || enc_dbcs, with
             enc_utf8 and enc_dbcs being mutually exclusive.
             Asserting on the globals, though, fails, because checker
             believes they could be modified by other threads in
             between.
Resolution : Make local copy of globals and assert relationship on them.
This commit is contained in:
Eliseo Martínez 2015-02-20 10:39:47 +01:00
parent c48f835749
commit 56e339c594

View File

@ -86,6 +86,7 @@
* update_screen() called to redraw. * update_screen() called to redraw.
*/ */
#include <assert.h>
#include <errno.h> #include <errno.h>
#include <inttypes.h> #include <inttypes.h>
#include <stdbool.h> #include <stdbool.h>
@ -5176,17 +5177,24 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
int force_redraw_next = FALSE; int force_redraw_next = FALSE;
int need_redraw; int need_redraw;
const int l_has_mbyte = has_mbyte;
const bool l_enc_utf8 = enc_utf8;
const int l_enc_dbcs = enc_dbcs;
assert((l_has_mbyte == (l_enc_utf8 || l_enc_dbcs))
&& !(l_enc_utf8 && l_enc_dbcs));
if (ScreenLines == NULL || row >= screen_Rows) /* safety check */ if (ScreenLines == NULL || row >= screen_Rows) /* safety check */
return; return;
off = LineOffset[row] + col; off = LineOffset[row] + col;
/* When drawing over the right halve of a double-wide char clear out the /* When drawing over the right halve of a double-wide char clear out the
* left halve. Only needed in a terminal. */ * left halve. Only needed in a terminal. */
if (has_mbyte && col > 0 && col < screen_Columns if (l_has_mbyte && col > 0 && col < screen_Columns
&& mb_fix_col(col, row) != col) { && mb_fix_col(col, row) != col) {
ScreenLines[off - 1] = ' '; ScreenLines[off - 1] = ' ';
ScreenAttrs[off - 1] = 0; ScreenAttrs[off - 1] = 0;
if (enc_utf8) { if (l_enc_utf8) {
ScreenLinesUC[off - 1] = 0; ScreenLinesUC[off - 1] = 0;
ScreenLinesC[0][off - 1] = 0; ScreenLinesC[0][off - 1] = 0;
} }
@ -5202,14 +5210,14 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
&& *ptr != NUL) { && *ptr != NUL) {
c = *ptr; c = *ptr;
/* check if this is the first byte of a multibyte */ /* check if this is the first byte of a multibyte */
if (has_mbyte) { if (l_has_mbyte) {
if (enc_utf8 && len > 0) if (l_enc_utf8 && len > 0)
mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr)); mbyte_blen = utfc_ptr2len_len(ptr, (int)((text + len) - ptr));
else else
mbyte_blen = (*mb_ptr2len)(ptr); mbyte_blen = (*mb_ptr2len)(ptr);
if (enc_dbcs == DBCS_JPNU && c == 0x8e) if (l_enc_dbcs == DBCS_JPNU && c == 0x8e)
mbyte_cells = 1; mbyte_cells = 1;
else if (enc_dbcs != 0) else if (l_enc_dbcs != 0)
mbyte_cells = mbyte_blen; mbyte_cells = mbyte_blen;
else { /* enc_utf8 */ else { /* enc_utf8 */
if (len >= 0) if (len >= 0)
@ -5256,11 +5264,11 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
need_redraw = ScreenLines[off] != c need_redraw = ScreenLines[off] != c
|| (mbyte_cells == 2 || (mbyte_cells == 2
&& ScreenLines[off + 1] != (enc_dbcs ? ptr[1] : 0)) && ScreenLines[off + 1] != (l_enc_dbcs ? ptr[1] : 0))
|| (enc_dbcs == DBCS_JPNU || (l_enc_dbcs == DBCS_JPNU
&& c == 0x8e && c == 0x8e
&& ScreenLines2[off] != ptr[1]) && ScreenLines2[off] != ptr[1])
|| (enc_utf8 || (l_enc_utf8
&& (ScreenLinesUC[off] != && (ScreenLinesUC[off] !=
(u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c) (u8char_T)(c < 0x80 && u8cc[0] == 0 ? 0 : u8c)
|| (ScreenLinesUC[off] != 0 || (ScreenLinesUC[off] != 0
@ -5278,7 +5286,7 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
* (mb_off2cells() may return 2 on the right halve). */ * (mb_off2cells() may return 2 on the right halve). */
if (clear_next_cell) if (clear_next_cell)
clear_next_cell = FALSE; clear_next_cell = FALSE;
else if (has_mbyte else if (l_has_mbyte
&& (len < 0 ? ptr[mbyte_blen] == NUL && (len < 0 ? ptr[mbyte_blen] == NUL
: ptr + mbyte_blen >= text + len) : ptr + mbyte_blen >= text + len)
&& ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
@ -5289,7 +5297,7 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
/* Make sure we never leave a second byte of a double-byte behind, /* Make sure we never leave a second byte of a double-byte behind,
* it confuses mb_off2cells(). */ * it confuses mb_off2cells(). */
if (enc_dbcs if (l_enc_dbcs
&& ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1) && ((mbyte_cells == 1 && (*mb_off2cells)(off, max_off) > 1)
|| (mbyte_cells == 2 || (mbyte_cells == 2
&& (*mb_off2cells)(off, max_off) == 1 && (*mb_off2cells)(off, max_off) == 1
@ -5297,7 +5305,7 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
ScreenLines[off + mbyte_blen] = 0; ScreenLines[off + mbyte_blen] = 0;
ScreenLines[off] = c; ScreenLines[off] = c;
ScreenAttrs[off] = attr; ScreenAttrs[off] = attr;
if (enc_utf8) { if (l_enc_utf8) {
if (c < 0x80 && u8cc[0] == 0) if (c < 0x80 && u8cc[0] == 0)
ScreenLinesUC[off] = 0; ScreenLinesUC[off] = 0;
else { else {
@ -5319,13 +5327,13 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
ScreenLines[off + 1] = ptr[1]; ScreenLines[off + 1] = ptr[1];
ScreenAttrs[off + 1] = attr; ScreenAttrs[off + 1] = attr;
screen_char_2(off, row, col); screen_char_2(off, row, col);
} else if (enc_dbcs == DBCS_JPNU && c == 0x8e) { } else if (l_enc_dbcs == DBCS_JPNU && c == 0x8e) {
ScreenLines2[off] = ptr[1]; ScreenLines2[off] = ptr[1];
screen_char(off, row, col); screen_char(off, row, col);
} else } else
screen_char(off, row, col); screen_char(off, row, col);
} }
if (has_mbyte) { if (l_has_mbyte) {
off += mbyte_cells; off += mbyte_cells;
col += mbyte_cells; col += mbyte_cells;
ptr += mbyte_blen; ptr += mbyte_blen;
@ -5344,7 +5352,7 @@ void screen_puts_len(char_u *text, int textlen, int row, int col, int attr)
/* If we detected the next character needs to be redrawn, but the text /* If we detected the next character needs to be redrawn, but the text
* doesn't extend up to there, update the character here. */ * doesn't extend up to there, update the character here. */
if (force_redraw_next && col < screen_Columns) { if (force_redraw_next && col < screen_Columns) {
if (enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1) if (l_enc_dbcs != 0 && dbcs_off2cells(off, max_off) > 1)
screen_char_2(off, row, col); screen_char_2(off, row, col);
else else
screen_char(off, row, col); screen_char(off, row, col);