src/test/SDL_test_fuzzer.c
changeset 6811 60d95fcfaf3c
parent 6789 7177d421bb07
child 6839 2494f667555c
     1.1 --- a/src/test/SDL_test_fuzzer.c	Sat Jan 12 14:06:58 2013 -0500
     1.2 +++ b/src/test/SDL_test_fuzzer.c	Sat Jan 12 22:58:12 2013 -0800
     1.3 @@ -614,25 +614,37 @@
     1.4  char *
     1.5  SDLTest_RandomAsciiString()
     1.6  {
     1.7 -	// note: fuzzerInvocationCounter is increment in the RandomAsciiStringWithMaximumLenght
     1.8  	return SDLTest_RandomAsciiStringWithMaximumLength(255);
     1.9  }
    1.10  
    1.11  char *
    1.12 -SDLTest_RandomAsciiStringWithMaximumLength(int maxSize)
    1.13 +SDLTest_RandomAsciiStringWithMaximumLength(int maxLength)
    1.14  {
    1.15  	int size;
    1.16 +
    1.17 +	if(maxLength < 1) {
    1.18 +                SDL_InvalidParamError("maxLength");
    1.19 +		return NULL;
    1.20 +	}
    1.21 +
    1.22 +	size = (SDLTest_RandomUint32() % (maxLength + 1));
    1.23 +	
    1.24 +	return SDLTest_RandomAsciiStringOfSize(size);	
    1.25 +}
    1.26 +
    1.27 +char *
    1.28 +SDLTest_RandomAsciiStringOfSize(int size)
    1.29 +{
    1.30  	char *string;
    1.31  	int counter;
    1.32  
    1.33 -	fuzzerInvocationCounter++;
    1.34  
    1.35 -	if(maxSize < 1) {
    1.36 +	if(size < 1) {
    1.37 +                SDL_InvalidParamError("size");
    1.38  		return NULL;
    1.39  	}
    1.40  
    1.41 -	size = (SDLTest_RandomUint32() % (maxSize + 1)) + 1;
    1.42 -	string = (char *)SDL_malloc(size * sizeof(char));
    1.43 +	string = (char *)SDL_malloc((size + 1) * sizeof(char));
    1.44  	if (string==NULL) {
    1.45  	  return NULL;
    1.46          }
    1.47 @@ -643,5 +655,7 @@
    1.48  
    1.49  	string[counter] = '\0';
    1.50  
    1.51 +	fuzzerInvocationCounter++;
    1.52 +
    1.53  	return string;
    1.54  }