Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Don't name unused exceptions.
[simgrid.git] / teshsuite / mc / dwarf-expression / dwarf-expression.cpp
index 8dfb552..2dce6b2 100644 (file)
@@ -11,6 +11,7 @@
 #include <cassert>
 #include <cstdlib>
 #include <cstring>
+#include <random>
 
 #include "src/mc/mc_private.hpp"
 
@@ -19,6 +20,8 @@
 #include "src/mc/Variable.hpp"
 #include "src/mc/remote/RemoteClient.hpp"
 
+static std::default_random_engine rnd_engine;
+
 static simgrid::mc::RemoteClient* process;
 
 static
@@ -36,8 +39,7 @@ uintptr_t eval_binary_operation(
 
   try {
     simgrid::dwarf::execute(ops, 3, state, stack);
-  }
-  catch(std::runtime_error& e) {
+  } catch (const std::runtime_error&) {
     fprintf(stderr,"Expression evaluation error");
   }
 
@@ -51,8 +53,8 @@ void basic_test(simgrid::dwarf::ExpressionContext const& state) {
 
   Dwarf_Op ops[60];
 
-  uintptr_t a = rand();
-  uintptr_t b = rand();
+  uintptr_t a = rnd_engine();
+  uintptr_t b = rnd_engine();
 
   simgrid::dwarf::ExpressionStack stack;
 
@@ -60,7 +62,7 @@ void basic_test(simgrid::dwarf::ExpressionContext const& state) {
   try {
     ops[0].atom = DW_OP_drop;
     simgrid::dwarf::execute(ops, 1, state, stack);
-  } catch (simgrid::dwarf::evaluation_error& e) {
+  } catch (const simgrid::dwarf::evaluation_error&) {
     caught_ex = true;
   }
   if (not caught_ex)
@@ -122,8 +124,7 @@ void basic_test(simgrid::dwarf::ExpressionContext const& state) {
   assert(stack.top()  == a);
   assert(stack.top(1) == b);
 
-  }
-  catch(std::runtime_error& e) {
+  } catch (const std::runtime_error&) {
     fprintf(stderr,"Expression evaluation error");
   }
 }
@@ -145,8 +146,7 @@ void test_deref(simgrid::dwarf::ExpressionContext const& state) {
   assert(stack.size() == 1);
   assert(stack.top()  == foo);
 
-  }
-  catch(std::runtime_error& e) {
+  } catch (const std::runtime_error&) {
     fprintf(stderr,"Expression evaluation error");
   }
 }
@@ -161,26 +161,26 @@ int main(int argc, char** argv) {
   basic_test(state);
 
   for(int i=0; i!=100; ++i) {
-    uintptr_t a = rand();
-    uintptr_t b = rand();
+    uintptr_t a = rnd_engine();
+    uintptr_t b = rnd_engine();
     assert(eval_binary_operation(state, DW_OP_plus, a, b) == (a + b));
   }
 
   for(int i=0; i!=100; ++i) {
-    uintptr_t a = rand();
-    uintptr_t b = rand();
+    uintptr_t a = rnd_engine();
+    uintptr_t b = rnd_engine();
     assert(eval_binary_operation(state, DW_OP_or, a, b) == (a | b));
   }
 
   for(int i=0; i!=100; ++i) {
-    uintptr_t a = rand();
-    uintptr_t b = rand();
+    uintptr_t a = rnd_engine();
+    uintptr_t b = rnd_engine();
     assert(eval_binary_operation(state, DW_OP_and, a, b) == (a & b));
   }
 
   for(int i=0; i!=100; ++i) {
-    uintptr_t a = rand();
-    uintptr_t b = rand();
+    uintptr_t a = rnd_engine();
+    uintptr_t b = rnd_engine();
     assert(eval_binary_operation(state, DW_OP_xor, a, b) == (a ^ b));
   }