From 0eeeb016b7c059eb1d77b015b7486a96b544df9f Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Tue, 2 Jul 2013 14:36:37 +0200 Subject: misc fix MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- Makefile | 4 ++-- src/argparser.c | 19 ++++++++++++------- src/test.c | 10 +++++----- 3 files changed, 19 insertions(+), 14 deletions(-) diff --git a/Makefile b/Makefile index a34111e..5193ce1 100644 --- a/Makefile +++ b/Makefile @@ -3,8 +3,8 @@ JAVA_OPTIMISE = -O all: @mkdir -p bin - $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -fPIC -shared src/argparser.c -o bin/argparser.so - $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -c src/argparser.c -o bin/argparser.o + $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -fPIC -c src/argparser.c -o bin/argparser.o + $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic -shared bin/argparser.o -o bin/argparser.so $(CC) $(C_OPTIMISE) -std=gnu99 -Wall -Wextra -pedantic src/test.c bin/argparser.o -o bin/test javac $(JAVA_OPTIMISE) -cp src -s src -d bin src/argparser/ArgParser.java javac $(JAVA_OPTIMISE) -cp src -s src -d bin src/Test.java diff --git a/src/argparser.c b/src/argparser.c index 427a4b7..13ab1b7 100644 --- a/src/argparser.c +++ b/src/argparser.c @@ -205,7 +205,7 @@ args_Option args_new_argumentless(int standard, char* alternatives, ...) va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -243,7 +243,7 @@ args_Option args_new_argumented(char* argument, int standard, char* alternatives va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -281,7 +281,7 @@ args_Option args_new_variadic(char* argument, int standard, char* alternatives, va_copy(cp, args); /* va_copy(dest, src) */ va_start(cp, alternatives); - while (va_arg(args, char*) != null) + while (va_arg(cp, char*) != null) count++; va_end(cp); @@ -693,6 +693,7 @@ char* args_parent_name(long levels) data = (char*)malloc(2048 * sizeof(char)); while (lvl > 0) { + long found = false; i = 0; for (j = 0; *("/proc/" + j); j++) *(buf + i++) = *("/proc/" + j); for (j = 0; *(pid + j); j++) *(buf + i++) = *(pid + j); @@ -726,15 +727,19 @@ char* args_parent_name(long levels) *(pid + i) = *(buf + off + i); *(pid + j) = 0; lvl--; + found = true; break; } j = 0; } - if (j < 35) - *(buf + j) = c; + else if (j < 35) + *(buf + j++) = c; + } + if (found == false) + { + free(data); + return null; } - free(data); - return null; } free(data); i = 0; diff --git a/src/test.c b/src/test.c index 9f85185..3f5f9a0 100644 --- a/src/test.c +++ b/src/test.c @@ -43,12 +43,12 @@ int main(int argc, char** argv) "You should have received a copy of the GNU General Public License\n" "along with this library. If not, see .", 0, 1); - args_add_option(args_new_argumentless(0, "-h", "-?", "--help"), "Prints this help message\n(and exits)"); - args_add_option(args_new_argumentless(0, "--hello"), "Prints the text: hello world'"); - args_add_option(args_new_argumentless(0, "++hidden"), 0); + args_add_option(args_new_argumentless(0, "-h", "-?", "--help", NULL), "Prints this help message\n(and exits)"); + args_add_option(args_new_argumentless(0, "--hello", NULL), "Prints the text: hello world'"); + args_add_option(args_new_argumentless(0, "++hidden", NULL), 0); - args_add_option(args_new_argumented("LINE", 0, "-l", "--line"), "Prints the choosen line"); - args_add_option(args_new_variadic("LINE", 0, "--l", "--lines"), "Prints the choosen lines"); + args_add_option(args_new_argumented("LINE", 0, "-l", "--line", NULL), "Prints the choosen line"); + args_add_option(args_new_variadic("LINE", 0, "--l", "--lines", NULL), "Prints the choosen lines"); args_parse(argc, argv); args_support_alternatives(); -- cgit v1.2.3-70-g09d2