Should not use `assert` with expressions with side-effect; ref #49812.1.1-rc2
authorYukihiro "Matz" Matsumoto <[email protected]>
Tue, 28 Apr 2020 13:36:32 +0000 (28 22:36 +0900)
committerHiroshi Mimaki <[email protected]>
Thu, 7 May 2020 00:37:02 +0000 (7 09:37 +0900)
`assert()` can be completely removed when `NDEBUG` is set.

mrbgems/mruby-io/test/mruby_io_test.c

index 7165d09..4dce48c 100644 (file)
@@ -53,7 +53,6 @@ mkdtemp(char *temp)
   #include <sys/socket.h>
   #include <unistd.h>
   #include <sys/un.h>
-  #include <assert.h>
   #include <fcntl.h>
 #endif
 
@@ -117,10 +116,8 @@ mrb_io_test_io_setup(mrb_state *mrb, mrb_value self)
     char *tmpdir;
     wd_save = open(".", O_DIRECTORY);
     tmpdir = getenv("TMPDIR");
-    if (tmpdir)
-      assert(!chdir(tmpdir));
-    else
-      assert(!chdir("/tmp"));
+    if (tmpdir) chdir(tmpdir);
+    else chdir("/tmp");
   }
 #endif
 
@@ -220,7 +217,7 @@ mrb_io_test_io_cleanup(mrb_state *mrb, mrb_value self)
 
 #if !defined(_WIN32) && !defined(_WIN64)
   if(!socket_available_p) {
-    assert(!fchdir(wd_save));
+    fchdir(wd_save);
     close(wd_save);
   }
 #endif