From: Ivan Maidanski Date: Thu, 20 Apr 2017 08:50:03 +0000 (+0300) Subject: Eliminate 'possible loss of data' compiler warnings in cord (MS VC) X-Git-Tag: v8.0.0~778 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=c01a22abd76bb0f346d1ba735f3346ca3a813338;p=platform%2Fupstream%2Flibgc.git Eliminate 'possible loss of data' compiler warnings in cord (MS VC) * cord/cordbscs.c (CORD_cat_char_star, CORD_cat, CORD_from_fn_inner): Add explicit cast in assignment of result->depth, result->len. * cord/cordbscs.c (CORD_substr_checked): Change type of "j", "lim" local variables from int to size_t. * cord/cordbscs.c (CORD_init_min_len): Add explicit cast (to int) in assignment of CORD_max_len. * cord/cordxtra.c (CORD_ncmp): Add explicit cast (to long) when "avail" local variable is updated. * cord/cordxtra.c (CORD_chr, CORD_rchr, CORD_from_file_eager): Add explicit cast to char (from int) for "c" local variable in assignment of d.target and in CORD_ec_append call. * cord/cordxtra.c (refill_cache): Add explicit cast to long (from size_t) for line_start in fseek call. * cord/tests/de.c (line_pos, fix_pos, do_command): Add explicit cast to int in assignment of *c, line, col. * cord/tests/de.c (do_command): Reset line, col and file_pos variables (of different types) in separate statements. * cord/tests/de_win.c (WinMain): Add explicit cast of msg.wParam to int in return statement. --- diff --git a/cord/cordbscs.c b/cord/cordbscs.c index 38b1c95..032c4fb 100644 --- a/cord/cordbscs.c +++ b/cord/cordbscs.c @@ -221,10 +221,10 @@ CORD CORD_cat_char_star(CORD x, const char * y, size_t leny) result = GC_NEW(struct Concatenation); if (result == 0) OUT_OF_MEMORY; result->header = CONCAT_HDR; - result->depth = depth; + result->depth = (char)depth; if (lenx <= MAX_LEFT_LEN) result->left_len = (unsigned char)lenx; - result->len = result_len; + result->len = (word)result_len; result->left = x; result->right = y; if (depth >= MAX_DEPTH) { @@ -263,10 +263,10 @@ CORD CORD_cat(CORD x, CORD y) result = GC_NEW(struct Concatenation); if (result == 0) OUT_OF_MEMORY; result->header = CONCAT_HDR; - result->depth = depth; + result->depth = (char)depth; if (lenx <= MAX_LEFT_LEN) result->left_len = (unsigned char)lenx; - result->len = result_len; + result->len = (word)result_len; result->left = x; result->right = y; if (depth >= MAX_DEPTH) { @@ -307,7 +307,7 @@ static CordRep *CORD_from_fn_inner(CORD_fn fn, void * client_data, size_t len) if (result == 0) OUT_OF_MEMORY; result->header = FN_HDR; /* depth is already 0 */ - result->len = len; + result->len = (word)len; result->fn = fn; result->client_data = client_data; return (CordRep *)result; @@ -437,8 +437,8 @@ CORD CORD_substr_checked(CORD x, size_t i, size_t n) register struct Function * f = &(((CordRep *)x) -> function); char buf[SUBSTR_LIMIT+1]; register char * p = buf; - register int j; - register int lim = i + n; + register size_t j; + register size_t lim = i + n; for (j = i; j < lim; j++) { char c = (*(f -> fn))(j, f -> client_data); @@ -618,7 +618,7 @@ void CORD_init_min_len(void) previous = last; last = current; } - CORD_max_len = last - 1; + CORD_max_len = (int)last - 1; min_len_init = 1; } diff --git a/cord/cordxtra.c b/cord/cordxtra.c index 61df89b..751b2ed 100644 --- a/cord/cordxtra.c +++ b/cord/cordxtra.c @@ -229,7 +229,8 @@ int CORD_ncmp(CORD x, size_t x_start, CORD y, size_t y_start, size_t len) if (avail > yavail) avail = yavail; count += avail; - if (count > len) avail -= (count - len); + if (count > len) + avail -= (long)(count - len); result = strncmp(CORD_pos_cur_char_addr(xpos), CORD_pos_cur_char_addr(ypos), (size_t)avail); if (result != 0) return(result); @@ -347,7 +348,7 @@ size_t CORD_chr(CORD x, size_t i, int c) chr_data d; d.pos = i; - d.target = c; + d.target = (char)c; if (CORD_iter5(x, i, CORD_chr_proc, CORD_batched_chr_proc, &d)) { return(d.pos); } else { @@ -360,7 +361,7 @@ size_t CORD_rchr(CORD x, size_t i, int c) chr_data d; d.pos = i; - d.target = c; + d.target = (char)c; if (CORD_riter4(x, i, CORD_rchr_proc, &d)) { return(d.pos); } else { @@ -476,7 +477,7 @@ CORD CORD_from_file_eager(FILE * f) ecord[0].ec_cord = CORD_cat(ecord[0].ec_cord, CORD_nul(count)); } if (c == EOF) break; - CORD_ec_append(ecord, c); + CORD_ec_append(ecord, (char)c); } (void) fclose(f); return(CORD_balance(CORD_ec_to_cord(ecord))); @@ -535,7 +536,7 @@ static char refill_cache(refill_data * client_data) cache_line * new_cache = client_data -> new_cache; if (line_start != state -> lf_current - && fseek(f, line_start, SEEK_SET) != 0) { + && fseek(f, (long)line_start, SEEK_SET) != 0) { ABORT("fseek failed"); } if (fread(new_cache -> data, sizeof(char), LINE_SZ, f) diff --git a/cord/tests/de.c b/cord/tests/de.c index bb902de..2b467f2 100644 --- a/cord/tests/de.c +++ b/cord/tests/de.c @@ -179,7 +179,7 @@ size_t line_pos(int i, int *c) if (next == CORD_NOT_FOUND) next = current_len - 1; if (next < cur + *c) { - *c = next - cur; + *c = (int)(next - cur); } cur += *c; } @@ -347,7 +347,8 @@ void fix_pos(void) { int my_col = col; - if ((size_t)line > current_len) line = current_len; + if ((size_t)line > current_len) + line = (int)current_len; file_pos = line_pos(line, &my_col); if (file_pos == CORD_NOT_FOUND) { for (line = current_map -> line, file_pos = current_map -> pos; @@ -428,7 +429,7 @@ void do_command(int c) if (file_pos > new_pos) break; line++; } - col = new_pos - line_pos(line, 0); + col = (int)(new_pos - line_pos(line, 0)); file_pos = new_pos; fix_cursor(); } else { @@ -459,7 +460,8 @@ void do_command(int c) locate_mode = 1; break; case TOP: - line = col = file_pos = 0; + line = col = 0; + file_pos = 0; break; case UP: if (line != 0) { diff --git a/cord/tests/de_win.c b/cord/tests/de_win.c index 733cc1d..64ab804 100644 --- a/cord/tests/de_win.c +++ b/cord/tests/de_win.c @@ -114,7 +114,7 @@ int APIENTRY WinMain (HINSTANCE hInstance, HINSTANCE hPrevInstance, DispatchMessage (&msg); } } - return msg.wParam; + return (int)msg.wParam; } /* Return the argument with all control characters replaced by blanks. */