Script size argument detection: argc should be greater than one,
rather than not equal to zero.

Output loop termination: the index variable should be compared against
the value of the size variable, as opposed to the default SCRIPT_SIZE
definition.

munmap: the mapping returned by mmap, addr, should be unmapped instead
of NULL.

Signed-off-by: Justin Swartz <justin.swa...@risingedge.co.za>
---
 script_extractor.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/script_extractor.c b/script_extractor.c
index 52d817f..bc67b7a 100644
--- a/script_extractor.c
+++ b/script_extractor.c
@@ -18,6 +18,7 @@
 #include <fcntl.h>
 #include <stdio.h>
 #include <stdlib.h>
+#include <unistd.h>
 #include <sys/mman.h>
 #include <sys/stat.h>
 #include <sys/types.h>
@@ -34,13 +35,13 @@ int main(int argc, char *argv[]) {
        fd = open("/dev/mem", O_RDONLY);
 
        size = SCRIPT_SIZE;
-       if (argc)
+       if (argc > 1)
                size = atoi(argv[1]);
 
        addr = (char *)mmap(NULL, size, PROT_READ, MAP_SHARED, fd, 
SCRIPT_START);
-       for (i = 0; i < SCRIPT_SIZE; i++)
+       for (i = 0; i < size; i++)
                putchar(addr[i]);
-       munmap(NULL, SCRIPT_SIZE);
+       munmap(addr, size);
        close(fd);
 
        return 0;
-- 
2.1.4

-- 
You received this message because you are subscribed to the Google Groups 
"linux-sunxi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to linux-sunxi+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to