Fix clang-tidy-11 for topology module
[alexxy/gromacs.git] / src / gromacs / topology / symtab.cpp
index c6e56a5ec153fefd9b65d69cb40672ac0cf16e99..84ae546e074cdc9d61c38357e456e4dfda28c361 100644 (file)
@@ -4,7 +4,7 @@
  * Copyright (c) 1991-2000, University of Groningen, The Netherlands.
  * Copyright (c) 2001-2004, The GROMACS development team.
  * Copyright (c) 2013,2014,2015,2016,2017 by the GROMACS development team.
- * Copyright (c) 2018,2019,2020, by the GROMACS development team, led by
+ * Copyright (c) 2018,2019,2020,2021, by the GROMACS development team, led by
  * Mark Abraham, David van der Spoel, Berk Hess, and Erik Lindahl,
  * and including many others, as listed in the AUTHORS file in the
  * top-level source directory and at http://www.gromacs.org.
@@ -185,7 +185,7 @@ constexpr int c_maxBufSize = 5;
  */
 static char* trim_string(const char* s, char* out, int maxlen)
 {
-    int len, i;
+    int len = 0, i = 0;
 
     if (strlen(s) > static_cast<size_t>(maxlen - 1))
     {
@@ -214,11 +214,8 @@ static char* trim_string(const char* s, char* out, int maxlen)
 
 int lookup_symtab(t_symtab* symtab, char** name)
 {
-    int       base;
-    t_symbuf* symbuf;
-
-    base   = 0;
-    symbuf = symtab->symbuf;
+    int       base   = 0;
+    t_symbuf* symbuf = symtab->symbuf;
     while (symbuf != nullptr)
     {
         const int index = name - symbuf->buf;
@@ -237,9 +234,7 @@ int lookup_symtab(t_symtab* symtab, char** name)
 
 char** get_symtab_handle(t_symtab* symtab, int name)
 {
-    t_symbuf* symbuf;
-
-    symbuf = symtab->symbuf;
+    t_symbuf* symbuf = symtab->symbuf;
     while (symbuf != nullptr)
     {
         if (name < symbuf->bufsize)
@@ -258,7 +253,7 @@ char** get_symtab_handle(t_symtab* symtab, int name)
 //! Returns a new initialized entry into the symtab linked list.
 static t_symbuf* new_symbuf()
 {
-    t_symbuf* symbuf;
+    t_symbuf* symbuf = nullptr;
 
     snew(symbuf, 1);
     symbuf->bufsize = c_maxBufSize;
@@ -277,19 +272,17 @@ static t_symbuf* new_symbuf()
  */
 static char** enter_buf(t_symtab* symtab, char* name)
 {
-    int       i;
-    t_symbuf* symbuf;
-    gmx_bool  bCont;
+    bool bCont = false;
 
     if (symtab->symbuf == nullptr)
     {
         symtab->symbuf = new_symbuf();
     }
 
-    symbuf = symtab->symbuf;
+    t_symbuf* symbuf = symtab->symbuf;
     do
     {
-        for (i = 0; (i < symbuf->bufsize); i++)
+        for (int i = 0; (i < symbuf->bufsize); i++)
         {
             if (symbuf->buf[i] == nullptr)
             {
@@ -340,7 +333,7 @@ void close_symtab(t_symtab gmx_unused* symtab) {}
 // std::list<std::vector<std::string>>> for t_symtab.
 t_symtab* duplicateSymtab(const t_symtab* symtab)
 {
-    t_symtab* copySymtab;
+    t_symtab* copySymtab = nullptr;
     snew(copySymtab, 1);
     open_symtab(copySymtab);
     t_symbuf* symbuf = symtab->symbuf;
@@ -373,21 +366,19 @@ t_symtab* duplicateSymtab(const t_symtab* symtab)
 
 void done_symtab(t_symtab* symtab)
 {
-    int       i;
-    t_symbuf *symbuf, *freeptr;
-
     close_symtab(symtab);
-    symbuf = symtab->symbuf;
+    t_symbuf* symbuf = symtab->symbuf;
     while (symbuf != nullptr)
     {
-        for (i = 0; (i < symbuf->bufsize) && (i < symtab->nr); i++)
+        int i = 0;
+        for (; (i < symbuf->bufsize) && (i < symtab->nr); i++)
         {
             sfree(symbuf->buf[i]);
         }
         symtab->nr -= i;
         sfree(symbuf->buf);
-        freeptr = symbuf;
-        symbuf  = symbuf->next;
+        t_symbuf* freeptr = symbuf;
+        symbuf            = symbuf->next;
         sfree(freeptr);
     }
     symtab->symbuf = nullptr;
@@ -399,15 +390,13 @@ void done_symtab(t_symtab* symtab)
 
 void free_symtab(t_symtab* symtab)
 {
-    t_symbuf *symbuf, *freeptr;
-
     close_symtab(symtab);
-    symbuf = symtab->symbuf;
+    t_symbuf* symbuf = symtab->symbuf;
     while (symbuf != nullptr)
     {
         symtab->nr -= std::min(symbuf->bufsize, symtab->nr);
-        freeptr = symbuf;
-        symbuf  = symbuf->next;
+        t_symbuf* freeptr = symbuf;
+        symbuf            = symbuf->next;
         sfree(freeptr);
     }
     symtab->symbuf = nullptr;
@@ -419,18 +408,16 @@ void free_symtab(t_symtab* symtab)
 
 void pr_symtab(FILE* fp, int indent, const char* title, t_symtab* symtab)
 {
-    int       i, j, nr;
-    t_symbuf* symbuf;
-
     if (available(fp, symtab, indent, title))
     {
-        indent = pr_title_n(fp, indent, title, symtab->nr);
-        i      = 0;
-        nr     = symtab->nr;
-        symbuf = symtab->symbuf;
+        indent           = pr_title_n(fp, indent, title, symtab->nr);
+        int       i      = 0;
+        int       nr     = symtab->nr;
+        t_symbuf* symbuf = symtab->symbuf;
         while (symbuf != nullptr)
         {
-            for (j = 0; (j < symbuf->bufsize) && (j < nr); j++)
+            int j = 0;
+            for (; (j < symbuf->bufsize) && (j < nr); j++)
             {
                 pr_indent(fp, indent);
                 (void)fprintf(fp, "%s[%d]=\"%s\"\n", title, i++, symbuf->buf[j]);