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 --- src/argparser.c | 19 ++++++++++++------- src/test.c | 10 +++++----- 2 files changed, 17 insertions(+), 12 deletions(-) (limited to 'src') 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