Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Use C++ std::array (sonar).
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Feb 2022 14:26:57 +0000 (15:26 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Wed, 16 Feb 2022 15:07:48 +0000 (16:07 +0100)
src/mc/ModelChecker.cpp
src/mc/remote/AppSide.cpp
src/mc/remote/mc_protocol.h

index 5b517e5..0f0d02c 100644 (file)
@@ -332,7 +332,7 @@ Transition* ModelChecker::handle_simcall(aid_t aid, int times_considered, bool n
     checker_side_.dispatch(); // The app may send messages while processing the transition
 
   if (new_transition) {
-    std::stringstream stream(answer.buffer);
+    std::stringstream stream(answer.buffer.data());
     return deserialize_transition(aid, times_considered, stream);
   } else
     return nullptr;
index e062682..ed860fc 100644 (file)
@@ -109,11 +109,13 @@ void AppSide::handle_simcall_execute(const s_mc_message_simcall_execute_t* messa
   } else {
     stream << (short)mc::Transition::Type::UNKNOWN;
   }
-  xbt_assert(stream.str().size() < sizeof(answer.buffer) - 1,
+  std::string str = stream.str();
+  xbt_assert(str.size() + 1 <= answer.buffer.size(),
              "The serialized simcall is too large for the buffer. Please fix the code.");
-  strncpy(answer.buffer, stream.str().c_str(), sizeof(answer.buffer) - 1);
+  strncpy(answer.buffer.data(), str.c_str(), answer.buffer.size() - 1);
+  answer.buffer.back() = '\0';
 
-  XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> '%s'", actor->get_cname(), answer.buffer);
+  XBT_DEBUG("send SIMCALL_EXECUTE_ANSWER(%s) ~> '%s'", actor->get_cname(), str.c_str());
   xbt_assert(channel_.send(answer) == 0, "Could not send response");
 
   // The client may send some messages to the server while processing the transition
index b933fea..ef82981 100644 (file)
@@ -35,12 +35,11 @@ XBT_DECLARE_ENUM_CLASS(MessageType, NONE, INITIAL_ADDRESSES, CONTINUE, IGNORE_HE
                        SIMCALL_EXECUTE_ANSWER, SIMCALL_IS_VISIBLE, SIMCALL_IS_VISIBLE_ANSWER, ASSERTION_FAILED,
                        ACTOR_ENABLED, ACTOR_ENABLED_REPLY, FINALIZE);
 
-#define SIMCALL_SERIALIZATION_BUFFER_SIZE 2048
-
 } // namespace mc
 } // namespace simgrid
 
 constexpr unsigned MC_MESSAGE_LENGTH = 512;
+constexpr unsigned SIMCALL_SERIALIZATION_BUFFER_SIZE = 2048;
 
 /** Basic structure for a MC message
  *
@@ -105,7 +104,7 @@ struct s_mc_message_simcall_execute_t {
 };
 struct s_mc_message_simcall_execute_answer_t {
   simgrid::mc::MessageType type;
-  char buffer[SIMCALL_SERIALIZATION_BUFFER_SIZE];
+  std::array<char, SIMCALL_SERIALIZATION_BUFFER_SIZE> buffer;
 };
 
 struct s_mc_message_restore_t {