]> git.openfabrics.org - ~shefty/ibacm.git/commitdiff
Refresh of snprintf
authorSean Hefty <sean.hefty@intel.com>
Mon, 23 Apr 2012 16:13:13 +0000 (09:13 -0700)
committerSean Hefty <sean.hefty@intel.com>
Mon, 23 Apr 2012 16:13:13 +0000 (09:13 -0700)
linux/acme_linux.c
src/acm.c
src/parse.c

index 9477d29439268e0a2bd992b19d321c08dc9ae334..1039645ec9e6665ec23db75a39603696a7c29d69 100644 (file)
@@ -53,7 +53,7 @@ get_pkey(struct ifreq *ifreq, uint16_t *pkey)
        FILE *f;
        int ret;
 
-       sprintf(buf, "//sys//class//net//%s//pkey", ifreq->ifr_name);
+       snprintf(buf, sizeof buf, "//sys//class//net//%s//pkey", ifreq->ifr_name);
        f = fopen(buf, "r");
        if (!f) {
                printf("failed to open %s\n", buf);
@@ -79,7 +79,7 @@ get_sgid(struct ifreq *ifr, union ibv_gid *sgid)
        FILE *f;
        int i, p, ret;
 
-       sprintf(buf, "//sys//class//net//%s//address", ifr->ifr_name);
+       snprintf(buf, sizeof buf, "//sys//class//net//%s//address", ifr->ifr_name);
        f = fopen(buf, "r");
        if (!f) {
                printf("failed to open %s\n", buf);
index 099e84e5079fea0021126be153db3879873a86ad..376f294f6895f8c4bfa2611151706a6d4ab934dd 100644 (file)
--- a/src/acm.c
+++ b/src/acm.c
@@ -268,7 +268,7 @@ acm_format_name(int level, char *name, size_t name_size,
        case ACM_EP_INFO_PATH:
                path = (struct ibv_path_record *) addr;
                if (path->dlid) {
-                       sprintf(name, "SLID(%u) DLID(%u)",
+                       snprintf(name, name_size, "SLID(%u) DLID(%u)",
                                ntohs(path->slid), ntohs(path->dlid));
                } else {
                        acm_format_name(level, name, name_size, ACM_ADDRESS_GID,
@@ -276,7 +276,7 @@ acm_format_name(int level, char *name, size_t name_size,
                }
                break;
        case ACM_ADDRESS_LID:
-               sprintf(name, "LID(%u)", ntohs(*((uint16_t *) addr)));
+               snprintf(name, name_size, "LID(%u)", ntohs(*((uint16_t *) addr)));
                break;
        default:
                strcpy(name, "Unknown");
@@ -3125,7 +3125,7 @@ static int acm_open_lock_file(void)
                return -1;
        }
 
-       sprintf(pid, "%d\n", getpid());
+       snprintf(pid, sizeof pid, "%d\n", getpid());
        write(lock_fd, pid, strlen(pid));
        return 0;
 }
index 9a01afbcf9bcaf3043d1a5161ef2d698b6c4a8d0..83ce8439edac94f5d9501ab1afb80ebe9c86e8df 100644 (file)
@@ -52,7 +52,7 @@ static char *expand(char *basename, char *args, int *str_cnt, int *str_size)
                }
 
                while (from <= to) {
-                       sprintf(buf, "%s%0*d", basename, width, from);
+                       snprintf(buf, sizeof buf, "%s%0*d", basename, width, from);
                        str_buf = realloc(str_buf, size + strlen(buf)+1);
                        strcpy(&str_buf[size], buf);