[ofa-general] [PATCH TRIVIAL] opensm/osm_helper: remove repeated strlen() calls

Sasha Khapyorsky sashak at voltaire.com
Sun May 6 06:03:52 PDT 2007


Replace repeated strlen() calls used in sprintf() by actual string
length accumulated from sprintf() return values.

Signed-off-by: Sasha Khapyorsky <sashak at voltaire.com>
---
 osm/opensm/osm_helper.c |   56 +++++++++++++++++++++--------------------------
 1 files changed, 25 insertions(+), 31 deletions(-)

diff --git a/osm/opensm/osm_helper.c b/osm/opensm/osm_helper.c
index a1a2e93..b424e84 100644
--- a/osm/opensm/osm_helper.c
+++ b/osm/opensm/osm_helper.c
@@ -1145,22 +1145,22 @@ osm_dump_multipath_record(
   IN const ib_multipath_rec_t* const p_mpr,
   IN const osm_log_level_t log_level )
 {
-  int i;
   char buf_line[1024];
   ib_gid_t const *p_gid;
+  int i, n;
 
   if( osm_log_is_active( p_log, log_level ) )
   {
-    memset(buf_line, 0, sizeof(buf_line));
+    n = 0;
     p_gid = p_mpr->gids;
     if ( p_mpr->sgid_count )
     {
       for (i = 0; i < p_mpr->sgid_count; i++)
       {
-        sprintf( buf_line + strlen(buf_line), "\t\t\t\tsgid%02d.................."
-                 "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
-                 i + 1, cl_ntoh64( p_gid->unicast.prefix ),
-                 cl_ntoh64( p_gid->unicast.interface_id ) );
+        n += sprintf( buf_line + n, "\t\t\t\tsgid%02d.................."
+                      "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
+                      i + 1, cl_ntoh64( p_gid->unicast.prefix ),
+                      cl_ntoh64( p_gid->unicast.interface_id ) );
         p_gid++;
       }
     }
@@ -1168,10 +1168,10 @@ osm_dump_multipath_record(
     {
       for (i = 0; i < p_mpr->dgid_count; i++)
       {
-        sprintf( buf_line + strlen(buf_line), "\t\t\t\tdgid%02d.................."
-                 "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
-                 i + 1, cl_ntoh64( p_gid->unicast.prefix ),
-                 cl_ntoh64( p_gid->unicast.interface_id ) );
+        n += sprintf( buf_line + n, "\t\t\t\tdgid%02d.................."
+                      "0x%016" PRIx64 " : 0x%016" PRIx64 "\n",
+                      i + 1, cl_ntoh64( p_gid->unicast.prefix ),
+                      cl_ntoh64( p_gid->unicast.interface_id ) );
         p_gid++;
       }
     }
@@ -1650,15 +1650,14 @@ osm_dump_pkey_block(
   IN const ib_pkey_table_t* const p_pkey_tbl,
   IN const osm_log_level_t log_level )
 {
-  int i;
   char buf_line[1024];
+  int i, n;
 
   if( osm_log_is_active( p_log, log_level ) )
   {
-    buf_line[0] = '\0';
-    for (i = 0; i < 32; i++)
-      sprintf( buf_line + strlen(buf_line)," 0x%04x |",
-               cl_ntoh16(p_pkey_tbl->pkey_entry[i]));
+    for (i = 0, n = 0; i < 32; i++)
+      n += sprintf( buf_line + n," 0x%04x |",
+                    cl_ntoh16(p_pkey_tbl->pkey_entry[i]));
 
     osm_log( p_log, log_level,
              "P_Key table dump:\n"
@@ -1684,18 +1683,17 @@ osm_dump_slvl_map_table(
   IN const ib_slvl_table_t* const p_slvl_tbl,
   IN const osm_log_level_t log_level )
 {
-  uint8_t i;
   char buf_line1[1024];
   char buf_line2[1024];
+  int n;
+  uint8_t i;
 
   if( osm_log_is_active( p_log, log_level ) )
   {
-    buf_line1[0] = '\0';
-    buf_line2[0] = '\0';
-    for (i = 0; i < 16; i++)
-      sprintf( buf_line1 + strlen(buf_line1)," %-2u |", i);
-    for (i = 0; i < 16; i++)
-      sprintf( buf_line2 + strlen(buf_line2),"0x%01X |",
+    for (i = 0, n = 0; i < 16; i++)
+      n += sprintf( buf_line1 + n," %-2u |", i);
+    for (i = 0, n = 0; i < 16; i++)
+      n += sprintf( buf_line2 + n,"0x%01X |",
                ib_slvl_table_get(p_slvl_tbl, i));
     osm_log( p_log, log_level,
              "SLtoVL dump:\n"
@@ -1721,20 +1719,16 @@ osm_dump_vl_arb_table(
   IN const ib_vl_arb_table_t* const p_vla_tbl,
   IN const osm_log_level_t log_level )
 {
-  int i;
   char buf_line1[1024];
   char buf_line2[1024];
+  int i, n;
 
   if( osm_log_is_active( p_log, log_level ) )
   {
-    buf_line1[0] = '\0';
-    buf_line2[0] = '\0';
-    for (i = 0; i < 32; i++)
-      sprintf( buf_line1 + strlen(buf_line1)," 0x%01X |",
-               p_vla_tbl->vl_entry[i].vl);
-    for (i = 0; i < 32; i++)
-      sprintf( buf_line2 + strlen(buf_line2)," 0x%01X |",
-               p_vla_tbl->vl_entry[i].weight);
+    for (i = 0, n = 0; i < 32; i++)
+      n += sprintf( buf_line1 + n," 0x%01X |", p_vla_tbl->vl_entry[i].vl);
+    for (i = 0, n = 0; i < 32; i++)
+      n += sprintf( buf_line2 + n," 0x%01X |", p_vla_tbl->vl_entry[i].weight);
     osm_log( p_log, log_level,
              "VlArb dump:\n"
              "\t\t\tport_guid...........0x%016" PRIx64 "\n"
-- 
1.5.1.rc1.18.ga41b4




More information about the general mailing list