diff options
author | Douglas Gilbert <dgilbert@interlog.com> | 2019-09-17 21:53:05 +0000 |
---|---|---|
committer | Douglas Gilbert <dgilbert@interlog.com> | 2019-09-17 21:53:05 +0000 |
commit | bcdf18e4dd92f592617c35edbc9ffbb2817bd36c (patch) | |
tree | d408e019b135df92eb3f6860333865b9c9064b5c /src | |
parent | eaa9d929aba1cc812418582c779731bcde2adf68 (diff) | |
download | sg3_utils-bcdf18e4dd92f592617c35edbc9ffbb2817bd36c.tar.gz |
sync with fixes from Redhat, via github; remove testing/Makefile.cplus and testing/Makefile.cplus_fb
git-svn-id: https://svn.bingwo.ca/repos/sg3_utils/trunk@832 6180dd3e-e324-4e3e-922d-17de1ae2f315
Diffstat (limited to 'src')
-rw-r--r-- | src/sg_dd.c | 22 | ||||
-rw-r--r-- | src/sg_format.c | 12 | ||||
-rw-r--r-- | src/sg_get_lba_status.c | 4 | ||||
-rw-r--r-- | src/sg_inq.c | 3 | ||||
-rw-r--r-- | src/sg_logs.c | 4 | ||||
-rw-r--r-- | src/sg_luns.c | 7 | ||||
-rw-r--r-- | src/sg_opcodes.c | 3 | ||||
-rw-r--r-- | src/sg_persist.c | 6 | ||||
-rw-r--r-- | src/sg_rbuf.c | 6 | ||||
-rw-r--r-- | src/sg_sanitize.c | 11 | ||||
-rw-r--r-- | src/sg_ses.c | 25 | ||||
-rw-r--r-- | src/sg_test_rwbuf.c | 8 | ||||
-rw-r--r-- | src/sg_vpd.c | 83 | ||||
-rw-r--r-- | src/sg_vpd_vendor.c | 2 | ||||
-rw-r--r-- | src/sg_write_x.c | 18 | ||||
-rw-r--r-- | src/sginfo.c | 9 |
16 files changed, 104 insertions, 119 deletions
diff --git a/src/sg_dd.c b/src/sg_dd.c index 01588669..06d96610 100644 --- a/src/sg_dd.c +++ b/src/sg_dd.c @@ -982,7 +982,7 @@ err_out: } return may_coe ? 0 : ret; } else - return ret ? ret : -1; + return ret; } @@ -1230,7 +1230,8 @@ static int open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, int * in_typep, int vb) { - int infd, flags, fl, t, res; + int infd = -1; + int flags, fl, t, res; char ebuff[EBUFF_SZ]; struct sg_simple_inquiry_resp sir; @@ -1332,7 +1333,7 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, #endif } } - if (ifp->flock) { + if (ifp->flock && (infd >= 0)) { res = flock(infd, LOCK_EX | LOCK_NB); if (res < 0) { close(infd); @@ -1345,8 +1346,12 @@ open_if(const char * inf, int64_t skip, int bpt, struct flags_t * ifp, return infd; file_err: + if (infd >= 0) + close(infd); return -SG_LIB_FILE_ERROR; other_err: + if (infd >= 0) + close(infd); return -SG_LIB_CAT_OTHER; } @@ -1358,7 +1363,8 @@ static int open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, int * out_typep, int vb) { - int outfd, flags, t, res; + int outfd = -1; + int flags, t, res; char ebuff[EBUFF_SZ]; struct sg_simple_inquiry_resp sir; @@ -1460,21 +1466,25 @@ open_of(const char * outf, int64_t seek, int bpt, struct flags_t * ofp, "\n", (uint64_t)offset); } } - if (ofp->flock) { + if (ofp->flock && (outfd >= 0)) { res = flock(outfd, LOCK_EX | LOCK_NB); if (res < 0) { - close(outfd); snprintf(ebuff, EBUFF_SZ, ME "flock(LOCK_EX | LOCK_NB) on %s " "failed", outf); perror(ebuff); + close(outfd); return -SG_LIB_FLOCK_ERR; } } return outfd; file_err: + if (outfd >= 0) + close(outfd); return -SG_LIB_FILE_ERROR; other_err: + if (outfd >= 0) + close(outfd); return -SG_LIB_CAT_OTHER; } diff --git a/src/sg_format.c b/src/sg_format.c index 12fa78d1..9b29caf9 100644 --- a/src/sg_format.c +++ b/src/sg_format.c @@ -40,7 +40,7 @@ #include "sg_pr2serr.h" #include "sg_pt.h" -static const char * version_str = "1.58 20190113"; +static const char * version_str = "1.59 20190913"; #define RW_ERROR_RECOVERY_PAGE 1 /* can give alternate with --mode=MP */ @@ -706,15 +706,9 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, if (n > (SAFE_STD_INQ_RESP_LEN - 4)) n = (SAFE_STD_INQ_RESP_LEN - 4); for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) { - if (VPD_UNIT_SERIAL_NUM == b[4 + k]) { - if (has_di) { - if (op->verbose) - pr2serr("VPD_SUPPORTED_VPDS " - "dis-ordered\n"); - goto out; - } + if (VPD_UNIT_SERIAL_NUM == b[4 + k]) ++has_sn; - } else if (VPD_DEVICE_ID == b[4 + k]) { + else if (VPD_DEVICE_ID == b[4 + k]) { ++has_di; break; } diff --git a/src/sg_get_lba_status.c b/src/sg_get_lba_status.c index 1b9df4de..4feac63b 100644 --- a/src/sg_get_lba_status.c +++ b/src/sg_get_lba_status.c @@ -35,7 +35,7 @@ * device. */ -static const char * version_str = "1.20 20190822"; /* sbc4r15 */ +static const char * version_str = "1.21 20190913"; /* sbc4r15 */ #ifndef UINT32_MAX #define UINT32_MAX ((uint32_t)-1) @@ -391,7 +391,7 @@ main(int argc, char * argv[]) res = sg_ll_get_lba_status16(sg_fd, lba, rt, glbasBuffp, maxlen, true, verbose); else if (do_32) /* keep analyser happy since do_32 must be true */ - res = sg_ll_get_lba_status32(sg_fd, lba, element_id, scan_len, rt, + res = sg_ll_get_lba_status32(sg_fd, lba, scan_len, element_id, rt, glbasBuffp, maxlen, true, verbose); ret = res; diff --git a/src/sg_inq.c b/src/sg_inq.c index 5ee6792f..f1df8085 100644 --- a/src/sg_inq.c +++ b/src/sg_inq.c @@ -51,7 +51,7 @@ #include "sg_pt_nvme.h" #endif -static const char * version_str = "2.02 20190815"; /* SPC-5 rev 22 */ +static const char * version_str = "2.03 20190913"; /* SPC-5 rev 22 */ /* INQUIRY notes: * It is recommended that the initial allocation length given to a @@ -3246,7 +3246,6 @@ cmddt_process(int sg_fd, const struct opts_t * op) break; case 6: desc_p = "vendor specific (6)"; break; case 7: desc_p = "reserved (7)"; break; - default: desc_p = "impossible value > 7"; break; } if (prnt_cmd) { printf(" Support field: %s [", desc_p); diff --git a/src/sg_logs.c b/src/sg_logs.c index e11e8523..c23a62e5 100644 --- a/src/sg_logs.c +++ b/src/sg_logs.c @@ -36,7 +36,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.77 20190822"; /* spc5r22 + sbc4r17 */ +static const char * version_str = "1.78 20190913"; /* spc5r22 + sbc4r17 */ #define MX_ALLOC_LEN (0xfffc) #define SHORT_RESP_LEN 128 @@ -6980,7 +6980,7 @@ main(int argc, char * argv[]) if (k) { if (SG_LIB_CAT_NOT_READY == k) pr2serr("log_select: device not ready\n"); - else if (SG_LIB_CAT_ILLEGAL_REQ == res) + else if (SG_LIB_CAT_ILLEGAL_REQ == k) pr2serr("log_select: field in cdb illegal\n"); else if (SG_LIB_CAT_INVALID_OP == k) pr2serr("log_select: not supported\n"); diff --git a/src/sg_luns.c b/src/sg_luns.c index d1a5030e..555e14d6 100644 --- a/src/sg_luns.c +++ b/src/sg_luns.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2004-2018 Douglas Gilbert. + * Copyright (c) 2004-2019 Douglas Gilbert. * All rights reserved. * Use of this source code is governed by a BSD-style * license that can be found in the BSD_LICENSE file. @@ -34,7 +34,7 @@ * and decodes the response. */ -static const char * version_str = "1.42 20180626"; +static const char * version_str = "1.43 20190913"; #define MAX_RLUNS_BUFF_LEN (1024 * 1024) #define DEF_RLUNS_BUFF_LEN (1024 * 8) @@ -308,9 +308,6 @@ decode_lun(const char * leadin, const uint8_t * lunp, bool lu_cong, } } break; - default: - printf("%s<<%s: faulty logic>>\n", l_leadin, __func__); - break; } if (next_level) continue; diff --git a/src/sg_opcodes.c b/src/sg_opcodes.c index 52032cd1..f80b79da 100644 --- a/src/sg_opcodes.c +++ b/src/sg_opcodes.c @@ -800,7 +800,8 @@ list_all_codes(uint8_t * rsoc_buff, int rsoc_len, struct opts_t * op, printf(" usage: "); else printf(" cdb usage: "); - for (m = 0; m < cdb_sz; ++m) + for (m = 0; (m < cdb_sz) && ((4 + m) < (int)sizeof(b)); + ++m) printf("%.2x ", b[4 + m]); printf("\n"); } diff --git a/src/sg_persist.c b/src/sg_persist.c index c1324c43..59067f2a 100644 --- a/src/sg_persist.c +++ b/src/sg_persist.c @@ -1,5 +1,5 @@ /* A utility program originally written for the Linux OS SCSI subsystem. - * Copyright (C) 2004-2018 D. Gilbert + * Copyright (C) 2004-2019 D. Gilbert * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -35,7 +35,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "0.66 20180615"; +static const char * version_str = "0.67 20190913"; #define PRIN_RKEY_SA 0x0 @@ -826,7 +826,7 @@ decode_file_tids(const char * fnp, struct opts_t * op) pr2serr("%s: array length exceeded\n", __func__); goto bad; } - tid_arr[off + k] = h; + op->transportid_arr[off + k] = h; /* keep code checker happy */ lcp = strpbrk(lcp, " ,\t"); if (NULL == lcp) break; diff --git a/src/sg_rbuf.c b/src/sg_rbuf.c index 9f5055e8..2f5229f0 100644 --- a/src/sg_rbuf.c +++ b/src/sg_rbuf.c @@ -1,5 +1,5 @@ /* A utility program originally written for the Linux OS SCSI subsystem. - * Copyright (C) 1999-2018 D. Gilbert + * Copyright (C) 1999-2019 D. Gilbert * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2, or (at your option) @@ -57,7 +57,7 @@ #endif -static const char * version_str = "5.05 20180627"; +static const char * version_str = "5.06 20190913"; static struct option long_options[] = { {"buffer", required_argument, 0, 'b'}, @@ -683,5 +683,5 @@ main(int argc, char * argv[]) else printf("read buffer non-zero\n"); #endif - return (res >= 0) ? res : SG_LIB_CAT_OTHER; + return res; } diff --git a/src/sg_sanitize.c b/src/sg_sanitize.c index 9fc348c8..b4a10682 100644 --- a/src/sg_sanitize.c +++ b/src/sg_sanitize.c @@ -33,7 +33,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.12 20190113"; +static const char * version_str = "1.13 20190913"; /* Not all environments support the Unix sleep() */ #if defined(MSC_VER) || defined(__MINGW32__) @@ -389,14 +389,9 @@ print_dev_id(int fd, uint8_t * sinq_resp, int max_rlen, int verbose) if (n > (SAFE_STD_INQ_RESP_LEN - 4)) n = (SAFE_STD_INQ_RESP_LEN - 4); for (k = 0, has_sn = 0, has_di = 0; k < n; ++k) { - if (VPD_UNIT_SERIAL_NUM == b[4 + k]) { - if (has_di) { - if (verbose) - pr2serr("VPD_SUPPORTED_VPDS dis-ordered\n"); - return 0; - } + if (VPD_UNIT_SERIAL_NUM == b[4 + k]) ++has_sn; - } else if (VPD_DEVICE_ID == b[4 + k]) { + else if (VPD_DEVICE_ID == b[4 + k]) { ++has_di; break; } diff --git a/src/sg_ses.c b/src/sg_ses.c index 2325b8b4..cc24c13e 100644 --- a/src/sg_ses.c +++ b/src/sg_ses.c @@ -38,7 +38,7 @@ * commands tailored for SES (enclosure) devices. */ -static const char * version_str = "2.46 20190826"; /* ses4r03 */ +static const char * version_str = "2.47 20190913"; /* ses4r03 */ #define MX_ALLOC_LEN ((64 * 1024) - 4) /* max allowable for big enclosures */ #define MX_ELEM_HDR 1024 @@ -1425,15 +1425,12 @@ parse_cmd_line(struct opts_t *op, int argc, char *argv[]) break; } } - if (n > 1) - op->many_dpages = true; - else if (1 == n) { + if (1 == n) { op->page_code_given = true; op->page_code = pc; - } else { - pr2serr("No dpage found --data= argument\n"); - goto err_help; - } + } else /* n must be > 1 */ + op->many_dpages = true; + if (op->verbose > 3) { int k; char b[128]; @@ -2454,9 +2451,6 @@ find_sas_connector_type(int conn_type, bool abridged, char * buff, else if (conn_type < 0x20) snprintf(buff, buff_len, "unknown internal wide connector type: " "0x%x", conn_type); - else if (conn_type < 0x30) - snprintf(buff, buff_len, "unknown internal connector to end " - "device, type: 0x%x", conn_type); else if (conn_type < 0x3f) snprintf(buff, buff_len, "reserved for internal connector, " "type: 0x%x", conn_type); @@ -2660,8 +2654,6 @@ enc_status_helper(const char * pad, const uint8_t * statp, int etype, printf("%slast 3 bytes (hex): %02x %02x %02x\n", pad, statp[1], statp[2], statp[3]); break; - default: - break; } break; case UI_POWER_SUPPLY_ETC: /* Uninterruptible power supply */ @@ -4286,8 +4278,7 @@ process_status_dpage(struct sg_pt_base * ptvp, int page_code, uint8_t * resp, subenc_nickname_sdg(resp, resp_len); break; default: - printf("Cannot decode response from diagnostic " - "page: %s\n", (cp ? cp : "<unknown>")); + printf("Cannot decode response from diagnostic page: %s\n", cp); hex2stdout(resp, resp_len, 0); } @@ -5336,7 +5327,7 @@ ses_cgs(struct sg_pt_base * ptvp, const struct tuple_acronym_val * tavp, if (op->ind_indiv_last <= op->ind_indiv) break; } /* end of loop over join array */ - if ((NULL == jrp->enc_statp) || (k >= MX_JOIN_ROWS)) { + if ((k >= MX_JOIN_ROWS || (NULL == jrp->enc_statp))) { if (op->desc_name) pr2serr("descriptor name: %s not found (check the 'ed' page " "[0x7])\n", op->desc_name); @@ -5907,7 +5898,7 @@ early_out: pr2serr("Some error occurred, try again with '-v' or '-vv' for " "more information\n"); else if ((SG_LIB_SYNTAX_ERROR == ret) && (0 == vb)) - pr2serr("Add '-h' to command line for usage infomation\n"); + pr2serr("Add '-h' to command line for usage information\n"); } if (op->free_data_arr) free(op->free_data_arr); diff --git a/src/sg_test_rwbuf.c b/src/sg_test_rwbuf.c index 8eb604b0..86d85ca1 100644 --- a/src/sg_test_rwbuf.c +++ b/src/sg_test_rwbuf.c @@ -1,7 +1,7 @@ /* * (c) 2000 Kurt Garloff <garloff at suse dot de> * heavily based on Douglas Gilbert's sg_rbuf program. - * (c) 1999-2018 Douglas Gilbert + * (c) 1999-2019 Douglas Gilbert * * Program to test the SCSI host adapter by issuing * write and read operations on a device's buffer @@ -47,7 +47,7 @@ #include "sg_pr2serr.h" -static const char * version_str = "1.18 20180628"; +static const char * version_str = "1.19 20190913"; #define BPI (signed)(sizeof(int)) @@ -388,8 +388,8 @@ void usage () int main (int argc, char * argv[]) { - bool verbose_given = true; - bool version_given = true; + bool verbose_given = false; + bool version_given = false; int sg_fd, res; const char * device_name = NULL; int times = 1; diff --git a/src/sg_vpd.c b/src/sg_vpd.c index 6e4b21e8..3fdcca84 100644 --- a/src/sg_vpd.c +++ b/src/sg_vpd.c @@ -40,7 +40,7 @@ */ -static const char * version_str = "1.54 20190516"; /* spc5r22 + sbc4r17 */ +static const char * version_str = "1.55 20190913"; /* spc5r22 + sbc4r17 */ /* standard VPD pages, in ascending page number order */ #define VPD_SUPPORTED_VPDS 0x0 @@ -1047,9 +1047,6 @@ decode_x_inq_vpd(uint8_t * b, int len, int do_hex, bool do_long, case 7: printf(" [protection types 1, 2 and 3 supported]\n"); break; - default: - printf("\n"); - break; } } else printf("\n"); @@ -1775,10 +1772,18 @@ decode_3party_copy_vpd(uint8_t * buff, int len, int do_hex, int pdt, printf(" Maximum identified concurrent copies: %u\n", u); u = sg_get_unaligned_be32(bp + 12); printf(" Maximum segment length: %u\n", u); - ull = (1 << bp[16]); /* field is power of 2 */ - printf(" Data segment granularity: %" PRIu64 "\n", ull); - ull = (1 << bp[17]); - printf(" Inline data granularity: %" PRIu64 "\n", ull); + printf(" Data segment granularity: "); + u = bp[16]; /* field is power of 2 */ + if (u < 64) + printf("%" PRIu64 "\n", (uint64_t)1 << u); + else + printf("too large [2^%u]\n", u); + printf(" Inline data granularity: "); + u = bp[17]; /* field is power of 2 */ + if (u < 64) + printf("%" PRIu64 "\n", (uint64_t)1 << u); + else + printf("too large [2^%u]\n", u); break; case 0x9101: printf(" Stream copy operations:\n"); @@ -1832,21 +1837,19 @@ decode_proto_lu_vpd(uint8_t * buff, int len, int do_hex) } if (0 == desc_len) continue; - if (2 == do_hex) + if (2 == do_hex) { hex2stdout(bp + 8, desc_len, 1); - else if (do_hex > 2) - hex2stdout(bp, bump, 1); - else { - switch (proto) { - case TPROTO_SAS: - printf(" Protocol identifier: SAS\n"); - printf(" TLR control supported: %d\n", !!(bp[8] & 0x1)); - break; - default: - pr2serr("Unexpected proto=%d\n", proto); - hex2stderr(bp, bump, 1); - break; - } + continue; + } + switch (proto) { + case TPROTO_SAS: + printf(" Protocol identifier: SAS\n"); + printf(" TLR control supported: %d\n", !!(bp[8] & 0x1)); + break; + default: + pr2serr("Unexpected proto=%d\n", proto); + hex2stderr(bp, bump, 1); + break; } } } @@ -1883,25 +1886,23 @@ decode_proto_port_vpd(uint8_t * buff, int len, int do_hex) } if (0 == desc_len) continue; - if (2 == do_hex) + if (2 == do_hex) { hex2stdout(bp + 8, desc_len, 1); - else if (do_hex > 2) - hex2stdout(bp, bump, 1); - else { - switch (proto) { - case TPROTO_SAS: /* page added in spl3r02 */ - printf(" power disable supported (pwr_d_s)=%d\n", - !!(bp[3] & 0x1)); /* added spl3r03 */ - pidp = bp + 8; - for (j = 0; j < desc_len; j += 4, pidp += 4) - printf(" phy id=%d, SSP persistent capable=%d\n", - pidp[1], (0x1 & pidp[2])); - break; - default: - pr2serr("Unexpected proto=%d\n", proto); - hex2stderr(bp, bump, 1); - break; - } + continue; + } + switch (proto) { + case TPROTO_SAS: /* page added in spl3r02 */ + printf(" power disable supported (pwr_d_s)=%d\n", + !!(bp[3] & 0x1)); /* added spl3r03 */ + pidp = bp + 8; + for (j = 0; j < desc_len; j += 4, pidp += 4) + printf(" phy id=%d, SSP persistent capable=%d\n", + pidp[1], (0x1 & pidp[2])); + break; + default: + pr2serr("Unexpected proto=%d\n", proto); + hex2stderr(bp, bump, 1); + break; } } } @@ -2740,7 +2741,7 @@ svpd_decode_t10(int sg_fd, struct opts_t * op, int subvalue, int off, dStrRaw(rp, alloc_len); else if (op->do_hex) { if (! op->do_quiet && (op->do_hex < 3)) - printf("Standard Inquiry reponse:\n"); + printf("Standard Inquiry response:\n"); hex2stdout(rp, alloc_len, (1 == op->do_hex) ? 0 : -1); } else std_inq_decode(rp, alloc_len, vb); diff --git a/src/sg_vpd_vendor.c b/src/sg_vpd_vendor.c index 66be0729..32fc3494 100644 --- a/src/sg_vpd_vendor.c +++ b/src/sg_vpd_vendor.c @@ -1431,7 +1431,7 @@ svpd_decode_vendor(int sg_fd, struct opts_t * op, int off) if (0 == res) { vnp = svpd_get_v_detail(op->vpd_pn, op->vend_prod_num, 0xf & rp[0]); if (vnp && vnp->name) - strcpy(name, vnp->name); + snprintf(name, sizeof(name), "%s", vnp->name); else snprintf(name, sizeof(name) - 1, "Vendor VPD page=0x%x", op->vpd_pn); diff --git a/src/sg_write_x.c b/src/sg_write_x.c index c610fa00..fca94377 100644 --- a/src/sg_write_x.c +++ b/src/sg_write_x.c @@ -38,7 +38,7 @@ #include "sg_unaligned.h" #include "sg_pr2serr.h" -static const char * version_str = "1.20 20190113"; +static const char * version_str = "1.21 20190913"; /* Protection Information refers to 8 bytes of extra information usually * associated with each logical block and is often abbreviated to PI while @@ -673,8 +673,10 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) if (cp) { /* copy from first non whitespace ... */ memcpy(c, lcp, cp - lcp); /* ... to just prior to first '#' */ c[cp - lcp] = '\0'; - } else - strcpy(c, lcp); /* ... to end of line, including null */ + } else { + /* ... to end of line, including null */ + snprintf(c, sizeof(c), "%s", lcp); + } ll = sg_get_llnum(bp); ok = ((-1 != ll) || all_ascii_f_s(bp, 16)); if (! ok) { @@ -750,10 +752,6 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) } else if (up) sg_put_unaligned_be16((uint16_t)ll, up + 18); break; - default: - pr2serr("%s: k=%d should not be >= 3\n", __func__, k); - ok = false; - break; } if (! ok) break; @@ -774,13 +772,9 @@ parse_scat_pi_line(const char * lcp, uint8_t * up, uint32_t * sum_num) if (up) sg_put_unaligned_be16((uint16_t)DEF_TM, up + 18); break; - default: - pr2serr("%s: k=%d should not be >= 3\n", __func__, k); - ok = false; - break; } } - return ok ? 0 : SG_LIB_SYNTAX_ERROR; + return 0; } /* Read pairs or quintets from a scat_file and places them in a T10 scatter diff --git a/src/sginfo.c b/src/sginfo.c index 6a514fc1..3529d1fd 100644 --- a/src/sginfo.c +++ b/src/sginfo.c @@ -124,7 +124,7 @@ #define _GNU_SOURCE 1 #endif -static const char * version_str = "2.42 [20180811]"; +static const char * version_str = "2.43 [20190913]"; #include <stdio.h> #include <string.h> @@ -1514,12 +1514,11 @@ read_defect_list(int grown_only) if (defectformat == HEAD_SORT_TOKEN) { defectformat = 0x04; sorthead = 1; - headsp = (unsigned int *)malloc(sizeof(unsigned int) * MAX_HEADS); + headsp = (unsigned int *)calloc(MAX_HEADS, sizeof(unsigned int)); if (headsp == NULL) { perror("malloc failed"); return status; } - memset(headsp,0,sizeof(unsigned int) * MAX_HEADS); } for (table = grown_only; table < 2; table++) { if (heapp) { @@ -1759,6 +1758,7 @@ trytenbyte: } else if (!sorthead) printf("|"); } + break; case 5: /* physical sector */ while (len > 0) { snprintf((char *)cbuffer1, 40, "%6d:%2u:%5d", @@ -1777,6 +1777,7 @@ trytenbyte: } else if (!sorthead) printf("|"); } + break; case 0: /* lba (32 bit) */ while (len > 0) { printf("%10d", getnbyte(df, 4)); @@ -1790,6 +1791,7 @@ trytenbyte: else printf("|"); } + break; case 3: /* lba (64 bit) */ while (len > 0) { printf("%15" PRId64 , getnbyte_ll(df, 8)); @@ -1825,6 +1827,7 @@ trytenbyte: printf("%3d: %u\n", i, headsp[i]); } } + free(headsp); } printf("\n"); return status; |