Use sizeof rather than hardcoded constant in case buffer size changes in future

Signed-off-by: Hal Rosenstock <[email protected]>

---
diff --git a/opensm/opensm/osm_console.c b/opensm/opensm/osm_console.c
index 00264e5..d351261 100644
--- a/opensm/opensm/osm_console.c
+++ b/opensm/opensm/osm_console.c
@@ -1426,14 +1426,17 @@ int osm_console(osm_opensm_t * p_osm)
                if (inet_ntop
                    (AF_INET, &sin.sin_addr, p_oct->client_ip,
                     sizeof(p_oct->client_ip)) == NULL) {
-                       snprintf(p_oct->client_ip, 64, "STRING_UNKNOWN");
+                       snprintf(p_oct->client_ip, sizeof(p_oct->client_ip),
+                                "STRING_UNKNOWN");
                }
                if ((hent = gethostbyaddr((const char *)&sin.sin_addr,
                                          sizeof(struct in_addr),
                                          AF_INET)) == NULL) {
-                       snprintf(p_oct->client_hn, 128, "STRING_UNKNOWN");
+                       snprintf(p_oct->client_hn, sizeof(p_oct->client_hn),
+                                "STRING_UNKNOWN");
                } else {
-                       snprintf(p_oct->client_hn, 128, "%s", hent->h_name);
+                       snprintf(p_oct->client_hn, sizeof(p_oct->client_hn),
+                                "%s", hent->h_name);
                }
                if (is_authorized(p_oct)) {
                        cio_open(p_oct, new_fd, &p_osm->log);
diff --git a/opensm/opensm/osm_event_plugin.c b/opensm/opensm/osm_event_plugin.c
index b0dc549..c77494e 100644
--- a/opensm/opensm/osm_event_plugin.c
+++ b/opensm/opensm/osm_event_plugin.c
@@ -73,7 +73,7 @@ osm_epi_plugin_t *osm_epi_construct(osm_opensm_t *osm, char 
*plugin_name)
                return (NULL);
 
        /* find the plugin */
-       snprintf(lib_name, OSM_PATH_MAX, "lib%s.so", plugin_name);
+       snprintf(lib_name, sizeof(lib_name), "lib%s.so", plugin_name);
 
        rc = malloc(sizeof(*rc));
        if (!rc)
diff --git a/opensm/opensm/osm_perfmgr_db.c b/opensm/opensm/osm_perfmgr_db.c
index b0b2e4a..8be0b6f 100644
--- a/opensm/opensm/osm_perfmgr_db.c
+++ b/opensm/opensm/osm_perfmgr_db.c
@@ -120,7 +120,7 @@ static _db_node_t *__malloc_node(uint64_t guid, boolean_t 
esp0,
                rc->ports[i].err_previous.time = cur_time;
                rc->ports[i].dc_previous.time = cur_time;
        }
-       snprintf(rc->node_name, NODE_NAME_SIZE, "%s", name);
+       snprintf(rc->node_name, sizeof(rc->node_name), "%s", name);
 
        return (rc);
 
_______________________________________________
general mailing list
[email protected]
http://lists.openfabrics.org/cgi-bin/mailman/listinfo/general

To unsubscribe, please visit http://openib.org/mailman/listinfo/openib-general

Reply via email to