Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/external/cddl/osnet/dist kill sprintf



details:   https://anonhg.NetBSD.org/src/rev/9e093804f62d
branches:  trunk
changeset: 794870:9e093804f62d
user:      christos <christos%NetBSD.org@localhost>
date:      Thu Mar 27 15:50:48 2014 +0000

description:
kill sprintf

diffstat:

 external/cddl/osnet/dist/cmd/dtrace/dtrace.c              |   2 +-
 external/cddl/osnet/dist/cmd/zdb/zdb.c                    |  44 ++++++++------
 external/cddl/osnet/dist/cmd/ztest/ztest.c                |  42 +++++++------
 external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c    |   2 +-
 external/cddl/osnet/dist/lib/libdtrace/common/dt_handle.c |   8 +-
 external/cddl/osnet/dist/lib/libdtrace/common/dt_link.c   |   3 +-
 external/cddl/osnet/dist/lib/libdtrace/common/dt_subr.c   |   4 +-
 external/cddl/osnet/dist/lib/libzpool/common/util.c       |  28 ++++----
 external/cddl/osnet/dist/tools/ctf/cvt/merge.c            |   3 +-
 external/cddl/osnet/dist/uts/common/dtrace/dtrace.c       |   2 +-
 external/cddl/osnet/dist/uts/common/dtrace/fasttrap.c     |   2 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/ddt.c          |  12 ++--
 external/cddl/osnet/dist/uts/common/fs/zfs/spa.c          |   6 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/sys/ddt.h      |   2 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_vfsops.c   |  10 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zfs_znode.c    |   3 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zio.c          |   6 +-
 external/cddl/osnet/dist/uts/common/fs/zfs/zvol.c         |   2 +-
 external/cddl/osnet/dist/uts/common/sys/cmn_err.h         |   5 -
 19 files changed, 99 insertions(+), 87 deletions(-)

diffs (truncated from 643 to 300 lines):

diff -r bd426f2bf898 -r 9e093804f62d external/cddl/osnet/dist/cmd/dtrace/dtrace.c
--- a/external/cddl/osnet/dist/cmd/dtrace/dtrace.c      Thu Mar 27 10:42:47 2014 +0000
+++ b/external/cddl/osnet/dist/cmd/dtrace/dtrace.c      Thu Mar 27 15:50:48 2014 +0000
@@ -953,7 +953,7 @@
                        uint8_t *data;
                        int lim = rec->dtrd_size;
 
-                       (void) sprintf(buf, "%d (data: ", rec->dtrd_offset);
+                       (void) snprintf(buf, end, "%d (data: ", rec->dtrd_offset);
                        c = buf + strlen(buf);
 
                        if (lim > sizeof (uint64_t))
diff -r bd426f2bf898 -r 9e093804f62d external/cddl/osnet/dist/cmd/zdb/zdb.c
--- a/external/cddl/osnet/dist/cmd/zdb/zdb.c    Thu Mar 27 10:42:47 2014 +0000
+++ b/external/cddl/osnet/dist/cmd/zdb/zdb.c    Thu Mar 27 15:50:48 2014 +0000
@@ -572,7 +572,7 @@
                if (ddp->ddp_phys_birth == 0)
                        continue;
                ddt_bp_create(ddt->ddt_checksum, ddk, ddp, &blk);
-               sprintf_blkptr(blkbuf, &blk);
+               snprintf_blkptr(blkbuf, sizeof(blkbuf), &blk);
                (void) printf("index %llx refcnt %llu %s %s\n",
                    (u_longlong_t)index, (u_longlong_t)ddp->ddp_refcnt,
                    types[p], blkbuf);
@@ -822,25 +822,30 @@
 }
 
 static void
