diff --git a/cairo/test/Makefile.am b/cairo/test/Makefile.am
index 9b673d2..e127f53 100644
--- a/cairo/test/Makefile.am
+++ b/cairo/test/Makefile.am
@@ -1706,17 +1706,22 @@ recheck:
 	@$(MAKE) $(AM_MAKEFLAGS) $(recheck)
 
 # Checks tests and creates index.html.
-# Target doesn't fail if tests fail.
 test:
-	@$(MAKE) $(AM_MAKEFLAGS) check; \
-	$(MAKE) $(AM_MAKEFLAGS) html
+	@if $(MAKE) $(AM_MAKEFLAGS) check; then \
+	  res=true; \
+	else \
+	  res=false; \
+	fi; \
+	$(MAKE) $(AM_MAKEFLAGS) html && $$res
 
 # Re-checks tests and creates index.html.
-# Target doesn't fail if tests fail.
 retest:
-	@CAIRO_TESTS="$(FAILED_TESTS)"; \
-	$(MAKE) $(AM_MAKEFLAGS) check; \
-	$(MAKE) $(AM_MAKEFLAGS) html
+	@if CAIRO_TESTS="$(FAILED_TESTS)" $(MAKE) $(AM_MAKEFLAGS) check; then \
+	  res=true; \
+	else \
+	  res=false; \
+	fi; \
+	$(MAKE) $(AM_MAKEFLAGS) html && $$res
 
 html-local: index.html
 
diff --git a/cairo/test/README b/cairo/test/README
index 0cd3433..44e144e 100644
--- a/cairo/test/README
+++ b/cairo/test/README
@@ -41,7 +41,7 @@ It should contain a (space-, comma-, etc-separated) list of backends to test.
 To limit the tests run, use the CAIRO_TESTS environment variable, which
 should be a space-separated list of tests to run.  For example:
 
-  CAIRO_TEST="zero-alpha" make test TARGETS=image,ps
+  CAIRO_TESTS="zero-alpha" make test TARGETS=image,ps
 
 Another very handy mechanism when trying to fix bugs is:
 
diff --git a/cairo/test/cairo-test-runner.c b/cairo/test/cairo-test-runner.c
index 5aea643..bbe238c 100644
--- a/cairo/test/cairo-test-runner.c
+++ b/cairo/test/cairo-test-runner.c
@@ -278,9 +278,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 *) * (1 + i);
 	for (i = 0; i < old_argc; i++) {
 	    len = strlen (old_argv[i]) + 1;
 	    if (doit) {
@@ -315,7 +315,7 @@ append_argv (int *argc, char ***argv, const char *str)
 	}
     } while (doit++ == FALSE);
     (*argv)[i] = NULL;
-    *argc += i;
+    *argc = i;
 }
 
 static void
