]> git.sur5r.net Git - u-boot/blobdiff - tools/mkenvimage.c
Merge branch 'master' of git://git.denx.de/u-boot-sunxi
[u-boot] / tools / mkenvimage.c
index 8eee72e2572e321bbcf70d516d884708724f7fa4..75967d0c2d59667da31ada29bc3d7abb3e3b5acc 100644 (file)
@@ -1,3 +1,4 @@
+// SPDX-License-Identifier: GPL-2.0+
 /*
  * (C) Copyright 2011 Free Electrons
  * David Wagner <david.wagner@free-electrons.com>
@@ -5,8 +6,6 @@
  * Inspired from envcrc.c:
  * (C) Copyright 2001
  * Paolo Scaffardi, AIRVENT SAM s.p.a - RIMINI(ITALY), arsenio@tin.it
- *
- * SPDX-License-Identifier:    GPL-2.0+
  */
 
 #include <errno.h>
@@ -162,13 +161,13 @@ int main(int argc, char **argv)
                txt_fd = STDIN_FILENO;
 
                do {
-                       filebuf = realloc(filebuf, readlen);
+                       filebuf = realloc(filebuf, filesize + readlen);
                        if (!filebuf) {
                                fprintf(stderr, "Can't realloc memory for the input file buffer\n");
                                return EXIT_FAILURE;
                        }
                        readbytes = read(txt_fd, filebuf + filesize, readlen);
-                       if (errno) {
+                       if (readbytes < 0) {
                                fprintf(stderr, "Error while reading stdin: %s\n",
                                                strerror(errno));
                                return EXIT_FAILURE;