diff options
author | Sascha Hauer <s.hauer@pengutronix.de> | 2008-11-10 17:52:14 +0100 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2008-11-10 17:52:14 +0100 |
commit | dfefaf57443d4e6ca2ffcc42ede5f06ffa5676e6 (patch) | |
tree | 5f737bd6e19cdcd62e2d9c6336614ada1219bc35 /commands/crc.c | |
parent | 54ec87f0cb60c456e276001022131f358fcd1370 (diff) | |
download | barebox-dfefaf57443d4e6ca2ffcc42ede5f06ffa5676e6.tar.gz barebox-dfefaf57443d4e6ca2ffcc42ede5f06ffa5676e6.tar.xz |
CRC: various fixes
- bail out on read errors
- test for -1 instead of < 0 for lseek
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'commands/crc.c')
-rw-r--r-- | commands/crc.c | 13 |
1 files changed, 9 insertions, 4 deletions
diff --git a/commands/crc.c b/commands/crc.c index 979d3b28a4..008cbb845f 100644 --- a/commands/crc.c +++ b/commands/crc.c @@ -32,11 +32,11 @@ static int do_crc (cmd_tbl_t *cmdtp, int argc, char *argv[]) { - ulong start = 0, size = ~0, total = 0, now; + ulong start = 0, size = ~0, total = 0; ulong crc = 0, vcrc = 0; char *filename = "/dev/mem"; char *buf; - int fd, opt, err = 0, filegiven = 0, verify = 0; + int fd, opt, err = 0, filegiven = 0, verify = 0, now; getopt_reset(); @@ -71,8 +71,8 @@ static int do_crc (cmd_tbl_t *cmdtp, int argc, char *argv[]) return 1; } - if (lseek(fd, start, SEEK_SET) < 0) { - printf("file is smaller than start address\n"); + if (lseek(fd, start, SEEK_SET) == -1) { + perror("lseek"); err = 1; goto out; } @@ -82,6 +82,10 @@ static int do_crc (cmd_tbl_t *cmdtp, int argc, char *argv[]) while (size) { now = min((ulong)4096, size); now = read(fd, buf, now); + if (now < 0) { + perror("read"); + goto out_free; + } if (!now) break; crc = crc32(crc, buf, now); @@ -99,6 +103,7 @@ static int do_crc (cmd_tbl_t *cmdtp, int argc, char *argv[]) printf("\n"); +out_free: free(buf); out: close(fd); |