Skip to content

Commit

Permalink
test: fix append_argv()
Browse files Browse the repository at this point in the history
When I ran "CAIRO_TESTS=a1-bug make test", no test executed because of a
bug in append_argv(). The "olen" variable was assuming that we always
only append a single argument to argv and the resulting argc was also
wrong.

Signed-off-by: Paulo Zanoni <paulo.r.zanoni@intel.com>
Signed-off-by: Chris Wilson <chris@chris-wilson.co.uk>
  • Loading branch information
Paulo Zanoni authored and Chris Wilson committed Sep 9, 2011
1 parent 166be70 commit 669242c
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions test/cairo-test-runner.c
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@ append_argv (int *argc, char ***argv, const char *str)
int olen;
int len;
int i;
int args_to_add = 0;

if (str == NULL)
return;
Expand All @@ -290,9 +291,9 @@ append_argv (int *argc, char ***argv, const char *str)
doit = FALSE;
do {
if (doit)
*argv = xmalloc (sizeof (char *) * (1 + *argc) + olen);
*argv = xmalloc (olen);

olen = sizeof (char *) * (1 + *argc);
olen = sizeof (char *) * (args_to_add + *argc);
for (i = 0; i < old_argc; i++) {
len = strlen (old_argv[i]) + 1;
if (doit) {
Expand All @@ -310,7 +311,10 @@ append_argv (int *argc, char ***argv, const char *str)
(*argv)[i] = (char *) *argv + olen;
memcpy ((*argv)[i], s, len);
(*argv)[i][len] = '\0';
} else {
olen += sizeof (char *);
}
args_to_add++;
olen += len + 1;
i++;
}
Expand All @@ -321,13 +325,15 @@ append_argv (int *argc, char ***argv, const char *str)
if (doit) {
(*argv)[i] = (char *) *argv + olen;
memcpy ((*argv)[i], s, len);
} else {
olen += sizeof (char *);
}
args_to_add++;
olen += len;
i++;
}
} while (doit++ == FALSE);
(*argv)[i] = NULL;
*argc += i;
*argc = i;
}

static void
Expand Down

0 comments on commit 669242c

Please sign in to comment.