Fixed two test failures in GrowlVersionUtilities by rejecting a string that doesn't start with (optional whitespace followed by) a version number.
authorPeter Hosey <hg@boredzo.org>
Tue Oct 13 02:33:54 2009 -0700 (2009-10-13)
changeset 45158e4e8d23bf2d
parent 4514 d71f842e5297
child 4516 dac1afb94166
Fixed two test failures in GrowlVersionUtilities by rejecting a string that doesn't start with (optional whitespace followed by) a version number.
Common/Source/GrowlVersionUtilities.c
     1.1 --- a/Common/Source/GrowlVersionUtilities.c	Tue Oct 13 02:32:55 2009 -0700
     1.2 +++ b/Common/Source/GrowlVersionUtilities.c	Tue Oct 13 02:33:54 2009 -0700
     1.3 @@ -17,6 +17,7 @@
     1.4  	if (!string) {
     1.5  		return false;
     1.6  	}
     1.7 +	bool parsed = true;
     1.8  
     1.9  	unsigned myMajor = 0U, myMinor = 0U, myIncremental = 0U, myReleaseType = releaseType_release, myDevelopment = 0U;
    1.10  
    1.11 @@ -38,6 +39,7 @@
    1.12  		return false;
    1.13  	}
    1.14  
    1.15 +	CFIndex i = 0;
    1.16  	CFIndex length = 0;
    1.17  	canConvert = CFStringGetBytes(string, range,
    1.18  								  kCFStringEncodingUTF8,
    1.19 @@ -48,7 +50,14 @@
    1.20  								  &length);
    1.21  	if (canConvert) {
    1.22  		//converted to UTF-8 successfully. parse it.
    1.23 -		CFIndex i = 0;
    1.24 +
    1.25 +		while ((i < length) && isspace(buf[i])) {
    1.26 +			++i;
    1.27 +		}
    1.28 +		if (!isdigit(buf[i])) {
    1.29 +			parsed = false;
    1.30 +			goto end;
    1.31 +		}
    1.32  
    1.33  		//major version
    1.34  		while (i < length) {
    1.35 @@ -162,7 +171,7 @@
    1.36  		outVersion->development	= myDevelopment;
    1.37  	}
    1.38  
    1.39 -	return true;
    1.40 +	return parsed;
    1.41  }
    1.42  
    1.43  CFStringRef createVersionDescription(const struct Version v) {