Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
[sonar] Constify pointer and reference local variables in src/xbt/.
authorArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Dec 2019 21:09:47 +0000 (22:09 +0100)
committerArnaud Giersch <arnaud.giersch@univ-fcomte.fr>
Mon, 23 Dec 2019 23:33:39 +0000 (00:33 +0100)
13 files changed:
src/xbt/automaton/automaton.c
src/xbt/automaton/automatonparse_promela.c
src/xbt/dict.cpp
src/xbt/dict_cursor.c
src/xbt/dict_test.cpp
src/xbt/dynar.cpp
src/xbt/dynar_test.cpp
src/xbt/exception.cpp
src/xbt/log.cpp
src/xbt/memory_map.cpp
src/xbt/xbt_os_file.cpp
src/xbt/xbt_replay.cpp
src/xbt/xbt_virtu.cpp

index 708b5e1..b15cd73 100644 (file)
@@ -316,8 +316,8 @@ int xbt_automaton_propositional_symbols_compare_value(xbt_dynar_t s1, xbt_dynar_
   unsigned int nb_elem = xbt_dynar_length(s1);
 
   for (unsigned int cursor = 0; cursor < nb_elem; cursor++) {
-    int* iptr1 = xbt_dynar_get_ptr(s1, cursor);
-    int* iptr2 = xbt_dynar_get_ptr(s2, cursor);
+    const int* iptr1 = xbt_dynar_get_ptr(s1, cursor);
+    const int* iptr2 = xbt_dynar_get_ptr(s2, cursor);
     if(*iptr1 != *iptr2)
       return 1;
   }
index bb18110..84cb583 100644 (file)
@@ -22,13 +22,13 @@ char* state_id_src;
 static void new_state(char* id, int src){
   char* saveptr = NULL; // for strtok_r()
   char* id_copy = xbt_strdup(id);
-  char* first_part = strtok_r(id_copy, "_", &saveptr);
+  const char* first_part = strtok_r(id_copy, "_", &saveptr);
   int type = 0 ; // -1=initial state; 0=intermediate state; 1=final state
 
   if(strcmp(first_part,"accept")==0){
     type = 1;
   }else{
-    char* second_part = strtok_r(NULL, "_", &saveptr);
+    const char* second_part = strtok_r(NULL, "_", &saveptr);
     if(strcmp(second_part,"init")==0){
       type = -1;
     }
index 44361dc..1b33417 100644 (file)
@@ -197,7 +197,7 @@ void xbt_dict_set(xbt_dict_t dict, const char* key, void* data)
 void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
 {
   unsigned int hash_code = xbt_str_hash_ext(key, key_len);
-  xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
+  const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
 
   while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
           || memcmp(key, current->key, key_len))) {
@@ -214,7 +214,7 @@ void *xbt_dict_get_ext(xbt_dict_t dict, const char *key, int key_len)
 void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
 {
   unsigned int hash_code = xbt_str_hash_ext(key, key_len);
-  xbt_dictelm_t current = dict->table[hash_code & dict->table_size];
+  const s_xbt_dictelm* current = dict->table[hash_code & dict->table_size];
 
   while (current != nullptr && (hash_code != current->hash_code || key_len != current->key_len
           || memcmp(key, current->key, key_len))) {
@@ -235,7 +235,7 @@ void *xbt_dict_get_or_null_ext(xbt_dict_t dict, const char *key, int key_len)
 char *xbt_dict_get_key(xbt_dict_t dict, const void *data)
 {
   for (int i = 0; i <= dict->table_size; i++) {
-    xbt_dictelm_t current = dict->table[i];
+    const s_xbt_dictelm* current = dict->table[i];
     while (current != nullptr) {
       if (current->content == data)
         return current->key;
@@ -285,7 +285,7 @@ xbt_dictelm_t xbt_dict_get_elm(xbt_dict_t dict, const char *key)
  */
 void *xbt_dict_get_or_null(xbt_dict_t dict, const char *key)
 {
-  xbt_dictelm_t current = xbt_dict_get_elm_or_null(dict, key);
+  const s_xbt_dictelm* current = xbt_dict_get_elm_or_null(dict, key);
 
   if (current == nullptr)
     return nullptr;
index 5ee224a..ca96b1c 100644 (file)
@@ -123,7 +123,7 @@ inline void xbt_dict_cursor_step(xbt_dict_cursor_t cursor)
  */
 inline int xbt_dict_cursor_get_or_free(xbt_dict_cursor_t * cursor, char **key, void **data)
 {
-  xbt_dictelm_t current;
+  const struct s_xbt_dictelm* current;
 
   XBT_CDEBUG(xbt_dict_cursor, "xbt_dict_get_or_free");
 
index 8fe2f65..2045fa4 100644 (file)
@@ -192,7 +192,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
 
     /* RETRIEVE */
     INFO("Search 123");
-    char* data = (char*)xbt_dict_get(head, "123");
+    const char* data = (char*)xbt_dict_get(head, "123");
     REQUIRE((data && strcmp("123", data) == 0));
 
     search_not_found(head, "Can't be found");
@@ -299,7 +299,7 @@ TEST_CASE("xbt::dict: dict data container", "dict")
       INFO("using 1000 elements with " << SIZEOFKEY << " chars long randomized keys.");
       xbt_dict_t head = xbt_dict_new_homogeneous(free);
       for (int j = 0; j < 1000; j++) {
-        char* data = nullptr;
+        const char* data = nullptr;
         char* key  = (char*)xbt_malloc(SIZEOFKEY);
 
         do {
index 5c62e73..a1e04a8 100644 (file)
@@ -71,8 +71,7 @@ static inline void *_xbt_dynar_elm(const xbt_dynar_t dynar, const unsigned long
 
 static inline void _xbt_dynar_get_elm(void *const dst, const xbt_dynar_t dynar, const unsigned long idx)
 {
-  void *const elm = _xbt_dynar_elm(dynar, idx);
-
+  const void* const elm = _xbt_dynar_elm(dynar, idx);
   memcpy(dst, elm, dynar->elmsize);
 }
 
@@ -167,7 +166,7 @@ void xbt_dynar_merge(xbt_dynar_t* d1, xbt_dynar_t* d2)
 
   const unsigned long elmsize = (*d1)->elmsize;
 
-  void *ptr = _xbt_dynar_elm((*d2), 0);
+  const void* ptr = _xbt_dynar_elm((*d2), 0);
   _xbt_dynar_resize(*d1, (*d1)->size + (*d2)->size);
   void *elm = _xbt_dynar_elm((*d1), (*d1)->used);
 
index d549738..ebab878 100644 (file)
@@ -40,7 +40,7 @@ TEST_CASE("xbt::dynar: generic C vector", "dynar")
 
     /* 2. Traverse manually the dynar */
     for (int i = 0; i < NB_ELEM; i++) {
-      int* iptr = (int*)xbt_dynar_get_ptr(d, i);
+      const int* iptr = (int*)xbt_dynar_get_ptr(d, i);
       REQUIRE(i == *iptr); // The retrieved value is not the same than the injected one
     }
 
index 2d0748a..a152102 100644 (file)
@@ -55,8 +55,7 @@ void log_exception(e_xbt_log_priority_t prio, const char* context, std::exceptio
       return;
     try {
       with_nested->rethrow_nested();
-    }
-    catch (std::exception& nested_exception) {
+    } catch (const std::exception& nested_exception) {
       log_exception(prio, "Caused by", nested_exception);
     }
     // We could catch nested_exception or WithContextException but we don't bother:
@@ -100,14 +99,14 @@ static void handler()
   }
 
   // Parse error are handled differently, as the call stack does not matter, only the file location
-  catch (simgrid::ParseError& e) {
+  catch (const simgrid::ParseError& e) {
     XBT_ERROR("%s", e.what());
     XBT_ERROR("Exiting now.");
     std::abort();
   }
 
   // We manage C++ exception ourselves
-  catch (std::exception& e) {
+  catch (const std::exception& e) {
     log_exception(xbt_log_priority_critical, "Uncaught exception", e);
     show_backtrace(bt);
     std::abort();
index 17cc12c..0060b27 100644 (file)
@@ -157,7 +157,7 @@ static constexpr size_t XBT_LOG_DYNAMIC_BUFFER_SIZE = 4096;
 
 void _xbt_log_event_log(xbt_log_event_t ev, const char *fmt, ...)
 {
-  xbt_log_category_t cat = ev->cat;
+  const xbt_log_category_s* cat = ev->cat;
 
   xbt_assert(ev->priority >= 0, "Negative logging priority naturally forbidden");
   xbt_assert(static_cast<size_t>(ev->priority) < sizeof(xbt_log_priority_names)/sizeof(xbt_log_priority_names[0]),
@@ -282,7 +282,7 @@ int _xbt_log_cat_init(xbt_log_category_t category, e_xbt_log_priority_t priority
 
     if (XBT_LOG_ISENABLED(log, xbt_log_priority_debug)) {
       std::string res;
-      xbt_log_category_t cpp = category->parent->firstChild;
+      const xbt_log_category_s* cpp = category->parent->firstChild;
       while (cpp) {
         res += std::string(" ") + cpp->name;
         cpp = cpp->nextSibling;
index 43ce328..4484dfe 100644 (file)
@@ -197,7 +197,7 @@ std::vector<VmMap> get_memory_map(pid_t pid)
 
     /* Ok we are good enough to try to get the info we need */
     /* First get the start and the end address of the map   */
-    char* tok = strtok_r(lfields[0], "-", &saveptr);
+    const char* tok = strtok_r(lfields[0], "-", &saveptr);
     if (tok == nullptr) {
       std::fprintf(stderr,
                    "Start and end address of the map are not concatenated by a hyphen (-). Recovery impossible.\n");
index ce487f4..5a0b64d 100644 (file)
@@ -25,7 +25,7 @@ simgrid::xbt::Path::Path()
 {
 #if HAVE_UNISTD_H
   char buffer[2048];
-  char* ret = getcwd(buffer, 2048);
+  const char* ret = getcwd(buffer, 2048);
   xbt_assert(ret == buffer, "Error during getcwd: %s", strerror(errno));
   path_ = std::string(buffer);
 #else
@@ -36,13 +36,13 @@ simgrid::xbt::Path::Path()
 std::string simgrid::xbt::Path::get_dir_name()
 {
   std::string p(path_);
-  char *res = dirname(&p[0]);
+  const char* res = dirname(&p[0]);
   return std::string(res, strlen(res));
 }
 
 std::string simgrid::xbt::Path::get_base_name()
 {
   std::string p(path_);
-  char *res = basename(&p[0]);
+  const char* res = basename(&p[0]);
   return std::string(res, strlen(res));
 }
index 2c51d9d..cb966e9 100644 (file)
@@ -124,8 +124,7 @@ int replay_runner(const char* actor_name, const char* trace_filename)
       delete evt;
     }
     if (action_queues.find(actor_name_string) != action_queues.end()) {
-      std::queue<ReplayAction*>* myqueue = action_queues.at(actor_name_string);
-      delete myqueue;
+      delete action_queues.at(actor_name_string);
       action_queues.erase(actor_name_string);
     }
   } else { // Should have got my trace file in argument
index 557a2d3..e58f4fd 100644 (file)
@@ -11,7 +11,7 @@
 
 int xbt_getpid()
 {
-  smx_actor_t self = SIMIX_process_self();
+  const simgrid::kernel::actor::ActorImpl* self = SIMIX_process_self();
   return self == nullptr ? 0 : self->get_pid();
 }