From 395167071d38f02b7d476a7f60d441417ab502e4 Mon Sep 17 00:00:00 2001 From: John Scipione Date: Wed, 14 Mar 2012 18:56:54 -0400 Subject: [PATCH] * 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 --- src/kits/storage/MimeType.cpp | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/src/kits/storage/MimeType.cpp b/src/kits/storage/MimeType.cpp index f8e35d604c..d5bf9932ac 100644 --- a/src/kits/storage/MimeType.cpp +++ b/src/kits/storage/MimeType.cpp @@ -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; }