-sprintf_blkptr_compact(char *blkbuf, blkptr_t *bp)
+snprintf_blkptr_compact(char *blkbuf, size_t blklen, blkptr_t *bp)
 {
        dva_t *dva = bp->blk_dva;
        int ndvas = dump_opt['d'] > 5 ? BP_GET_NDVAS(bp) : 1;
+       size_t len;
 
        if (dump_opt['b'] >= 5) {
-               sprintf_blkptr(blkbuf, bp);
+               snprintf_blkptr(blkbuf, blklen, bp);
                return;
        }
 
        blkbuf[0] = '\0';
 
-       for (int i = 0; i < ndvas; i++)
-               (void) sprintf(blkbuf + strlen(blkbuf), "%llu:%llx:%llx ",
+       len = 0;
+       for (int i = 0; i < ndvas; i++) {
+               len += snprintf(blkbuf + len, blklen - len, "%llu:%llx:%llx ",
                    (u_longlong_t)DVA_GET_VDEV(&dva[i]),
                    (u_longlong_t)DVA_GET_OFFSET(&dva[i]),
                    (u_longlong_t)DVA_GET_ASIZE(&dva[i]));
-
-       (void) sprintf(blkbuf + strlen(blkbuf),
+               if (len > blklen)
+                       len = blklen;
+       }
+
+       snprintf(blkbuf + len, blklen - len,
            "%llxL/%llxP F=%llu B=%llu/%llu",
            (u_longlong_t)BP_GET_LSIZE(bp),
            (u_longlong_t)BP_GET_PSIZE(bp),
@@ -871,7 +876,7 @@
                }
        }
 
-       sprintf_blkptr_compact(blkbuf, bp);
+       snprintf_blkptr_compact(blkbuf, sizeof(blkbuf), bp);
        (void) printf("%s\n", blkbuf);
 }
 
@@ -1010,7 +1015,7 @@
        nicenum(ds->ds_compressed_bytes, compressed);
        nicenum(ds->ds_uncompressed_bytes, uncompressed);
        nicenum(ds->ds_unique_bytes, unique);
-       sprintf_blkptr(blkbuf, &ds->ds_bp);
+       snprintf_blkptr(blkbuf, sizeof(blkbuf), &ds->ds_bp);
 
        (void) printf("\t\tdir_obj = %llu\n",
            (u_longlong_t)ds->ds_dir_obj);
@@ -1093,7 +1098,7 @@
                char blkbuf[BP_SPRINTF_LEN];
 
                ASSERT(bp->blk_birth != 0);
-               sprintf_blkptr_compact(blkbuf, bp);
+               snprintf_blkptr_compact(blkbuf, sizeof(blkbuf), bp);
                (void) printf("\tItem %3llu: %s\n",
                    (u_longlong_t)itor - 1, blkbuf);
        }
@@ -1300,7 +1305,7 @@
        nicenum(doi.doi_max_offset, lsize);
        nicenum(doi.doi_physical_blocks_512 << 9, asize);
        nicenum(doi.doi_bonus_size, bonus_size);
-       (void) sprintf(fill, "%6.2f", 100.0 * doi.doi_fill_count *
+       (void) snprintf(fill, "%6.2f", 100.0 * doi.doi_fill_count *
            doi.doi_data_block_size / (object == 0 ? DNODES_PER_BLOCK : 1) /
            doi.doi_max_offset);
 
@@ -1397,6 +1402,7 @@
        int verbosity = dump_opt['d'];
        int print_header = 1;
        int i, error;
+       size_t len;
 
        dmu_objset_fast_stat(os, &dds);
 
@@ -1417,8 +1423,10 @@
        nicenum(refdbytes, numbuf);
 
        if (verbosity >= 4) {
-               (void) sprintf(blkbuf, ", rootbp ");
-               (void) sprintf_blkptr(blkbuf + strlen(blkbuf), os->os_rootbp);
+               len = snprintf(blkbuf, blklen, ", rootbp ");
+               if (len > blklen)
+                       len = blklen;
+               printf_blkptr(blkbuf + len, blklen - len, os->os_rootbp);
        } else {
                blkbuf[0] = '\0';
        }
@@ -1490,7 +1498,7 @@
            (u_longlong_t)ub->ub_timestamp, asctime(localtime(&timestamp)));
        if (dump_opt['u'] >= 3) {
                char blkbuf[BP_SPRINTF_LEN];
-               sprintf_blkptr(blkbuf, &ub->ub_rootbp);
+               snprintf_blkptr(blkbuf, sizeof(blkbuf), &ub->ub_rootbp);
                (void) printf("\trootbp = %s\n", blkbuf);
        }
        (void) printf(footer ? footer : "");
