changeset 3746:be037e51f080 gsoc2009_unit_tests

Allocate memory for testsuite/testcase name so pointer doesn't get bashed.
author Edgar Simo <bobbens@gmail.com>
date Tue, 04 Aug 2009 16:34:04 +0000
parents f0b89cf4bffc
children f7a3a47e6b50
files test/automated/SDL_at.c
diffstat 1 files changed, 19 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/test/automated/SDL_at.c	Tue Aug 04 16:26:43 2009 +0000
+++ b/test/automated/SDL_at.c	Tue Aug 04 16:34:04 2009 +0000
@@ -9,15 +9,17 @@
 
 #include "SDL_at.h"
 
-#include <stdio.h>
-#include <stdarg.h>
+#include <stdio.h> /* printf/fprintf */
+#include <stdarg.h> /* va_list */
+#include <string.h> /* strdup */
+#include <stdlib.h> /* free */
 
 
 /*
  * Internal usage SDL_AT variables.
  */
-static const char *at_suite_msg = NULL; /**< Testsuite message. */
-static const char *at_test_msg = NULL; /**< Testcase message. */
+static char *at_suite_msg = NULL; /**< Testsuite message. */
+static char *at_test_msg = NULL; /**< Testcase message. */
 static int at_success = 0; /**< Number of successful testcases. */
 static int at_failure = 0; /**< Number of failed testcases. */
 
@@ -34,10 +36,14 @@
  */
 static void SDL_ATcleanup (void)
 {
-   at_suite_msg = NULL;
-   at_test_msg = NULL;
-   at_success = 0;
-   at_failure = 0;
+   if (at_suite_msg != NULL)
+      free(at_suite_msg);
+   at_suite_msg   = NULL;
+   if (at_test_msg != NULL)
+      free(at_test_msg);
+   at_test_msg    = NULL;
+   at_success     = 0;
+   at_failure     = 0;
 }
 
 
@@ -56,10 +62,10 @@
       SDL_ATprintErr( "AT testsuite does not have a name.\n");
    }
    SDL_ATcleanup();
-   at_suite_msg = suite;
+   at_suite_msg = strdup(suite);
 
    /* Verbose message. */
-   SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", suite );
+   SDL_ATprintVerbose( 2, "--+---> Started Test Suite '%s'\n", at_suite_msg );
 }
 
 
@@ -152,7 +158,7 @@
    if (testcase == NULL) {
       SDL_ATprintErr( "AT testcase does not have a name.\n");
    }
-   at_test_msg = testcase;
+   at_test_msg = strdup(testcase);
 
    /* Verbose message. */
    SDL_ATprintVerbose( 2, "  +---> StartedTest Case '%s'\n", testcase );
@@ -180,6 +186,8 @@
    SDL_ATprintVerbose( 2, "  +---- Finished Test Case '%s'\n", at_test_msg );
 
    /* Clean up. */
+   if (at_test_msg != NULL)
+      free(at_test_msg);
    at_test_msg = NULL;
 }