summaryrefslogtreecommitdiff
path: root/tools/cws2fws.c
diff options
context:
space:
mode:
Diffstat (limited to 'tools/cws2fws.c')
-rw-r--r--tools/cws2fws.c16
1 files changed, 11 insertions, 5 deletions
diff --git a/tools/cws2fws.c b/tools/cws2fws.c
index 72980f4e2d..7046b69957 100644
--- a/tools/cws2fws.c
+++ b/tools/cws2fws.c
@@ -22,7 +22,7 @@
#ifdef DEBUG
#define dbgprintf printf
#else
-#define dbgprintf(...)
+#define dbgprintf(...) do { if (0) printf(__VA_ARGS__); } while (0)
#endif
int main(int argc, char *argv[])
@@ -61,7 +61,10 @@ int main(int argc, char *argv[])
goto out;
}
- fstat(fd_in, &statbuf);
+ if (fstat(fd_in, &statbuf) < 0) {
+ perror("fstat failed");
+ return 1;
+ }
comp_len = statbuf.st_size;
uncomp_len = buf_in[4] | (buf_in[5] << 8) | (buf_in[6] << 16) | (buf_in[7] << 24);
@@ -78,7 +81,10 @@ int main(int argc, char *argv[])
zstream.zalloc = NULL;
zstream.zfree = NULL;
zstream.opaque = NULL;
- inflateInit(&zstream);
+ if (inflateInit(&zstream) != Z_OK) {
+ fprintf(stderr, "inflateInit failed\n");
+ return 1;
+ }
for (i = 0; i < comp_len - 8;) {
int ret, len = read(fd_in, &buf_in, 1024);
@@ -125,8 +131,8 @@ int main(int argc, char *argv[])
buf_in[2] = ((zstream.total_out + 8) >> 16) & 0xff;
buf_in[3] = ((zstream.total_out + 8) >> 24) & 0xff;
- lseek(fd_out, 4, SEEK_SET);
- if (write(fd_out, &buf_in, 4) < 4) {
+ if ( lseek(fd_out, 4, SEEK_SET) < 0
+ || write(fd_out, &buf_in, 4) < 4) {
perror("Error writing output file");
inflateEnd(&zstream);
goto out;