@@ -1785,7 +1793,7 @@
                        zcb->zcb_errors[ioerr]++;
 
                        if (dump_opt['b'] >= 2)
-                               sprintf_blkptr(blkbuf, bp);
+                               snprintf_blkptr(blkbuf, sizeof(blkbuf), bp);
                        else
                                blkbuf[0] = '\0';
 
@@ -1804,7 +1812,7 @@
        zcb->zcb_readfails = 0;
 
        if (dump_opt['b'] >= 4) {
-               sprintf_blkptr(blkbuf, bp);
+               snprintf_blkptr(blkbuf, sizeof(blkbuf), bp);
                (void) printf("objset %llu object %llu "
                    "level %lld offset 0x%llx %s\n",
                    (u_longlong_t)zb->zb_objset,
@@ -1978,7 +1986,7 @@
                while (bplist_iterate(bpl, &itor, &blk) == 0) {
                        if (dump_opt['b'] >= 4) {
                                char blkbuf[BP_SPRINTF_LEN];
-                               sprintf_blkptr(blkbuf, &blk);
+                               snprintf_blkptr(blkbuf, sizeof(blkbuf), &blk);
                                (void) printf("[%s] %s\n",
                                    "deferred free", blkbuf);
                        }
@@ -2303,7 +2311,7 @@
        if (flags & ZDB_FLAG_BSWAP)
                byteswap_uint64_array((void *)bp, sizeof (blkptr_t));
 
-       sprintf_blkptr(blkbuf, bp);
+       snprintf_blkptr(blkbuf, sizeof(blkbuf), bp);
        (void) printf("%s\n", blkbuf);
 }
 
diff -r bd426f2bf898 -r 9e093804f62d external/cddl/osnet/dist/cmd/ztest/ztest.c
--- a/external/cddl/osnet/dist/cmd/ztest/ztest.c        Thu Mar 27 10:42:47 2014 +0000
+++ b/external/cddl/osnet/dist/cmd/ztest/ztest.c        Thu Mar 27 15:50:48 2014 +0000
@@ -378,17 +378,21 @@
        va_list args;
        int save_errno = errno;
        char buf[FATAL_MSG_SZ];
+       size_t len, blklen = sizeof(buf);
 
        (void) fflush(stdout);
 
        va_start(args, message);
-       (void) sprintf(buf, "ztest: ");
+       len = snprintf(buf, blklen, "ztest: ");
+       if (len > blklen)
+               len = blklen;
        /* LINTED */
-       (void) vsprintf(buf + strlen(buf), message, args);
+       len += vsnprintf(buf + len, blklen - len, message, args);
        va_end(args);
+       if (len > blklen)
+               len = blklen;
        if (do_perror) {
-               (void) snprintf(buf + strlen(buf), FATAL_MSG_SZ - strlen(buf),
-                   ": %s", strerror(save_errno));
+               snprintf(buf + len, blklen - len, ": %s", strerror(save_errno));
        }
        (void) fprintf(stderr, "%s\n", buf);
        fatal_msg = buf;                        /* to ease debugging */
@@ -650,11 +654,11 @@
 
                if (aux != NULL) {
                        vdev = ztest_shared->zs_vdev_aux;
-                       (void) sprintf(path, ztest_aux_template,
+                       (void) snprintf(path, sizeof(pathbuf), ztest_aux_template,
                            zopt_dir, zopt_pool, aux, vdev);
                } else {
                        vdev = ztest_shared->zs_vdev_next_leaf++;
-                       (void) sprintf(path, ztest_dev_template,
+                       (void) snprintf(path, sizeof(pathbuf), ztest_dev_template,
                            zopt_dir, zopt_pool, vdev);
                }
        }
@@ -2235,7 +2239,7 @@
                for (;;) {
                        char path[MAXPATHLEN];
                        int c;
-                       (void) sprintf(path, ztest_aux_template, zopt_dir,
+                       (void) snprintf(path, sizeof(pathbuf), ztest_aux_template, zopt_dir,
                            zopt_pool, aux, zs->zs_vdev_aux);
                        for (c = 0; c < sav->sav_count; c++)
                                if (strcmp(sav->sav_vdevs[c]->vdev_path,
@@ -3760,8 +3764,8 @@
        ints = MAX(ZTEST_ZAP_MIN_INTS, object % ZTEST_ZAP_MAX_INTS);
 
        prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
-       (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
-       (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
+       (void) snprintf(propname, sizeof(propname), "prop_%llu", (u_longlong_t)prop);
+       (void) snprintf(txgname, sizeof(txgname), "txg_%llu", (u_longlong_t)prop);
        bzero(value, sizeof (value));
        last_txg = 0;
 
@@ -3822,8 +3826,8 @@
         * Remove a random pair of entries.
         */
        prop = ztest_random(ZTEST_ZAP_MAX_PROPS);
-       (void) sprintf(propname, "prop_%llu", (u_longlong_t)prop);
-       (void) sprintf(txgname, "txg_%llu", (u_longlong_t)prop);
+       (void) snprintf(propname, sizeof(propname), "prop_%llu", (u_longlong_t)prop);
+       (void) snprintf(txgname, sizeof(txgname), "txg_%llu", (u_longlong_t)prop);
 
        error = zap_length(os, object, txgname, &zl_intsize, &zl_ints);
 
@@ -4719,7 +4723,7 @@
        isalen = ztest - isa;
        isa = strdup(isa);
        /* LINTED */
-       (void) sprintf(bin,
+       (void) snprintf(bin, sizeof(zdb) - (bin - zdb),
            "/usr/sbin%.*s/zdb -bcc%s%s -U /tmp/zpool.cache %s",
            isalen,
            isa,
@@ -5292,7 +5296,7 @@
 }
 
 void
-print_time(hrtime_t t, char *timebuf)
+print_time(hrtime_t t, char *timebuf, size_t timelen)
 {
        hrtime_t s = t / NANOSEC;
        hrtime_t m = s / 60;
@@ -5306,14 +5310,14 @@
        timebuf[0] = '\0';
 
        if (d)
-               (void) sprintf(timebuf,
+               (void) snprintf(timebuf, timelen,
                    "%llud%02lluh%02llum%02llus", d, h, m, s);
        else if (h)
-               (void) sprintf(timebuf, "%lluh%02llum%02llus", h, m, s);
+               (void) snprintf(timebuf, timelen, "%lluh%02llum%02llus", h, m, s);
        else if (m)
-               (void) sprintf(timebuf, "%llum%02llus", m, s);
+               (void) snprintf(timebuf, timelen, "%llum%02llus", m, s);
        else
-               (void) sprintf(timebuf, "%llus", s);
+               (void) snprintf(timebuf, timelen, "%llus", s);
 }
 
 static nvlist_t *
@@ -5503,7 +5507,7 @@
                        hrtime_t now = gethrtime();
 
                        now = MIN(now, zs->zs_proc_stop);
-                       print_time(zs->zs_proc_stop - now, timebuf);
+                       print_time(zs->zs_proc_stop - now, timebuf, sizeof(timebuf));
                        nicenum(zs->zs_space, numbuf);
 
                        (void) printf("Pass %3d, %8s, %3llu ENOSPC, "
@@ -5527,7 +5531,7 @@
                                Dl_info dli;
 
                                zi = &zs->zs_info[f];
-                               print_time(zi->zi_call_time, timebuf);
+                               print_time(zi->zi_call_time, timebuf, sizeof(timebuf));
                                (void) dladdr((void *)zi->zi_func, &dli);
                                (void) printf("%7llu %9s   %s\n",
                                    (u_longlong_t)zi->zi_call_count, timebuf,
diff -r bd426f2bf898 -r 9e093804f62d external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c
--- a/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c    Thu Mar 27 10:42:47 2014 +0000
+++ b/external/cddl/osnet/dist/lib/libdtrace/arm/dt_isadep.c    Thu Mar 27 15:50:48 2014 +0000
@@ -167,7 +167,7 @@
                char name[sizeof (i) * 2 + 1];
 
                for (i = 0; i < symp->st_size; i += 4) {
-                       (void) sprintf(name, "%lx", i);



Home | Main Index | Thread Index | Old Index