summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2016-12-07 06:18:30 -0800
committerKaz Kylheku <kaz@kylheku.com>2016-12-07 06:18:30 -0800
commit7ed9432eed94beef4f35f16df2c0bd53dd2ce4bc (patch)
tree4ac21fd4f2aa8f8ef67f424ab5a93d83c70e8bfd
parent0a97556f505334bcf48987129b3d35c48efdbb62 (diff)
downloadtxr-7ed9432eed94beef4f35f16df2c0bd53dd2ce4bc.tar.gz
txr-7ed9432eed94beef4f35f16df2c0bd53dd2ce4bc.tar.bz2
txr-7ed9432eed94beef4f35f16df2c0bd53dd2ce4bc.zip
Fix some C style casts to use casting macros.
This is uncovered by compiling with g++ using -Wold-style-cast. * mpi/mpi.c (mp_get_intptr): Use convert macro. Also in one of the rules producing REGCHAR. * parser.l (num_esc): Likewise. * struct.c (static_slot_set, static_slot_ens_rec, get_equal_method): Use coerce macro for int to pointer conversion. * sysif.c (setgroups_wrap): Use convert macro. * termios.c (termios_unpack, termios_pack): Likewise. * txr.c (sysroot_init): Likewise.
-rw-r--r--mpi/mpi.c2
-rw-r--r--parser.l4
-rw-r--r--struct.c8
-rw-r--r--sysif.c2
-rw-r--r--termios.c4
-rw-r--r--txr.c2
6 files changed, 11 insertions, 11 deletions
diff --git a/mpi/mpi.c b/mpi/mpi.c
index 2a2fea0d..6932d431 100644
--- a/mpi/mpi.c
+++ b/mpi/mpi.c
@@ -609,7 +609,7 @@ mp_err mp_get_intptr(mp_int *mp, int_ptr_t *z)
uint_ptr_t tmp = 0;
mp_get_uintptr(mp, &tmp);
/* Reliance on bitwise unsigned to two's complement conversion */
- *z = (int_ptr_t) tmp;
+ *z = convert(int_ptr_t, tmp);
return MP_OKAY;
}
diff --git a/parser.l b/parser.l
index a123f2f1..7760553c 100644
--- a/parser.l
+++ b/parser.l
@@ -177,7 +177,7 @@ static wchar_t num_esc(scanner_t *scn, char *num)
val = strtol(num, 0, 8);
}
- if (val < 0 || val > 0x10FFFF || (wchar_t) val != val) {
+ if (val < 0 || val > 0x10FFFF || convert(wchar_t, val) != val) {
yyerror(scn, yyget_extra(scn), "numeric character escape out of range");
val = 0;
}
@@ -895,7 +895,7 @@ UONLY {U2}{U}|{U3}{U}{U}|{U4}{U}{U}{U}
<SREGEX>. {
/* Allow non-UTF-8 byte for regexes scanned from string */
- yylval->chr = (unsigned char) yytext[0] + 0xDC00;
+ yylval->chr = convert(unsigned char, yytext[0]) + 0xDC00;
return REGCHAR;
}
diff --git a/struct.c b/struct.c
index 364050ba..bfa6acbd 100644
--- a/struct.c
+++ b/struct.c
@@ -924,7 +924,7 @@ val static_slot_set(val stype, val sym, val newval)
if (symbolp(sym)) {
loc ptr = lookup_static_slot(stype, st, sym);
if (!nullocp(ptr)) {
- if (st->eqmslot == (struct stslot *) -1)
+ if (st->eqmslot == coerce(struct stslot *, -1))
st->eqmslot = 0;
return set(ptr, newval);
}
@@ -1014,7 +1014,7 @@ static val static_slot_ens_rec(val stype, val sym, val newval,
no_error_p = default_bool_arg(no_error_p);
- if (st->eqmslot == (struct stslot *) -1)
+ if (st->eqmslot == coerce(struct stslot *, -1))
st->eqmslot = 0;
if (stsl != 0 && opt_compat && opt_compat <= 151) {
@@ -1384,7 +1384,7 @@ static cnum struct_inst_hash(val obj, int *count)
static val get_equal_method(val stype, struct struct_type *st)
{
- if (st->eqmslot == (struct stslot *) -1) {
+ if (st->eqmslot == coerce(struct stslot *, -1)) {
return nil;
} else if (st->eqmslot) {
struct stslot *stsl = st->eqmslot;
@@ -1395,7 +1395,7 @@ static val get_equal_method(val stype, struct struct_type *st)
st->eqmslot = stsl;
return stslot_place(stsl);
}
- st->eqmslot = (struct stslot *) -1;
+ st->eqmslot = coerce(struct stslot *, -1);
return nil;
}
}
diff --git a/sysif.c b/sysif.c
index 2c68b6d9..2cb9d378 100644
--- a/sysif.c
+++ b/sysif.c
@@ -1048,7 +1048,7 @@ static val setgroups_wrap(val list)
cnum len = c_num(length(list));
size_t size = len;
- if ((cnum) size != len) {
+ if (convert(cnum, size) != len) {
uw_throwf(system_error_s, lit("setgroups: list too long"), nao);
} else {
gid_t *arr = coerce(gid_t *, chk_malloc(size *sizeof *arr));
diff --git a/termios.c b/termios.c
index edb0e87a..8a7eb3e7 100644
--- a/termios.c
+++ b/termios.c
@@ -190,7 +190,7 @@ static val termios_unpack(struct termios *in)
{
args_decl(args, ARGS_MIN);
val out = make_struct(termios_s, nil, args);
- int i, cc_sz = (int) (sizeof in->c_cc / sizeof in->c_cc[0]);
+ int i, cc_sz = convert(int, sizeof in->c_cc / sizeof in->c_cc[0]);
val cc = vector(num_fast(cc_sz), nil);
slotset(out, iflag_s, num(in->c_iflag));
@@ -209,7 +209,7 @@ static val termios_unpack(struct termios *in)
static void termios_pack(struct termios *out, val in)
{
- int i, cc_sz = (int) (sizeof out->c_cc / sizeof out->c_cc[0]);
+ int i, cc_sz = convert(int, sizeof out->c_cc / sizeof out->c_cc[0]);
val cc = slot(in, cc_s);
out->c_iflag = c_num(slot(in, iflag_s));
diff --git a/txr.c b/txr.c
index ed089ce1..c69def68 100644
--- a/txr.c
+++ b/txr.c
@@ -304,7 +304,7 @@ static void sysroot_init(void)
#if HAVE_WINDOWS_H
val slash = regex_compile(lit("\\\\"), nil);
#endif
- protect(&prog_path, &sysroot_path, &stdlib_path, (val *) 0);
+ protect(&prog_path, &sysroot_path, &stdlib_path, convert(val *, 0));
prog_path = get_self_path();
#if HAVE_WINDOWS_H
prog_path = regsub(slash, lit("/"), prog_path);