From 958262e69d02abf1783f6fcad4ac0e79c03cb088 Mon Sep 17 00:00:00 2001 From: Kevin Lange Date: Tue, 27 Mar 2012 21:36:39 -0500 Subject: [PATCH] Fix argv[0] bug --- kernel/misc/elf.c | 2 +- userspace/argv-tester.c | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/kernel/misc/elf.c b/kernel/misc/elf.c index 1c599393..dedef148 100644 --- a/kernel/misc/elf.c +++ b/kernel/misc/elf.c @@ -112,7 +112,7 @@ exec( uintptr_t heap = current_process->image.entry + current_process->image.size; alloc_frame(get_page(heap, 1, current_directory), 0, 1); char ** argv_ = (char **)heap; - heap += sizeof(char *) * argc; + heap += sizeof(char *) * (argc + 1); for (int i = 0; i < argc; ++i) { alloc_frame(get_page(heap, 1, current_directory), 0, 1); argv_[i] = (char *)heap; diff --git a/userspace/argv-tester.c b/userspace/argv-tester.c index 08bf6d7f..6443b2a8 100644 --- a/userspace/argv-tester.c +++ b/userspace/argv-tester.c @@ -3,7 +3,7 @@ int main(int argc, char * argv[]) { printf("argc = %d\n", argc); for (int i = 0; i < argc; ++i) { - printf("argv[%d]= %s\n", i, argv[i]); + printf("%p argv[%d]= %s\n", argv[i], i, argv[i]); } printf("continuing until I hit a 0\n"); int i = argc;