Use `struct` initializer instead of `memset`.
MODIFY
mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
mrbgems/mruby-bin-debugger/tools/mrdb/apibreak.c
@@ -344,10 +344,10 @@ mrb_debug_delete_break(mrb_state *mrb, mrb_debug_context *dbg, uint32_t bpno)
for(i = index ; i < dbg->bpnum; i++) {
if ((i + 1) == dbg->bpnum) {
- memset(&dbg->bp[i], 0, sizeof(mrb_debug_breakpoint));
+ dbg->bp[i] = (mrb_debug_breakpoint){0};
}
else {
- memcpy(&dbg->bp[i], &dbg->bp[i + 1], sizeof(mrb_debug_breakpoint));
+ dbg->bp[i] = dbg->bp[i + 1];
}
}

MODIFY
mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c
mrbgems/mruby-bin-debugger/tools/mrdb/cmdmisc.c
@@ -141,7 +141,7 @@ static listcmd_parser_state*
listcmd_parser_state_new(mrb_state *mrb)
{
listcmd_parser_state *st = (listcmd_parser_state*)mrb_malloc(mrb, sizeof(listcmd_parser_state));
- memset(st, 0, sizeof(listcmd_parser_state));
+ *st = (listcmd_parser_state){0};
return st;
}

MODIFY
mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c
mrbgems/mruby-bin-debugger/tools/mrdb/mrdb.c
@@ -187,7 +187,7 @@ mrb_debug_context_new(mrb_state *mrb)
{
mrb_debug_context *dbg = (mrb_debug_context*)mrb_malloc(mrb, sizeof(mrb_debug_context));
- memset(dbg, 0, sizeof(mrb_debug_context));
+ *dbg = (mrb_debug_context){0};
dbg->xm = DBG_INIT;
dbg->xphase = DBG_PHASE_BEFORE_RUN;
@@ -226,7 +226,7 @@ mrdb_state_new(mrb_state *mrb)
{
mrdb_state *mrdb = (mrdb_state*)mrb_malloc(mrb, sizeof(mrdb_state));
- memset(mrdb, 0, sizeof(mrdb_state));
+ *mrdb = (mrdb_state){0};
mrdb->dbg = mrb_debug_context_get(mrb);
mrdb->command = (char*)mrb_malloc(mrb, MAX_COMMAND_LINE+1);

MODIFY
mrbgems/mruby-fiber/src/fiber.c
mrbgems/mruby-fiber/src/fiber.c
@@ -95,7 +95,6 @@ fiber_init(mrb_state *mrb, mrb_value self)
c->stbase = (mrb_value *)mrb_malloc(mrb, slen*sizeof(mrb_value));
c->stend = c->stbase + slen;
-#ifdef MRB_NAN_BOXING
{
mrb_value *p = c->stbase;
mrb_value *pend = c->stend;
@@ -105,9 +104,6 @@ fiber_init(mrb_state *mrb, mrb_value self)
p++;
}
}
-#else
- memset(c->stbase, 0, slen * sizeof(mrb_value));
-#endif
/* copy receiver from a block */
c->stbase[0] = mrb->c->ci->stack[0];

MODIFY
mrbgems/mruby-io/src/file.c
mrbgems/mruby-io/src/file.c
@@ -88,7 +88,7 @@ flock(int fd, int operation) {
DWORD flags;
flags = ((operation & LOCK_NB) ? LOCKFILE_FAIL_IMMEDIATELY : 0)
| ((operation & LOCK_SH) ? LOCKFILE_EXCLUSIVE_LOCK : 0);
- memset(&ov, 0, sizeof(ov));
+ ov = (OVERLAPPED){0};
return LockFileEx(h, flags, 0, 0xffffffff, 0xffffffff, &ov) ? 0 : -1;
}
#endif

MODIFY
mrbgems/mruby-socket/src/socket.c
mrbgems/mruby-socket/src/socket.c
@@ -67,7 +67,7 @@ static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
if (af == AF_INET)
{
struct sockaddr_in in;
- memset(&in, 0, sizeof(in));
+ in = (struct sockaddr_in){0};
in.sin_family = AF_INET;
memcpy(&in.sin_addr, src, sizeof(struct in_addr));
getnameinfo((struct sockaddr *)&in, sizeof(struct
@@ -77,7 +77,7 @@ static const char *inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
else if (af == AF_INET6)
{
struct sockaddr_in6 in;
- memset(&in, 0, sizeof(in));
+ in = (struct sockaddr_in6){0};
in.sin6_family = AF_INET6;
memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
getnameinfo((struct sockaddr *)&in, sizeof(struct
@@ -91,7 +91,7 @@ static int inet_pton(int af, const char *src, void *dst)
{
struct addrinfo hints, *res, *ressave;
- memset(&hints, 0, sizeof(struct addrinfo));
+ hints = (struct addrinfo){0};
hints.ai_family = af;
if (getaddrinfo(src, NULL, &hints, &res) != 0)
@@ -148,7 +148,7 @@ mrb_addrinfo_getaddrinfo(mrb_state *mrb, mrb_value klass)
mrb_raise(mrb, E_TYPE_ERROR, "service must be String, Integer, or nil");
}
- memset(&hints, 0, sizeof(hints));
+ hints = (struct addrinfo){0};
hints.ai_flags = (int)flags;
if (mrb_integer_p(family)) {

MODIFY
src/class.c
src/class.c
@@ -1698,7 +1698,9 @@ mrb_define_module_function(mrb_state *mrb, struct RClass *c, const char *name, m
static void
mc_clear(mrb_state *mrb)
{
- memset(mrb->cache, 0, MRB_METHOD_CACHE_SIZE*sizeof(mrb->cache[0]));
+ for (int i=0; i<MRB_METHOD_CACHE_SIZE; i++) {
+ mrb->cache[i] = (struct mrb_cache_entry){0};
+ }
}
void

MODIFY
src/vm.c
src/vm.c
@@ -86,14 +86,10 @@ void mrb_method_missing(mrb_state *mrb, mrb_sym name, mrb_value self, mrb_value
static inline void
stack_clear(mrb_value *from, size_t count)
{
-#ifdef MRB_NAN_BOXING
while (count-- > 0) {
SET_NIL_VALUE(*from);
from++;
}
-#else
- memset(from, 0, sizeof(mrb_value)*count);
-#endif
}
static inline void

Use `struct` initializer instead of `memset`.