From ef2c892144dbf9166b5efdc50d3da3df6433655d Mon Sep 17 00:00:00 2001 From: Oldes Date: Tue, 16 Oct 2018 23:59:07 +0200 Subject: [PATCH] FIX: more fixes trying to lower number of Clang warnings --- src/core/b-init.c | 6 +++--- src/core/c-do.c | 2 +- src/core/c-task.c | 4 ++-- src/core/d-crash.c | 4 ++-- src/core/d-dump.c | 14 +++++++------- src/core/d-print.c | 31 +++++++++++++++++-------------- src/core/f-deci.c | 2 +- src/core/f-stubs.c | 4 ++-- src/core/l-scan.c | 2 +- src/core/m-gc.c | 2 +- src/core/n-strings.c | 8 ++++---- src/core/p-dns.c | 2 +- src/core/s-make.c | 6 +++--- src/core/s-mold.c | 8 ++++---- src/core/t-block.c | 2 +- src/core/t-date.c | 4 ++-- src/core/t-event.c | 2 +- src/core/t-image.c | 4 ++-- src/core/t-vector.c | 2 +- src/core/u-compress.c | 3 +-- src/include/reb-c.h | 6 +++--- 21 files changed, 60 insertions(+), 58 deletions(-) diff --git a/src/core/b-init.c b/src/core/b-init.c index 0d3bb9997a..6e2117e9c5 100644 --- a/src/core/b-init.c +++ b/src/core/b-init.c @@ -200,9 +200,9 @@ extern const REBYTE Str_Banner[]; } } - ASSERT(!CMP_BYTES("end!", Get_Sym_Name(SYM_END_TYPE)), RP_BAD_END_CANON_WORD); - ASSERT(!CMP_BYTES("true", Get_Sym_Name(SYM_TRUE)), RP_BAD_TRUE_CANON_WORD); - ASSERT(!CMP_BYTES("line", BOOT_STR(RS_SCAN,1)), RP_BAD_BOOT_STRING); + ASSERT(!CMP_BYTES(cb_cast("end!"), Get_Sym_Name(SYM_END_TYPE)), RP_BAD_END_CANON_WORD); + ASSERT(!CMP_BYTES(cb_cast("true"), Get_Sym_Name(SYM_TRUE)), RP_BAD_TRUE_CANON_WORD); + ASSERT(!CMP_BYTES(cb_cast("line"), BOOT_STR(RS_SCAN,1)), RP_BAD_BOOT_STRING); } diff --git a/src/core/c-do.c b/src/core/c-do.c index e00f6bf2e6..42b3ae2212 100644 --- a/src/core/c-do.c +++ b/src/core/c-do.c @@ -257,7 +257,7 @@ void Trace_Return(REBVAL *word, REBVAL *value) { int depth; CHECK_DEPTH(depth); - Debug_Fmt_(cb_cast(BOOT_STR(RS_TRACE,6)), Get_Word_Name(word)); + Debug_Fmt_(BOOT_STR(RS_TRACE,6), Get_Word_Name(word)); Debug_Values(value, 1, 50); } diff --git a/src/core/c-task.c b/src/core/c-task.c index 70a47f6414..2f7f2d0440 100644 --- a/src/core/c-task.c +++ b/src/core/c-task.c @@ -67,14 +67,14 @@ { REBSER *body; - Debug_Str((REBYTE*)"Begin Task"); + Debug_Str("Begin Task"); Init_Task(); body = Clone_Block(VAL_MOD_BODY(task)); OS_TASK_READY(0); Do_Blk(body, 0); - Debug_Str((REBYTE*)"End Task"); + Debug_Str("End Task"); } diff --git a/src/core/d-crash.c b/src/core/d-crash.c index 5d82c4a31b..1b0cbc90ae 100644 --- a/src/core/d-crash.c +++ b/src/core/d-crash.c @@ -78,9 +78,9 @@ enum Crash_Msg_Nums { // "REBOL PANIC #nnn:" COPY_BYTES(buf, Crash_Msgs[CM_ERROR], CRASH_BUF_SIZE); - APPEND_BYTES(buf, " #", CRASH_BUF_SIZE); + APPEND_BYTES(buf, cb_cast(" #"), CRASH_BUF_SIZE); Form_Int(buf + LEN_BYTES(buf), id); - APPEND_BYTES(buf, ": ", CRASH_BUF_SIZE); + APPEND_BYTES(buf, cb_cast(": "), CRASH_BUF_SIZE); // "REBOL PANIC #nnn: put error message here" // The first few error types only print general error message. diff --git a/src/core/d-dump.c b/src/core/d-dump.c index d96fa83e36..3f576fcae8 100644 --- a/src/core/d-dump.c +++ b/src/core/d-dump.c @@ -33,7 +33,7 @@ /*********************************************************************** ** -*/ void Dump_Series(REBSER *series, REBYTE *memo) +*/ void Dump_Series(REBSER *series, const char *memo) /* ***********************************************************************/ { @@ -100,7 +100,7 @@ for (tp = str; *tp;) *cp++ = *tp++; *cp = 0; - Debug_Str(buf); + Debug_Str(cs_cast(buf)); if (cnt >= limit) break; cp = buf; } @@ -119,7 +119,7 @@ REBYTE *cp; REBCNT l, n; REBCNT *bp = (REBCNT*)vp; - REBYTE *type; + const REBYTE *type; cp = buf; for (l = 0; l < count; l++) { @@ -141,12 +141,12 @@ } n = 0; if (IS_WORD((REBVAL*)val) || IS_GET_WORD((REBVAL*)val) || IS_SET_WORD((REBVAL*)val)) { - char * name = Get_Word_Name((REBVAL*)val); - n = snprintf(cp, sizeof(buf) - (cp - buf), " (%s)", name); + const char * name = cs_cast(Get_Word_Name((REBVAL*)val)); + n = snprintf(s_cast(cp), sizeof(buf) - (cp - buf), " (%s)", name); } *(cp + n) = 0; - Debug_Str(buf); + Debug_Str(s_cast(buf)); cp = buf; } } @@ -349,7 +349,7 @@ xx*/ void Dump_Bind_Table() }; DISABLE_GC; - for (n = 0; n < 14; n++) Debug_Fmt(cb_cast(BOOT_STR(RS_DUMP, n)), nums[n]); + for (n = 0; n < 14; n++) Debug_Fmt(BOOT_STR(RS_DUMP, n), nums[n]); ENABLE_GC; } diff --git a/src/core/d-print.c b/src/core/d-print.c index e1945c4dd1..859a168d82 100644 --- a/src/core/d-print.c +++ b/src/core/d-print.c @@ -71,7 +71,10 @@ static REBREQ *Req_SIO; ** ***********************************************************************/ { - Req_SIO->data = b_cast("\n"); + // !!! Don't put const literal directly into mutable Req_SIO->data + static REBYTE newline[] = "\n"; + + Req_SIO->data = newline; Req_SIO->length = 1; Req_SIO->actual = 0; @@ -83,7 +86,7 @@ static REBREQ *Req_SIO; /*********************************************************************** ** -*/ static void Prin_OS_String(REBYTE *bp, REBINT len, REBOOL uni) +*/ static void Prin_OS_String(const REBYTE *bp, REBINT len, REBOOL uni) /* ** Print a string, but no line terminator or space. ** @@ -141,7 +144,7 @@ static REBREQ *Req_SIO; /*********************************************************************** ** -*/ void Out_Str(REBYTE *bp, REBINT lines) +*/ void Out_Str(const REBYTE *bp, REBINT lines) /* ***********************************************************************/ { @@ -206,18 +209,18 @@ static REBREQ *Req_SIO; //RESET_SERIES(Trace_Buffer); } else { - Out_Str("backtrace not enabled", 1); + Out_Str(cb_cast("backtrace not enabled"), 1); } } /*********************************************************************** ** -*/ void Debug_String(REBYTE *bp, REBINT len, REBOOL uni, REBINT lines) +*/ void Debug_String(const REBYTE *bp, REBINT len, REBOOL uni, REBINT lines) /* ***********************************************************************/ { - REBUNI *up = (REBUNI*)bp; + const REBUNI *up = cast(const REBUNI*, bp); REBUNI uc; if (Trace_Limit > 0) { @@ -245,19 +248,19 @@ static REBREQ *Req_SIO; /* ***********************************************************************/ { - Debug_String("", UNKNOWN, 0, 1); + Debug_String(cb_cast(""), UNKNOWN, 0, 1); } /*********************************************************************** ** -*/ void Debug_Str(REBYTE *str) +*/ void Debug_Str(const char *str) /* ** Print a string followed by a newline. ** ***********************************************************************/ { - Debug_String(str, UNKNOWN, 0, 1); + Debug_String(cb_cast(str), UNKNOWN, 0, 1); } @@ -292,7 +295,7 @@ static REBREQ *Req_SIO; /* ***********************************************************************/ { - if (BYTE_SIZE(ser)) Debug_Str(BIN_HEAD(ser)); + if (BYTE_SIZE(ser)) Debug_Str(s_cast(BIN_HEAD(ser))); else Debug_Uni(ser); } @@ -308,9 +311,9 @@ static REBREQ *Req_SIO; REBYTE buf[40]; Debug_String(str, UNKNOWN, 0, 0); - Debug_String(" ", 1, 0, 0); + Debug_String(cb_cast(" "), 1, 0, 0); Form_Hex_Pad(buf, num, 8); - Debug_Str(buf); + Debug_Str(s_cast(buf)); } @@ -350,7 +353,7 @@ static REBREQ *Req_SIO; ** ***********************************************************************/ { - Debug_Str(Get_Word_Name(word)); + Debug_Str(cs_cast(Get_Word_Name(word))); } @@ -362,7 +365,7 @@ static REBREQ *Req_SIO; ** ***********************************************************************/ { - if (VAL_TYPE(value) < REB_MAX) Debug_Str(Get_Type_Name(value)); + if (VAL_TYPE(value) < REB_MAX) Debug_Str(cs_cast(Get_Type_Name(value))); else Debug_Str("TYPE?!"); } diff --git a/src/core/f-deci.c b/src/core/f-deci.c index cd4146e256..dcc4168ffc 100644 --- a/src/core/f-deci.c +++ b/src/core/f-deci.c @@ -546,7 +546,7 @@ deci decimal_to_deci (REBDEC a) { e -= (rve - c); - d = CHR_TO_INT(c); + d = CHR_TO_INT(cs_cast(c)); result.s = s; result.m2 = 0; diff --git a/src/core/f-stubs.c b/src/core/f-stubs.c index 067db976d6..5cbf1aad8a 100644 --- a/src/core/f-stubs.c +++ b/src/core/f-stubs.c @@ -667,7 +667,7 @@ /*********************************************************************** ** -*/ REBINT Partial1(REBVAL *sval, REBVAL *lval) +*/ REBCNT Partial1(REBVAL *sval, REBVAL *lval) /* ** Process the /part (or /skip) and other length modifying ** arguments. @@ -705,7 +705,7 @@ } } - return (REBINT)len; + return (REBCNT)len; } diff --git a/src/core/l-scan.c b/src/core/l-scan.c index 9e9c36dd99..686a7e8dbb 100644 --- a/src/core/l-scan.c +++ b/src/core/l-scan.c @@ -376,7 +376,7 @@ // Check for identifiers: for (n = 0; n < ESC_MAX; n++) { - if (NZ(cp = Match_Bytes(*bp, cb_cast(Esc_Names[n])))) { + if (NZ(cp = Match_Bytes(*bp, Esc_Names[n]))) { if (cp && *cp == ')') { *bp = cp + 1; return Esc_Codes[n]; diff --git a/src/core/m-gc.c b/src/core/m-gc.c index ac9fd57b45..676069e62f 100644 --- a/src/core/m-gc.c +++ b/src/core/m-gc.c @@ -546,7 +546,7 @@ static void Mark_Series(REBSER *series, REBCNT depth); return 0; } - if (Reb_Opts->watch_recycle) Debug_Str(BOOT_STR(RS_WATCH, 0)); + if (Reb_Opts->watch_recycle) Debug_Str(cs_cast(BOOT_STR(RS_WATCH, 0))); GC_Disabled = 1; diff --git a/src/core/n-strings.c b/src/core/n-strings.c index 540bd54849..5c608f4d39 100644 --- a/src/core/n-strings.c +++ b/src/core/n-strings.c @@ -296,13 +296,13 @@ static struct digest { { REBSER *ser; REBCNT index; - REBINT len; + REBCNT len; len = Partial1(D_ARG(1), D_ARG(3)); ser = Prep_Bin_Str(D_ARG(1), &index, &len); // result may be a SHARED BUFFER! - Set_Binary(D_RET, Compress(ser, index, len, D_REF(4))); // /gzip + Set_Binary(D_RET, Compress(ser, index, (REBINT)len, D_REF(4))); // /gzip return R_RET; } @@ -318,13 +318,13 @@ static struct digest { { REBVAL *arg = D_ARG(1); REBINT limit = 0; - REBINT len; + REBCNT len; len = Partial1(D_ARG(1), D_ARG(3)); if (D_REF(5)) limit = Int32s(D_ARG(6), 1); // /limit size - Set_Binary(D_RET, Decompress(VAL_SERIES(arg), VAL_INDEX(arg), len, limit, D_REF(4))); // /gzip + Set_Binary(D_RET, Decompress(VAL_SERIES(arg), VAL_INDEX(arg), (REBINT)len, limit, D_REF(4))); // /gzip return R_RET; } diff --git a/src/core/p-dns.c b/src/core/p-dns.c index 1367074719..e2fe636918 100644 --- a/src/core/p-dns.c +++ b/src/core/p-dns.c @@ -66,7 +66,7 @@ arg = Obj_Value(spec, STD_PORT_SPEC_NET_HOST); - if (IS_TUPLE(arg) && Scan_Tuple(VAL_BIN(arg), strlen(VAL_BIN(arg)), &tmp)) { + if (IS_TUPLE(arg) && Scan_Tuple(VAL_BIN(arg), LEN_BYTES(VAL_BIN(arg)), &tmp)) { SET_FLAG(sock->modes, RST_REVERSE); memcpy(&sock->net.remote_ip, VAL_TUPLE(&tmp), 4); } diff --git a/src/core/s-make.c b/src/core/s-make.c index 0764c634d7..d2c7846793 100644 --- a/src/core/s-make.c +++ b/src/core/s-make.c @@ -417,7 +417,7 @@ x*/ REBCNT Insert_Value(REBSER *series, REBCNT index, REBVAL *item, REBCNT type, /*********************************************************************** ** -*/ REBSER *Append_Bytes(REBSER *dst, const REBYTE *src) +*/ REBSER *Append_Bytes(REBSER *dst, const char *src) /* ** Optimized function to append a non-encoded byte string. ** If dst is null, it will be created and returned. @@ -543,7 +543,7 @@ x*/ REBCNT Insert_Value(REBSER *series, REBCNT index, REBVAL *item, REBCNT type, REBYTE buf[32]; Form_Int(buf, num); - Append_Bytes(dst, buf); + Append_Bytes(dst, cs_cast(buf)); } @@ -561,7 +561,7 @@ x*/ REBCNT Insert_Value(REBSER *series, REBCNT index, REBVAL *item, REBCNT type, else Form_Int_Pad(buf, num, -digs, digs, '0'); - Append_Bytes(dst, buf); + Append_Bytes(dst, cs_cast(buf)); } diff --git a/src/core/s-mold.c b/src/core/s-mold.c index b375d9f3f4..fbdeb735e2 100644 --- a/src/core/s-mold.c +++ b/src/core/s-mold.c @@ -96,7 +96,7 @@ enum { Mold_Value(mold, va_arg(args, REBVAL*), TRUE); break; case 'S': // String of bytes - Append_Bytes(series, va_arg(args, REBYTE*)); + Append_Bytes(series, va_arg(args, const char*)); break; case 'C': // Char Append_Byte(series, va_arg(args, REBCNT)); @@ -536,7 +536,7 @@ STOID Mold_Handle(REBVAL *value, REB_MOLD *mold) const REBYTE *name = VAL_HANDLE_NAME(value); if (name != NULL) { Append_Bytes(mold->series, "#[handle! "); - Append_Bytes(mold->series, (REBYTE *)name); + Append_Bytes(mold->series, cs_cast(name)); Append_Byte(mold->series, ']'); } else { @@ -608,7 +608,7 @@ STOID Mold_Block_Series(REB_MOLD *mold, REBSER *series, REBCNT index, REBYTE *se if (!sep) sep = "[]"; if (IS_END(value)) { - Append_Bytes(out, sep); + Append_Bytes(out, cs_cast(sep)); return; } @@ -709,7 +709,7 @@ STOID Mold_Block(REBVAL *value, REB_MOLD *mold) break; } - if (over) Append_Bytes(mold->series, sep ? sep : (REBYTE*)("[]")); + if (over) Append_Bytes(mold->series, sep ? cs_cast(sep) : "[]"); else Mold_Block_Series(mold, VAL_SERIES(value), VAL_INDEX(value), sep); if (VAL_TYPE(value) == REB_SET_PATH) diff --git a/src/core/t-block.c b/src/core/t-block.c index d68dfc6da3..28fbf33cef 100644 --- a/src/core/t-block.c +++ b/src/core/t-block.c @@ -207,7 +207,7 @@ static void No_Nones(REBVAL *arg) { REBFLG is_blk = FALSE; // arg is a block not a value // Length of target (may modify index): (arg can be anything) - rlen = Partial1((action == A_CHANGE) ? block : arg, DS_ARG(AN_LENGTH)); + rlen = (REBINT)Partial1((action == A_CHANGE) ? block : arg, DS_ARG(AN_LENGTH)); index = VAL_INDEX(block); if (action == A_APPEND || index > tail) index = tail; diff --git a/src/core/t-date.c b/src/core/t-date.c index 1f5e378868..c2423d5e42 100644 --- a/src/core/t-date.c +++ b/src/core/t-date.c @@ -120,7 +120,7 @@ bp = Form_Int_Pad(bp, (REBINT)VAL_YEAR(value), 6, -4, '0'); *bp = 0; - Append_Bytes(mold->series, buf); + Append_Bytes(mold->series, cs_cast(buf)); if (VAL_TIME(value) != NO_TIME) { @@ -143,7 +143,7 @@ bp = Form_Int_Pad(bp, (tz&3) * 15, 2, 2, '0'); *bp = 0; - Append_Bytes(mold->series, buf); + Append_Bytes(mold->series, cs_cast(buf)); } } } diff --git a/src/core/t-event.c b/src/core/t-event.c index ccd3ebbcf2..570f13785d 100644 --- a/src/core/t-event.c +++ b/src/core/t-event.c @@ -520,7 +520,7 @@ enum rebol_event_fields { if (!IS_NONE(&val)) { New_Indented_Line(mold); Append_UTF8(mold->series, Get_Sym_Name(fields[field]), -1); - Append_Bytes(mold->series, cb_cast(": ")); + Append_Bytes(mold->series, ": "); if (IS_WORD(&val)) Append_Byte(mold->series, '\''); Mold_Value(mold, &val, TRUE); } diff --git a/src/core/t-image.c b/src/core/t-image.c index 5fc3fd45d3..ecced6ebcd 100644 --- a/src/core/t-image.c +++ b/src/core/t-image.c @@ -362,7 +362,7 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i) // Output Alpha channel, if it has one: if (Image_Has_Alpha(value, FALSE)) { - Append_Bytes(mold->series, cb_cast("\n} #{")); + Append_Bytes(mold->series, "\n} #{"); up = Prep_Uni_Series(mold, (size * 2) + (size / 10) + 1); @@ -374,7 +374,7 @@ INLINE REBCNT ARGB_To_BGR(REBCNT i) } *up = 0; // tail already set from Prep. - Append_Bytes(mold->series, cb_cast("\n}")); + Append_Bytes(mold->series, "\n}"); } diff --git a/src/core/t-vector.c b/src/core/t-vector.c index 7bd859a3a1..35faf88ce4 100644 --- a/src/core/t-vector.c +++ b/src/core/t-vector.c @@ -634,7 +634,7 @@ void Set_Vector_Row(REBSER *ser, REBVAL *blk) REBCNT type = (bits >= VTSF08) ? REB_DECIMAL : REB_INTEGER; Pre_Mold(value, mold); if (!GET_MOPT(mold, MOPT_MOLD_ALL)) Append_Byte(mold->series, '['); - if (bits >= VTUI08 && bits <= VTUI64) Append_Bytes(mold->series, cb_cast("unsigned ")); + if (bits >= VTUI08 && bits <= VTUI64) Append_Bytes(mold->series, "unsigned "); Emit(mold, "N I I [", type+1, bit_sizes[bits & 3], len); if (len) New_Indented_Line(mold); } diff --git a/src/core/u-compress.c b/src/core/u-compress.c index 45b3aef5f8..1a745ca1e0 100644 --- a/src/core/u-compress.c +++ b/src/core/u-compress.c @@ -56,7 +56,7 @@ /*********************************************************************** ** -*/ REBSER *Compress(REBSER *input, REBINT index, REBINT len, REBFLG use_crc) +*/ REBSER *Compress(REBSER *input, REBINT index, REBCNT len, REBFLG use_crc) /* ** Compress a binary (only). ** data @@ -76,7 +76,6 @@ REBINT err; REBYTE out_size[sizeof(REBCNT)]; - if (len < 0) Trap0(RE_PAST_END); // !!! better msg needed size = len + (len > STERLINGS_MAGIC_NUMBER ? len / 10 + 12 : STERLINGS_MAGIC_FIX); output = Make_Binary(size); diff --git a/src/include/reb-c.h b/src/include/reb-c.h index 7bfda74163..d0e2ab368c 100644 --- a/src/include/reb-c.h +++ b/src/include/reb-c.h @@ -207,15 +207,15 @@ enum { #define MAX_HEX_LEN 16 #ifdef ITOA64 // Integer to ascii conversion -#define INT_TO_STR(n,s) _i64toa(n, s, 10) +#define INT_TO_STR(n,s) _i64toa(n, s_cast(s), 10) #else #define INT_TO_STR(n,s) Form_Int_Len(s, n, MAX_INT_LEN) #endif #ifdef ATOI64 // Ascii to integer conversion -#define CHR_TO_INT(s) _atoi64(s) +#define CHR_TO_INT(s) _atoi64(cs_cast(s)) #else -#define CHR_TO_INT(s) strtoll(s, 0, 10) +#define CHR_TO_INT(s) strtoll(cs_cast(s), 0, 10) #endif #define LDIV lldiv