* Fix a bug where a string longer than INT_MAX can cause IsValid() to falsely

report a valid mimetype because strlen() returns a result than when stored
  in an int is treated as a negative number.

* Style fixes in the same method
This commit is contained in:
John Scipione 2012-03-14 18:56:54 -04:00
parent 08de244f9c
commit 395167071d

View File

@ -1152,25 +1152,25 @@ BMimeType::GetWildcardApps(BMessage *wild_ones)
bool
BMimeType::IsValid(const char *string)
{
if (!string)
if (string == NULL)
return false;
bool foundSlash = false;
int len = strlen(string);
bool foundSlash = false;
size_t len = strlen(string);
if (len >= B_MIME_TYPE_LENGTH || len == 0)
return false;
for (int i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
char ch = string[i];
if (ch == '/') {
if (foundSlash || i == 0 || i == len-1)
if (foundSlash || i == 0 || i == len - 1)
return false;
else
foundSlash = true;
} else if (!isValidMimeChar(ch)) {
return false;
}
}
}
return true;
}