summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYukihiro "Matz" Matsumoto <[email protected]>2020-04-28 18:30:50 +0900
committerHiroshi Mimaki <[email protected]>2020-05-07 09:33:44 +0900
commit9f4b5227fe21ad778d3b408c12315168307ae25f (patch)
treeb40451ef22fe057b08e7aa58845b94ed8e6f8dc5
parentd464fe50033084df6f171956d2fa051e4448c22f (diff)
downloadmruby-9f4b5227fe21ad778d3b408c12315168307ae25f.tar.gz
mruby-9f4b5227fe21ad778d3b408c12315168307ae25f.zip
Avoid `snprintf` in `mruby-io` test; ref #4981
-rw-r--r--mrbgems/mruby-io/test/mruby_io_test.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/mrbgems/mruby-io/test/mruby_io_test.c b/mrbgems/mruby-io/test/mruby_io_test.c
index 18635fb55..36872e7b7 100644
--- a/mrbgems/mruby-io/test/mruby_io_test.c
+++ b/mrbgems/mruby-io/test/mruby_io_test.c
@@ -77,22 +77,21 @@ static int mrb_io_socket_available()
struct sockaddr_un sun0;
char socketname[] = "tmp.mruby-io-socket-ok.XXXXXXXX";
if (!(fd = mkstemp(socketname))) {
- retval = 0;
goto sock_test_out;
}
unlink(socketname);
close(fd);
fd = socket(AF_UNIX, SOCK_STREAM, 0);
if (fd == -1) {
- retval = 0;
goto sock_test_out;
}
sun0.sun_family = AF_UNIX;
- snprintf(sun0.sun_path, sizeof(sun0.sun_path), "%s", socketname);
+ strncpy(sun0.sun_path, socketname, sizeof(sun0.sun_path));
if (bind(fd, (struct sockaddr *)&sun0, sizeof(sun0)) == -1) {
retval = 0;
}
sock_test_out:
+ retval = 0;
unlink(socketname);
close(fd);
return retval;
@@ -181,7 +180,7 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
mrb_raise(mrb, E_RUNTIME_ERROR, "can't make a socket");
}
sun0.sun_family = AF_UNIX;
- snprintf(sun0.sun_path, sizeof(sun0.sun_path), "%s", socketname);
+ strncpy(sun0.sun_path, socketname, sizeof(sun0.sun_path));
if (bind(fd3, (struct sockaddr *)&sun0, sizeof(sun0)) == -1) {
mrb_raisef(mrb, E_RUNTIME_ERROR, "can't bind AF_UNIX socket to %s: %d",
sun0.sun_path,