Skip to content
This repository has been archived by the owner on Feb 11, 2021. It is now read-only.

Commit

Permalink
Allocate memory for testsuite/testcase name so pointer doesn't get ba…
Browse files Browse the repository at this point in the history
…shed.
  • Loading branch information
bobbens committed Aug 4, 2009
1 parent d1f0f61 commit 20be33d
Showing 1 changed file with 19 additions and 11 deletions.
30 changes: 19 additions & 11 deletions test/automated/SDL_at.c
Expand Up @@ -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. */

Expand All @@ -34,10 +36,14 @@ static int at_quiet = 0; /**< Quietness. */
*/
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;
}


Expand All @@ -56,10 +62,10 @@ void SDL_ATinit( const char *suite )
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 );
}


Expand Down Expand Up @@ -152,7 +158,7 @@ void SDL_ATbegin( const char *testcase )
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 );
Expand Down Expand Up @@ -180,6 +186,8 @@ static void SDL_ATendWith( int success )
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;
}

Expand Down

0 comments on commit 20be33d

Please sign in to comment.