From b6fa6dd61310f2c3935d18d3c09e9ac313d89bb5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20K=C3=B6plinger?= Date: Sun, 5 May 2024 17:25:31 +0200 Subject: [PATCH] Fix check for AppleClang in src/native/libs and fix warnings (#101875) While looking at https://github.com/dotnet/runtime/pull/101781 I noticed that we weren't catching AppleClang in the CMAKE_C_COMPILER_ID in src/native/libs/CMakeLists.txt because we used STREQUAL instead of MATCHES like we do everywhere else. The result was that we didn't enable `-Weverything` on Apple platforms for the libs.native subset and a bunch of warnings didn't get enabled, this PR fixes that. --- src/native/libs/CMakeLists.txt | 2 +- .../pal_calendarData.m | 25 +++---- .../System.Globalization.Native/pal_casing.m | 10 +-- .../pal_collation.m | 43 ++++++------ .../System.Globalization.Native/pal_locale.m | 69 ++++++++++--------- .../pal_normalization.m | 10 +-- .../pal_placeholders.c | 12 +--- .../pal_timeZoneInfo.m | 8 +-- .../libs/System.Native/ios/net/if_media.h | 2 +- .../libs/System.Native/ios/netinet/icmp_var.h | 2 +- .../libs/System.Native/ios/netinet/ip_var.h | 2 +- .../libs/System.Native/ios/netinet/tcp_fsm.h | 4 +- .../libs/System.Native/ios/netinet/udp_var.h | 2 +- .../libs/System.Native/pal_autoreleasepool.m | 5 +- src/native/libs/System.Native/pal_datetime.m | 4 +- .../libs/System.Native/pal_environment.m | 8 +-- .../System.Native/pal_iossupportversion.m | 2 +- src/native/libs/System.Native/pal_log.m | 5 +- .../libs/System.Native/pal_networking.c | 14 ++-- .../System.Native/pal_networkstatistics.c | 1 + src/native/libs/System.Native/pal_process.c | 17 +++++ .../libs/System.Native/pal_searchpath.m | 2 +- src/native/libs/System.Native/pal_threading.c | 3 - .../pal_digest.c | 12 ++-- .../pal_hmac.c | 2 +- .../pal_keychain_ios.c | 30 ++++---- .../pal_keyderivation.c | 6 +- .../pal_keyderivation.h | 2 +- .../pal_signverify.c | 2 +- .../pal_ssl.c | 8 ++- .../pal_x509_ios.c | 8 ++- .../pal_x509chain.c | 2 +- src/native/libs/configure.cmake | 3 +- src/native/minipal/getexepath.h | 4 ++ src/native/minipal/random.c | 6 +- 35 files changed, 183 insertions(+), 154 deletions(-) diff --git a/src/native/libs/CMakeLists.txt b/src/native/libs/CMakeLists.txt index cba0ce782610e..26e619844469c 100644 --- a/src/native/libs/CMakeLists.txt +++ b/src/native/libs/CMakeLists.txt @@ -109,7 +109,7 @@ if (CLR_CMAKE_TARGET_UNIX OR CLR_CMAKE_TARGET_BROWSER OR CLR_CMAKE_TARGET_WASI) add_subdirectory(System.IO.Ports.Native) endif () - if (CMAKE_C_COMPILER_ID STREQUAL Clang) + if (CMAKE_C_COMPILER_ID MATCHES "Clang") add_compile_options(-Weverything) add_compile_options(-Wno-format-nonliteral) add_compile_options(-Wno-disabled-macro-expansion) diff --git a/src/native/libs/System.Globalization.Native/pal_calendarData.m b/src/native/libs/System.Globalization.Native/pal_calendarData.m index 9520e17646754..41bba41d20f10 100644 --- a/src/native/libs/System.Globalization.Native/pal_calendarData.m +++ b/src/native/libs/System.Globalization.Native/pal_calendarData.m @@ -87,7 +87,7 @@ static CalendarId GetCalendarId(const char* calendarName) { @autoreleasepool { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; if (dataType == CalendarData_MonthDay) @@ -162,8 +162,8 @@ static CalendarId GetCalendarId(const char* calendarName) assert(false); return NULL; } - - NSString *arrayToString = [[result valueForKey:@"description"] componentsJoinedByString:@"||"]; + NSArray *descriptionsArray = [result valueForKey:@"description"]; + NSString *arrayToString = [descriptionsArray componentsJoinedByString:@"||"]; return arrayToString ? strdup([arrayToString UTF8String]) : NULL; } } @@ -211,7 +211,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* for (int month = 0; month <= 12; month++) { NSDateComponents *eraComponents = [japaneseCalendar components:NSCalendarUnitEra fromDate:date]; - currentEra = [eraComponents era]; + currentEra = (int32_t)[eraComponents era]; if (currentEra == era) { for (int day = 0; day < 31; day++) @@ -220,7 +220,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* startDateComponents.day = startDateComponents.day - 1; date = [japaneseCalendar dateFromComponents:startDateComponents]; eraComponents = [japaneseCalendar components:NSCalendarUnitEra fromDate:date]; - currentEra = [eraComponents era]; + currentEra = (int32_t)[eraComponents era]; if (currentEra != era) { // add back 1 day to get back into the specified Era @@ -228,9 +228,9 @@ int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* date = [japaneseCalendar dateFromComponents:startDateComponents]; NSCalendar *gregorianCalendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian]; NSDateComponents *components = [gregorianCalendar components:NSCalendarUnitDay | NSCalendarUnitMonth | NSCalendarUnitYear fromDate:date]; - *startYear = [components year]; - *startMonth = [components month]; - *startDay = [components day]; + *startYear = (int32_t)[components year]; + *startMonth = (int32_t)[components month]; + *startDay = (int32_t)[components day]; return 1; } } @@ -239,7 +239,7 @@ int32_t GlobalizationNative_GetJapaneseEraStartDateNative(int32_t era, int32_t* startDateComponents.month = startDateComponents.month + 1; date = [japaneseCalendar dateFromComponents:startDateComponents]; eraComponents = [japaneseCalendar components:NSCalendarUnitEra fromDate:date]; - currentEra = [eraComponents era]; + currentEra = (int32_t)[eraComponents era]; } return 0; @@ -267,17 +267,18 @@ int32_t GlobalizationNative_GetCalendarsNative(const char* localeName, CalendarI NSCalendarIdentifierRepublicOfChina, ]; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSString *defaultCalendarIdentifier = [currentLocale calendarIdentifier]; - int32_t calendarCount = MIN(calendarIdentifiers.count, calendarsCapacity); + int32_t calendarCount = (int32_t)calendarIdentifiers.count < calendarsCapacity ? (int32_t)calendarIdentifiers.count : calendarsCapacity; int32_t calendarIndex = 0; CalendarId defaultCalendarId = GetCalendarId([defaultCalendarIdentifier UTF8String]); // If the default calendar is not supported, return the Gregorian calendar as the default. calendars[calendarIndex++] = defaultCalendarId == UNINITIALIZED_VALUE ? GREGORIAN : defaultCalendarId; for (int i = 0; i < calendarCount; i++) { - CalendarId calendarId = GetCalendarId([calendarIdentifiers[i] UTF8String]); + NSCalendarIdentifier calendarIdentifier = calendarIdentifiers[(NSUInteger)i]; + CalendarId calendarId = GetCalendarId([calendarIdentifier UTF8String]); if (calendarId == UNINITIALIZED_VALUE || calendarId == defaultCalendarId) continue; calendars[calendarIndex++] = calendarId; diff --git a/src/native/libs/System.Globalization.Native/pal_casing.m b/src/native/libs/System.Globalization.Native/pal_casing.m index ba5c853c0b4c6..8b27a56827ca2 100644 --- a/src/native/libs/System.Globalization.Native/pal_casing.m +++ b/src/native/libs/System.Globalization.Native/pal_casing.m @@ -78,7 +78,7 @@ int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, int32_t } else { - NSString *locName = [NSString stringWithCharacters: localeName length: lNameLength]; + NSString *locName = [NSString stringWithCharacters: localeName length: (NSUInteger)lNameLength]; currentLocale = [NSLocale localeWithLocaleIdentifier:locName]; } @@ -89,14 +89,14 @@ int32_t GlobalizationNative_ChangeCaseNative(const uint16_t* localeName, int32_t int32_t startIndex = srcIdx; NEXTOFFSET(lpSrc, srcIdx, cwSrcLength); int32_t srcLength = srcIdx - startIndex; - NSString *src = [NSString stringWithCharacters: lpSrc + startIndex length: srcLength]; + NSString *src = [NSString stringWithCharacters: lpSrc + startIndex length: (NSUInteger)srcLength]; NSString *dst = bToUpper ? [src uppercaseStringWithLocale:currentLocale] : [src lowercaseStringWithLocale:currentLocale]; int32_t index = 0; // iterate over all code points of a surrogate pair character while (index < srcLength) { // the dst.length > srcLength is to prevent code point expansions - dstCodepoint = dst.length > srcLength ? [src characterAtIndex: index] : [dst characterAtIndex: index]; + dstCodepoint = (int32_t)dst.length > srcLength ? [src characterAtIndex: (NSUInteger)index] : [dst characterAtIndex: (NSUInteger)index]; Append(lpDst, dstIdx, cwDstLength, dstCodepoint, isError); index++; } @@ -130,14 +130,14 @@ int32_t GlobalizationNative_ChangeCaseInvariantNative(const uint16_t* lpSrc, int int32_t startIndex = srcIdx; NEXTOFFSET(lpSrc, srcIdx, cwSrcLength); int32_t srcLength = srcIdx - startIndex; - NSString *src = [NSString stringWithCharacters: lpSrc + startIndex length: srcLength]; + NSString *src = [NSString stringWithCharacters: lpSrc + startIndex length: (NSUInteger)srcLength]; NSString *dst = bToUpper ? src.uppercaseString : src.lowercaseString; int32_t index = 0; // iterate over all code points of a surrogate pair character while (index < srcLength) { // the dst.length > srcLength is to prevent code point expansions - dstCodepoint = dst.length > srcLength ? [src characterAtIndex: index] : [dst characterAtIndex: index]; + dstCodepoint = (int32_t)dst.length > srcLength ? [src characterAtIndex: (NSUInteger)index] : [dst characterAtIndex: (NSUInteger)index]; Append(lpDst, dstIdx, cwDstLength, dstCodepoint, isError); index++; } diff --git a/src/native/libs/System.Globalization.Native/pal_collation.m b/src/native/libs/System.Globalization.Native/pal_collation.m index 9a63c11be44ab..f18066d0812e7 100644 --- a/src/native/libs/System.Globalization.Native/pal_collation.m +++ b/src/native/libs/System.Globalization.Native/pal_collation.m @@ -39,7 +39,7 @@ } else { - NSString *locName = [NSString stringWithCharacters: localeName length: lNameLength]; + NSString *locName = [NSString stringWithCharacters: localeName length: (NSUInteger)lNameLength]; currentLocale = [NSLocale localeWithLocaleIdentifier:locName]; } return currentLocale; @@ -90,9 +90,9 @@ int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, int3 if (!IsComparisonOptionSupported(comparisonOptions)) return ERROR_COMPARISON_OPTIONS_NOT_FOUND; NSLocale *currentLocale = GetCurrentLocale(localeName, lNameLength); - NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; + NSString *sourceString = [NSString stringWithCharacters: lpSource length: (NSUInteger)cwSourceLength]; NSString *sourceStrPrecomposed = sourceString.precomposedStringWithCanonicalMapping; - NSString *targetString = [NSString stringWithCharacters: lpTarget length: cwTargetLength]; + NSString *targetString = [NSString stringWithCharacters: lpTarget length: (NSUInteger)cwTargetLength]; NSString *targetStrPrecomposed = targetString.precomposedStringWithCanonicalMapping; if (comparisonOptions & IgnoreKanaType) @@ -110,7 +110,7 @@ int32_t GlobalizationNative_CompareStringNative(const uint16_t* localeName, int3 NSStringCompareOptions options = ConvertFromCompareOptionsToNSStringCompareOptions(comparisonOptions, true); NSRange comparisonRange = NSMakeRange(0, sourceStrPrecomposed.length); - return [sourceStrPrecomposed compare:targetStrPrecomposed + return (int32_t)[sourceStrPrecomposed compare:targetStrPrecomposed options:options range:comparisonRange locale:currentLocale]; @@ -158,9 +158,9 @@ Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, int32_t lNam return result; } NSStringCompareOptions options = ConvertFromCompareOptionsToNSStringCompareOptions(comparisonOptions, true); - NSString *searchString = [NSString stringWithCharacters: lpTarget length: cwTargetLength]; + NSString *searchString = [NSString stringWithCharacters: lpTarget length: (NSUInteger)cwTargetLength]; NSString *searchStrCleaned = RemoveWeightlessCharacters(searchString); - NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; + NSString *sourceString = [NSString stringWithCharacters: lpSource length: (NSUInteger)cwSourceLength]; NSString *sourceStrCleaned = RemoveWeightlessCharacters(sourceString); if (comparisonOptions & IgnoreKanaType) { @@ -170,7 +170,7 @@ Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, int32_t lNam if (sourceStrCleaned.length == 0 || searchStrCleaned.length == 0) { - result.location = fromBeginning ? 0 : sourceString.length; + result.location = fromBeginning ? 0 : (int32_t)sourceString.length; return result; } @@ -204,8 +204,8 @@ Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, int32_t lNam if (nsRange.location != NSNotFound) { - result.location = nsRange.location; - result.length = nsRange.length; + result.location = (int32_t)nsRange.location; + result.length = (int32_t)nsRange.length; // in case of CompareOptions.IgnoreCase if letters have different representations in source and search strings // and case insensitive search appears more than one time in source string take last index for LastIndexOf and first index for IndexOf // e.g. new CultureInfo().CompareInfo.LastIndexOf("Is \u0055\u0308 or \u0075\u0308 the same as \u00DC or \u00FC?", "U\u0308", 25,18, CompareOptions.IgnoreCase); @@ -230,8 +230,8 @@ Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, int32_t lNam if ((comparisonOptions & IgnoreCase) && IsIndexFound(fromBeginning, (int32_t)result.location, (int32_t)precomposedRange.location)) return result; - result.location = precomposedRange.location; - result.length = precomposedRange.length; + result.location = (int32_t)precomposedRange.location; + result.length = (int32_t)precomposedRange.length; if (!(comparisonOptions & IgnoreCase)) return result; } @@ -249,8 +249,8 @@ Range GlobalizationNative_IndexOfNative(const uint16_t* localeName, int32_t lNam if ((comparisonOptions & IgnoreCase) && IsIndexFound(fromBeginning, (int32_t)result.location, (int32_t)decomposedRange.location)) return result; - result.location = decomposedRange.location; - result.length = decomposedRange.length; + result.location = (int32_t)decomposedRange.location; + result.length = (int32_t)decomposedRange.length; return result; } @@ -270,9 +270,9 @@ int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, int32_t return ERROR_COMPARISON_OPTIONS_NOT_FOUND; NSStringCompareOptions options = ConvertFromCompareOptionsToNSStringCompareOptions(comparisonOptions, true); NSLocale *currentLocale = GetCurrentLocale(localeName, lNameLength); - NSString *prefixString = [NSString stringWithCharacters: lpPrefix length: cwPrefixLength]; + NSString *prefixString = [NSString stringWithCharacters: lpPrefix length: (NSUInteger)cwPrefixLength]; NSString *prefixStrComposed = RemoveWeightlessCharacters(prefixString.precomposedStringWithCanonicalMapping); - NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; + NSString *sourceString = [NSString stringWithCharacters: lpSource length: (NSUInteger)cwSourceLength]; NSString *sourceStrComposed = RemoveWeightlessCharacters(sourceString.precomposedStringWithCanonicalMapping); if (comparisonOptions & IgnoreKanaType) { @@ -282,7 +282,7 @@ int32_t GlobalizationNative_StartsWithNative(const uint16_t* localeName, int32_t NSRange sourceRange = NSMakeRange(0, prefixStrComposed.length > sourceStrComposed.length ? sourceStrComposed.length : prefixStrComposed.length); - int32_t result = [sourceStrComposed compare:prefixStrComposed + int32_t result = (int32_t)[sourceStrComposed compare:prefixStrComposed options:options range:sourceRange locale:currentLocale]; @@ -302,19 +302,19 @@ int32_t GlobalizationNative_EndsWithNative(const uint16_t* localeName, int32_t l return ERROR_COMPARISON_OPTIONS_NOT_FOUND; NSStringCompareOptions options = ConvertFromCompareOptionsToNSStringCompareOptions(comparisonOptions, true); NSLocale *currentLocale = GetCurrentLocale(localeName, lNameLength); - NSString *suffixString = [NSString stringWithCharacters: lpSuffix length: cwSuffixLength]; + NSString *suffixString = [NSString stringWithCharacters: lpSuffix length: (NSUInteger)cwSuffixLength]; NSString *suffixStrComposed = RemoveWeightlessCharacters(suffixString.precomposedStringWithCanonicalMapping); - NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; + NSString *sourceString = [NSString stringWithCharacters: lpSource length: (NSUInteger)cwSourceLength]; NSString *sourceStrComposed = RemoveWeightlessCharacters(sourceString.precomposedStringWithCanonicalMapping); if (comparisonOptions & IgnoreKanaType) { suffixStrComposed = ConvertToKatakana(suffixStrComposed); sourceStrComposed = ConvertToKatakana(sourceStrComposed); } - int32_t startIndex = suffixStrComposed.length > sourceStrComposed.length ? 0 : sourceStrComposed.length - suffixStrComposed.length; + NSUInteger startIndex = suffixStrComposed.length > sourceStrComposed.length ? 0 : sourceStrComposed.length - suffixStrComposed.length; NSRange sourceRange = NSMakeRange(startIndex, sourceStrComposed.length - startIndex); - int32_t result = [sourceStrComposed compare:suffixStrComposed + int32_t result = (int32_t)[sourceStrComposed compare:suffixStrComposed options:options range:sourceRange locale:currentLocale]; @@ -334,7 +334,7 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t } if (!IsComparisonOptionSupported(options)) return 0; - NSString *sourceString = [NSString stringWithCharacters: lpStr length: cwStrLength]; + NSString *sourceString = [NSString stringWithCharacters: lpStr length: (NSUInteger)cwStrLength]; if (options & IgnoreKanaType) { sourceString = ConvertToKatakana(sourceString); @@ -363,6 +363,7 @@ int32_t GlobalizationNative_GetSortKeyNative(const uint16_t* localeName, int32_t if (result) return (int32_t)usedLength; + (void)cbSortKeyLength; // ignore unused parameter return 0; } } diff --git a/src/native/libs/System.Globalization.Native/pal_locale.m b/src/native/libs/System.Globalization.Native/pal_locale.m index 873b56950ee3c..9cb5ffbaa1343 100644 --- a/src/native/libs/System.Globalization.Native/pal_locale.m +++ b/src/native/libs/System.Globalization.Native/pal_locale.m @@ -41,7 +41,7 @@ { @autoreleasepool { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; const char* value = [currentLocale.localeIdentifier UTF8String]; return strdup(value); @@ -79,11 +79,11 @@ static void GetParent(const char* localeID, char* parent, int32_t parentCapacity { localeID += 3; i -= 3; - memmove(parent, localeID, MIN(i, parentCapacity)); + memmove(parent, localeID, i < parentCapacity ? i : parentCapacity); } else if (parent != localeID) { - memcpy(parent, localeID, MIN(i, parentCapacity)); + memcpy(parent, localeID, i < parentCapacity ? i : parentCapacity); } } @@ -139,7 +139,7 @@ static int16_t _findIndex(const char* const* list, const char* key) @autoreleasepool { NSString *value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; numberFormatter.locale = currentLocale; @@ -152,7 +152,7 @@ static int16_t _findIndex(const char* const* list, const char* key) ///// localized name of locale, eg "German (Germany)" in UI language (corresponds to LOCALE_SLOCALIZEDDISPLAYNAME) case LocaleString_LocalizedDisplayName: { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSString *currUILocaleName = [[NSString alloc] initWithUTF8String: currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; value = [currentUILocale displayNameForKey:NSLocaleIdentifier value:currentLocale.localeIdentifier]; break; @@ -168,7 +168,7 @@ static int16_t _findIndex(const char* const* list, const char* key) /// Language Display Name for a language, eg "German" in UI language (corresponds to LOCALE_SLOCALIZEDLANGUAGENAME) case LocaleString_LocalizedLanguageName: { - NSString *currUILocaleName = [NSString stringWithFormat:@"%s", currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; + NSString *currUILocaleName = [[NSString alloc] initWithUTF8String: currentUILocaleName == NULL ? GlobalizationNative_GetDefaultLocaleNameNative() : currentUILocaleName]; NSLocale *currentUILocale = [[NSLocale alloc] initWithLocaleIdentifier:currUILocaleName]; value = [currentUILocale localizedStringForLanguageCode:currentLocale.languageCode]; break; @@ -183,11 +183,11 @@ static int16_t _findIndex(const char* const* list, const char* key) break; /// English name of country, eg "Germany" (corresponds to LOCALE_SENGLISHCOUNTRYNAME) case LocaleString_EnglishCountryName: - value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode]; + value = [gbLocale localizedStringForCountryCode:currentLocale.countryCode == nil ? @"" : currentLocale.countryCode]; break; /// native name of country, eg "Deutschland" (corresponds to LOCALE_SNATIVECOUNTRYNAME) case LocaleString_NativeCountryName: - value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode]; + value = [currentLocale localizedStringForCountryCode:currentLocale.countryCode == nil ? @"" : currentLocale.countryCode]; break; case LocaleString_ThousandSeparator: value = currentLocale.groupingSeparator; @@ -214,10 +214,10 @@ static int16_t _findIndex(const char* const* list, const char* key) value = currentLocale.currencyCode; break; case LocaleString_CurrencyEnglishName: - value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + value = [gbLocale localizedStringForCurrencyCode:currentLocale.currencyCode == nil ? @"" : currentLocale.currencyCode]; break; case LocaleString_CurrencyNativeName: - value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode]; + value = [currentLocale localizedStringForCurrencyCode:currentLocale.currencyCode == nil ? @"" : currentLocale.currencyCode]; break; case LocaleString_MonetaryDecimalSeparator: value = numberFormatter.currencyDecimalSeparator; @@ -307,7 +307,7 @@ static int16_t _findIndex(const char* const* list, const char* key) static char* NormalizeNumericPattern(const char* srcPattern, int isNegative) { int iStart = 0; - int iEnd = strlen(srcPattern); + int iEnd = (int)strlen(srcPattern); // ';' separates positive and negative subpatterns. // When there is no explicit negative subpattern, @@ -315,7 +315,7 @@ static int16_t _findIndex(const char* const* list, const char* key) char * ptrNegativePattern = strrchr(srcPattern,';'); if (ptrNegativePattern) { - int32_t iNegativePatternStart = ptrNegativePattern - srcPattern; + int32_t iNegativePatternStart = (int32_t)(ptrNegativePattern - srcPattern); if (isNegative) { iStart = iNegativePatternStart + 1; @@ -529,16 +529,17 @@ int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, Local bool isSuccess = true; #endif int32_t value; - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; switch (localeNumberData) { case LocaleNumber_MeasurementSystem: { - const char *measurementSystem = [[currentLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; - NSLocale *usLocale = [[NSLocale alloc] initWithLocaleIdentifier:@"en_US"]; - const char *us_measurementSystem = [[usLocale objectForKey:NSLocaleMeasurementSystem] UTF8String]; + NSString *currentLocaleCode = [currentLocale objectForKey:NSLocaleMeasurementSystem]; + NSString *usLocaleCode = [[[NSLocale alloc] initWithLocaleIdentifier:@"en_US"] objectForKey:NSLocaleMeasurementSystem]; + const char *measurementSystem = [currentLocaleCode UTF8String]; + const char *us_measurementSystem = [usLocaleCode UTF8String]; value = (measurementSystem == us_measurementSystem) ? 1 : 0; break; } @@ -600,7 +601,8 @@ int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, Local } case LocaleNumber_ReadingLayout: { - NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:[currentLocale objectForKey:NSLocaleLanguageCode]]; + NSString* langCode = [currentLocale objectForKey:NSLocaleLanguageCode]; + NSLocaleLanguageDirection langDir = [NSLocale characterDirectionForLanguage:langCode]; // 0 - Left to right (such as en-US) // 1 - Right to left (such as arabic locales) value = NSLocaleLanguageDirectionRightToLeft == langDir ? 1 : 0; @@ -609,7 +611,7 @@ int32_t GlobalizationNative_GetLocaleInfoIntNative(const char* localeName, Local case LocaleNumber_FirstDayofWeek: { NSCalendar *calendar = [currentLocale objectForKey:NSLocaleCalendar]; - value = [calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; + value = (int32_t)[calendar firstWeekday] - 1; // .NET is 0-based and in Apple is 1-based; break; } default: @@ -636,7 +638,7 @@ int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* l { @autoreleasepool { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; numberFormatter.locale = currentLocale; @@ -653,7 +655,7 @@ int32_t GlobalizationNative_GetLocaleInfoPrimaryGroupingSizeNative(const char* l assert(false); break; } - return [numberFormatter groupingSize]; + return (int32_t)[numberFormatter groupingSize]; } } @@ -667,7 +669,7 @@ int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* { @autoreleasepool { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSNumberFormatter *numberFormatter = [[NSNumberFormatter alloc] init]; numberFormatter.locale = currentLocale; @@ -685,7 +687,7 @@ int32_t GlobalizationNative_GetLocaleInfoSecondaryGroupingSizeNative(const char* break; } - return [numberFormatter secondaryGroupingSize]; + return (int32_t)[numberFormatter secondaryGroupingSize]; } } @@ -699,7 +701,7 @@ Returns time format information (in native format, it needs to be converted to . { @autoreleasepool { - NSString *locName = [NSString stringWithFormat:@"%s", localeName]; + NSString *locName = [[NSString alloc] initWithUTF8String:localeName]; NSLocale *currentLocale = [[NSLocale alloc] initWithLocaleIdentifier:locName]; NSDateFormatter* dateFormatter = [[NSDateFormatter alloc] init]; [dateFormatter setLocale:currentLocale]; @@ -729,26 +731,26 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) @autoreleasepool { NSArray* availableLocaleIdentifiers = [NSLocale availableLocaleIdentifiers]; - int32_t index = 0; - int32_t totalLength = 0; - int32_t availableLength = (int32_t)[availableLocaleIdentifiers count]; + NSUInteger index = 0; + NSUInteger totalLength = 0; + NSUInteger availableLength = [availableLocaleIdentifiers count]; if (availableLength <= 0) return -1; // failed - for (NSInteger i = 0; i < availableLength; i++) + for (NSUInteger i = 0; i < availableLength; i++) { NSString *localeIdentifier = availableLocaleIdentifiers[i]; - int32_t localeNameLength = localeIdentifier.length; + NSUInteger localeNameLength = localeIdentifier.length; totalLength += localeNameLength + 1; // add 1 for the name length if (value != NULL) { - if (totalLength > length) + if (totalLength > (NSUInteger)length) return -3; value[index++] = (UChar) localeNameLength; - for (int j = 0; j < localeNameLength; j++) + for (NSUInteger j = 0; j < localeNameLength; j++) { if ((UChar)[localeIdentifier characterAtIndex:j] == '_') { @@ -761,7 +763,7 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) } } } - return totalLength; + return (int32_t)totalLength; } } @@ -770,7 +772,8 @@ int32_t GlobalizationNative_GetLocalesNative(UChar* value, int32_t length) @autoreleasepool { NSString *bundlePath = [[NSBundle mainBundle] bundlePath]; - NSString *dataPath = [bundlePath stringByAppendingPathComponent: [NSString stringWithFormat:@"%s", path]]; + NSString *pathInBundle = [[NSString alloc] initWithUTF8String:path]; + NSString *dataPath = [bundlePath stringByAppendingPathComponent:pathInBundle]; return strdup([dataPath UTF8String]); } @@ -824,7 +827,7 @@ int32_t GlobalizationNative_IsPredefinedLocaleNative(const char* localeName) { @autoreleasepool { - NSString *localeIdentifier = [NSString stringWithFormat:@"%s", localeName]; + NSString *localeIdentifier = [[NSString alloc] initWithUTF8String:localeName]; NSString *localeIdentifierByRegionDesignator = [localeIdentifier stringByReplacingOccurrencesOfString:@"-" withString:@"_"]; NSArray *availableLocales = [NSLocale availableLocaleIdentifiers]; diff --git a/src/native/libs/System.Globalization.Native/pal_normalization.m b/src/native/libs/System.Globalization.Native/pal_normalization.m index c029a16328bb2..4dac9969a27dc 100644 --- a/src/native/libs/System.Globalization.Native/pal_normalization.m +++ b/src/native/libs/System.Globalization.Native/pal_normalization.m @@ -45,7 +45,7 @@ int32_t GlobalizationNative_IsNormalizedNative(NormalizationForm normalizationFo { @autoreleasepool { - NSString *sourceString = [NSString stringWithCharacters: lpStr length: cwStrLength]; + NSString *sourceString = [NSString stringWithCharacters: lpStr length: (NSUInteger)cwStrLength]; NSString *normalizedString = GetNormalizedStringForForm(normalizationForm, sourceString); return normalizedString == NULL ? -1 : [sourceString isEqualToString: normalizedString]; @@ -67,7 +67,7 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio { @autoreleasepool { - NSString *sourceString = [NSString stringWithCharacters: lpSource length: cwSourceLength]; + NSString *sourceString = [NSString stringWithCharacters: lpSource length: (NSUInteger)cwSourceLength]; NSString *normalizedString = GetNormalizedStringForForm(normalizationForm, sourceString); if (normalizedString == NULL || normalizedString.length == 0) @@ -77,14 +77,14 @@ int32_t GlobalizationNative_NormalizeStringNative(NormalizationForm normalizatio int32_t index = 0, dstIdx = 0, isError = 0; uint16_t dstCodepoint; - while (index < normalizedString.length) + while ((NSUInteger)index < normalizedString.length) { - dstCodepoint = [normalizedString characterAtIndex: index]; + dstCodepoint = [normalizedString characterAtIndex: (NSUInteger)index]; Append(lpDst, dstIdx, cwDstLength, dstCodepoint, isError); index++; } - return !isError ? [normalizedString length] : 0; + return !isError ? (int32_t)[normalizedString length] : 0; } } #endif diff --git a/src/native/libs/System.Globalization.Native/pal_placeholders.c b/src/native/libs/System.Globalization.Native/pal_placeholders.c index 7d0f9624e082b..413e2d311a29d 100644 --- a/src/native/libs/System.Globalization.Native/pal_placeholders.c +++ b/src/native/libs/System.Globalization.Native/pal_placeholders.c @@ -16,14 +16,6 @@ #include "pal_timeZoneInfo.h" #ifdef DEBUG -#define assert_err(cond, msg, err) do \ -{ \ - if(!(cond)) \ - { \ - fprintf(stderr, "%s (%d): error %d: %s. %s (%s failed)\n", __FILE__, __LINE__, err, msg, strerror(err), #cond); \ - assert(false && "assert_err failed"); \ - } \ -} while(0) #define assert_msg(cond, msg, val) do \ { \ if(!(cond)) \ @@ -33,10 +25,12 @@ } \ } while(0) #else // DEBUG -#define assert_err(cond, msg, err) #define assert_msg(cond, msg, val) #endif // DEBUG +// don't generate warnings for placeholders +#pragma clang diagnostic ignored "-Wunused-parameter" +#pragma clang diagnostic ignored "-Wmissing-noreturn" // Placeholder for calendar data int32_t GlobalizationNative_GetCalendars( diff --git a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m index e5404e5cb0d4c..b7e7dc627da20 100644 --- a/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m +++ b/src/native/libs/System.Globalization.Native/pal_timeZoneInfo.m @@ -20,7 +20,7 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN { @autoreleasepool { - NSString* tzName = [NSString stringWithCharacters: timeZoneId length: timeZoneIdLength]; + NSString* tzName = [NSString stringWithCharacters: timeZoneId length: (NSUInteger)timeZoneIdLength]; NSTimeZone* timeZone = [NSTimeZone timeZoneWithName:tzName]; if (timeZone == NULL) { @@ -39,7 +39,7 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN } else { - NSString *locName = [NSString stringWithCharacters: localeName length: lNameLength]; + NSString *locName = [NSString stringWithCharacters: localeName length: (NSUInteger)lNameLength]; currentLocale = [NSLocale localeWithLocaleIdentifier:locName]; } NSTimeZoneNameStyle style; @@ -68,9 +68,9 @@ int32_t GlobalizationNative_GetTimeZoneDisplayNameNative(const uint16_t* localeN int32_t index = 0, dstIdx = 0, resultCode = Success; uint16_t dstCodepoint; - while (index < timeZoneName.length) + while ((NSUInteger)index < timeZoneName.length) { - dstCodepoint = [timeZoneName characterAtIndex: index]; + dstCodepoint = [timeZoneName characterAtIndex: (NSUInteger)index]; Append(result, dstIdx, resultLength, dstCodepoint, resultCode); if (resultCode != Success) return resultCode; diff --git a/src/native/libs/System.Native/ios/net/if_media.h b/src/native/libs/System.Native/ios/net/if_media.h index e7e1a838d420f..cef4c1f666a35 100644 --- a/src/native/libs/System.Native/ios/net/if_media.h +++ b/src/native/libs/System.Native/ios/net/if_media.h @@ -586,4 +586,4 @@ struct ifmedia_description { { 0, NULL }, \ } -#endif /* _NET_IF_MEDIA_H_ */ \ No newline at end of file +#endif /* _NET_IF_MEDIA_H_ */ diff --git a/src/native/libs/System.Native/ios/netinet/icmp_var.h b/src/native/libs/System.Native/ios/netinet/icmp_var.h index 2633ab1bcf5a3..da5c3955e1a76 100644 --- a/src/native/libs/System.Native/ios/netinet/icmp_var.h +++ b/src/native/libs/System.Native/ios/netinet/icmp_var.h @@ -118,4 +118,4 @@ extern boolean_t badport_bandlim(int which); extern struct icmpstat icmpstat; #endif /* BSD_KERNEL_PRIVATE */ -#endif /* _NETINET_ICMP_VAR_H_ */ \ No newline at end of file +#endif /* _NETINET_ICMP_VAR_H_ */ diff --git a/src/native/libs/System.Native/ios/netinet/ip_var.h b/src/native/libs/System.Native/ios/netinet/ip_var.h index e5137effeed46..7fbe4ba82bfc4 100644 --- a/src/native/libs/System.Native/ios/netinet/ip_var.h +++ b/src/native/libs/System.Native/ios/netinet/ip_var.h @@ -368,4 +368,4 @@ extern int ip_gre_output(struct mbuf *); typedef struct mbuf *(*gre_input_func_t)(struct mbuf *, int, int); extern int ip_gre_register_input(gre_input_func_t); #endif /* KERNEL_PRIVATE */ -#endif /* !_NETINET_IP_VAR_H_ */ \ No newline at end of file +#endif /* !_NETINET_IP_VAR_H_ */ diff --git a/src/native/libs/System.Native/ios/netinet/tcp_fsm.h b/src/native/libs/System.Native/ios/netinet/tcp_fsm.h index 869d9bcef8d51..0bdb5b0fe60f5 100644 --- a/src/native/libs/System.Native/ios/netinet/tcp_fsm.h +++ b/src/native/libs/System.Native/ios/netinet/tcp_fsm.h @@ -136,7 +136,7 @@ static u_char tcp_outflags[TCP_NSTATES] = { #endif #endif /* KERNEL_PRIVATE */ -#if KPROF +#ifdef KPROF #ifdef KERNEL_PRIVATE int tcp_acounts[TCP_NSTATES][PRU_NREQ]; #endif /* KERNEL_PRIVATE */ @@ -150,4 +150,4 @@ char *tcpstates[] = { }; #endif -#endif \ No newline at end of file +#endif diff --git a/src/native/libs/System.Native/ios/netinet/udp_var.h b/src/native/libs/System.Native/ios/netinet/udp_var.h index 12e4ea51f0b49..54afeab9deb5f 100644 --- a/src/native/libs/System.Native/ios/netinet/udp_var.h +++ b/src/native/libs/System.Native/ios/netinet/udp_var.h @@ -185,4 +185,4 @@ extern void udp_fill_keepalive_offload_frames(struct ifnet *, __END_DECLS #endif /* BSD_KERNEL_PRIVATE */ -#endif /* _NETINET_UDP_VAR_H_ */ \ No newline at end of file +#endif /* _NETINET_UDP_VAR_H_ */ diff --git a/src/native/libs/System.Native/pal_autoreleasepool.m b/src/native/libs/System.Native/pal_autoreleasepool.m index 9f20031ffca47..740a059e7e0e2 100644 --- a/src/native/libs/System.Native/pal_autoreleasepool.m +++ b/src/native/libs/System.Native/pal_autoreleasepool.m @@ -20,9 +20,12 @@ void EnsureNSThreadIsMultiThreaded(void) // We need to use detachNewThreadSelector to put NSThread into multithreaded mode. // We can't use detachNewThreadWithBlock since it doesn't change NSThread into multithreaded mode for some reason. // See https://developer.apple.com/documentation/foundation/nswillbecomemultithreadednotification for more information. - id placeholderObject = [[NSMutableString alloc] init]; + id placeholderObject = [[NSMutableString alloc] init]; [NSThread detachNewThreadSelector:@selector(appendString:) toTarget:placeholderObject withObject:@""]; +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wobjc-messaging-id" [placeholderObject release]; +#pragma clang diagnostic pop } assert([NSThread isMultiThreaded]); } diff --git a/src/native/libs/System.Native/pal_datetime.m b/src/native/libs/System.Native/pal_datetime.m index f023703f27be0..74914d4fdc323 100644 --- a/src/native/libs/System.Native/pal_datetime.m +++ b/src/native/libs/System.Native/pal_datetime.m @@ -8,9 +8,9 @@ #error This file uses manual memory management and must not use ARC, but ARC is enabled. #endif -char* SystemNative_GetDefaultTimeZone() +char* SystemNative_GetDefaultTimeZone(void) { NSTimeZone *tz = [NSTimeZone localTimeZone]; NSString *name = [tz name]; return (name != nil) ? strdup([name UTF8String]) : NULL; -} \ No newline at end of file +} diff --git a/src/native/libs/System.Native/pal_environment.m b/src/native/libs/System.Native/pal_environment.m index fe02a2f96d4bb..3293b8b37bf04 100644 --- a/src/native/libs/System.Native/pal_environment.m +++ b/src/native/libs/System.Native/pal_environment.m @@ -25,8 +25,8 @@ static void get_environ_helper(const void *key, const void *value, void *context char ***temp_environ_ptr = (char***)context; const char *utf8_key = [(NSString *)key UTF8String]; const char *utf8_value = [(NSString *)value UTF8String]; - int utf8_key_length = strlen(utf8_key); - int utf8_value_length = strlen(utf8_value); + size_t utf8_key_length = strlen(utf8_key); + size_t utf8_value_length = strlen(utf8_value); char *key_value_pair; key_value_pair = malloc(utf8_key_length + utf8_value_length + 2); @@ -47,13 +47,13 @@ static void get_environ_helper(const void *key, const void *value, void *context (*temp_environ_ptr)++; } -char** SystemNative_GetEnviron() +char** SystemNative_GetEnviron(void) { char **temp_environ; char **temp_environ_ptr; CFDictionaryRef environment = (CFDictionaryRef)[[NSProcessInfo processInfo] environment]; - int count = CFDictionaryGetCount(environment); + size_t count = (size_t)CFDictionaryGetCount(environment); temp_environ = (char **)malloc((count + 1) * sizeof(char *)); if (temp_environ != NULL) { diff --git a/src/native/libs/System.Native/pal_iossupportversion.m b/src/native/libs/System.Native/pal_iossupportversion.m index 0a531350a1d07..b3ace719f2e13 100644 --- a/src/native/libs/System.Native/pal_iossupportversion.m +++ b/src/native/libs/System.Native/pal_iossupportversion.m @@ -9,7 +9,7 @@ #error This file uses manual memory management and must not use ARC, but ARC is enabled. #endif -const char* SystemNative_iOSSupportVersion() +const char* SystemNative_iOSSupportVersion(void) { NSDictionary *plist = [[NSDictionary alloc] initWithContentsOfFile:@"/System/Library/CoreServices/SystemVersion.plist"]; NSString *iOSSupportVersion = (NSString *)[plist objectForKey:@"iOSSupportVersion"]; diff --git a/src/native/libs/System.Native/pal_log.m b/src/native/libs/System.Native/pal_log.m index b62e4f750a838..befc96a518e35 100644 --- a/src/native/libs/System.Native/pal_log.m +++ b/src/native/libs/System.Native/pal_log.m @@ -10,7 +10,7 @@ void SystemNative_Log (uint8_t* buffer, int32_t length) { - NSString *msg = [[NSString alloc] initWithBytes: buffer length: length encoding: NSUTF16LittleEndianStringEncoding]; + NSString *msg = [[NSString alloc] initWithBytes: buffer length: (NSUInteger)length encoding: NSUTF16LittleEndianStringEncoding]; if (length > 4096) { // Write in chunks of max 4096 characters; older versions of iOS seems to have a bug where NSLog may hang with long strings (!). @@ -32,7 +32,10 @@ void SystemNative_Log (uint8_t* buffer, int32_t length) // No newline found, break in the middle. chunk_size = len > max_size ? max_size : len; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcstring-format-directive" NSLog (@"%.*s", (int) chunk_size, utf8); +#pragma clang diagnostic pop len -= chunk_size; utf8 += chunk_size; } diff --git a/src/native/libs/System.Native/pal_networking.c b/src/native/libs/System.Native/pal_networking.c index f8916702ef48d..113ef377294f2 100644 --- a/src/native/libs/System.Native/pal_networking.c +++ b/src/native/libs/System.Native/pal_networking.c @@ -2076,7 +2076,7 @@ int32_t SystemNative_GetSockOpt( } struct socket_fdinfo fdi; - if (proc_pidfdinfo(getpid(), fd, PROC_PIDFDSOCKETINFO, &fdi, sizeof(fdi)) < sizeof(fdi)) + if (proc_pidfdinfo(getpid(), fd, PROC_PIDFDSOCKETINFO, &fdi, sizeof(fdi)) < (int)sizeof(fdi)) { return SystemNative_ConvertErrorPlatformToPal(errno); } @@ -2589,7 +2589,7 @@ int32_t SystemNative_GetSocketType(intptr_t socket, int32_t* addressFamily, int3 #if HAVE_SYS_PROCINFO_H struct socket_fdinfo fdi; - if (proc_pidfdinfo(getpid(), fd, PROC_PIDFDSOCKETINFO, &fdi, sizeof(fdi)) < sizeof(fdi)) + if (proc_pidfdinfo(getpid(), fd, PROC_PIDFDSOCKETINFO, &fdi, sizeof(fdi)) < (int)sizeof(fdi)) { return Error_EFAULT; } @@ -3218,8 +3218,8 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i char* buffer = NULL; // Save the original input file position and seek to the offset position - off_t inputFileOrigOffset = lseek(in_fd, 0, SEEK_CUR); - if (inputFileOrigOffset == -1 || lseek(in_fd, offtOffset, SEEK_SET) == -1) + off_t inputFileOrigOffset = lseek(infd, 0, SEEK_CUR); + if (inputFileOrigOffset == -1 || lseek(infd, offtOffset, SEEK_SET) == -1) { goto error; } @@ -3239,7 +3239,7 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i // Read up to what will fit in our buffer. We're done if we get back 0 bytes or read 'count' bytes ssize_t bytesRead; - while ((bytesRead = read(in_fd, buffer, numBytesToRead)) < 0 && errno == EINTR); + while ((bytesRead = read(infd, buffer, numBytesToRead)) < 0 && errno == EINTR); if (bytesRead == -1) { goto error; @@ -3255,7 +3255,7 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i while (bytesRead > 0) { ssize_t bytesWritten; - while ((bytesWritten = write(out_fd, buffer + writeOffset, (size_t)bytesRead)) < 0 && errno == EINTR); + while ((bytesWritten = write(outfd, buffer + writeOffset, (size_t)bytesRead)) < 0 && errno == EINTR); if (bytesWritten == -1) { goto error; @@ -3269,7 +3269,7 @@ int32_t SystemNative_SendFile(intptr_t out_fd, intptr_t in_fd, int64_t offset, i } // Restore the original input file position - if (lseek(in_fd, inputFileOrigOffset, SEEK_SET) == -1) + if (lseek(infd, inputFileOrigOffset, SEEK_SET) == -1) { goto error; } diff --git a/src/native/libs/System.Native/pal_networkstatistics.c b/src/native/libs/System.Native/pal_networkstatistics.c index eeeb8ac802942..bfa1cc50074be 100644 --- a/src/native/libs/System.Native/pal_networkstatistics.c +++ b/src/native/libs/System.Native/pal_networkstatistics.c @@ -18,6 +18,7 @@ #if HAVE_NETINET_TCP_VAR_H #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wreserved-id-macro" +#pragma clang diagnostic ignored "-Wunused-macros" #define _WANT_INPCB #define _WANT_TCPCB #pragma clang diagnostic pop diff --git a/src/native/libs/System.Native/pal_process.c b/src/native/libs/System.Native/pal_process.c index 509049b2fdcd7..fa5e522c36205 100644 --- a/src/native/libs/System.Native/pal_process.c +++ b/src/native/libs/System.Native/pal_process.c @@ -507,6 +507,23 @@ done:; return success ? 0 : -1; #else + // ignore unused parameters + (void)filename; + (void)argv; + (void)envp; + (void)cwd; + (void)redirectStdin; + (void)redirectStdout; + (void)redirectStderr; + (void)setCredentials; + (void)userId; + (void)groupId; + (void)groups; + (void)groupsLength; + (void)childPid; + (void)stdinFd; + (void)stdoutFd; + (void)stderrFd; return -1; #endif } diff --git a/src/native/libs/System.Native/pal_searchpath.m b/src/native/libs/System.Native/pal_searchpath.m index e8d07c163cc4e..571e9b04116f5 100644 --- a/src/native/libs/System.Native/pal_searchpath.m +++ b/src/native/libs/System.Native/pal_searchpath.m @@ -16,7 +16,7 @@ return path == NULL ? NULL : strdup (path); } -const char* SystemNative_SearchPath_TempDirectory() +const char* SystemNative_SearchPath_TempDirectory(void) { NSString* tempPath = NSTemporaryDirectory(); const char *path = [tempPath UTF8String]; diff --git a/src/native/libs/System.Native/pal_threading.c b/src/native/libs/System.Native/pal_threading.c index 975e94acc476d..1d9f3cd6bf330 100644 --- a/src/native/libs/System.Native/pal_threading.c +++ b/src/native/libs/System.Native/pal_threading.c @@ -21,9 +21,6 @@ #undef _XOPEN_SOURCE #endif #include -#if defined(TARGET_OSX) -#define _XOPEN_SOURCE -#endif //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// // LowLevelMonitor - Represents a non-recursive mutex and condition diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_digest.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_digest.c index dba8026dd3154..b2b89be4e6644 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_digest.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_digest.c @@ -167,7 +167,7 @@ int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pB { return -1; } - CC_SHA1(pBuf, cbBuf, pOutput); + CC_SHA1(pBuf, (CC_LONG)cbBuf, pOutput); return 1; case PAL_SHA256: *pcbDigest = CC_SHA256_DIGEST_LENGTH; @@ -175,7 +175,7 @@ int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pB { return -1; } - CC_SHA256(pBuf, cbBuf, pOutput); + CC_SHA256(pBuf, (CC_LONG)cbBuf, pOutput); return 1; case PAL_SHA384: *pcbDigest = CC_SHA384_DIGEST_LENGTH; @@ -183,7 +183,7 @@ int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pB { return -1; } - CC_SHA384(pBuf, cbBuf, pOutput); + CC_SHA384(pBuf, (CC_LONG)cbBuf, pOutput); return 1; case PAL_SHA512: *pcbDigest = CC_SHA512_DIGEST_LENGTH; @@ -191,7 +191,7 @@ int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pB { return -1; } - CC_SHA512(pBuf, cbBuf, pOutput); + CC_SHA512(pBuf, (CC_LONG)cbBuf, pOutput); return 1; case PAL_MD5: *pcbDigest = CC_MD5_DIGEST_LENGTH; @@ -201,7 +201,7 @@ int32_t AppleCryptoNative_DigestOneShot(PAL_HashAlgorithm algorithm, uint8_t* pB } #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" - CC_MD5(pBuf, cbBuf, pOutput); + CC_MD5(pBuf, (CC_LONG)cbBuf, pOutput); #pragma clang diagnostic pop return 1; default: @@ -233,6 +233,4 @@ int32_t AppleCryptoNative_DigestReset(DigestCtx* ctx) assert(false); return -2; } - - return 1; } diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_hmac.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_hmac.c index 4ffbc2f094d9b..6dfc1067d2f06 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_hmac.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_hmac.c @@ -142,6 +142,6 @@ int32_t AppleCryptoNative_HmacOneShot(PAL_HashAlgorithm algorithm, if (cbOutput < *pcbDigest) return -1; - CCHmac(ccAlgorithm, pKey, cbKey, pBuf, cbBuf, pOutput); + CCHmac(ccAlgorithm, pKey, (size_t)cbKey, pBuf, (size_t)cbBuf, pOutput); return 1; } diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keychain_ios.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keychain_ios.c index a666297f04d68..8139fd6260736 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keychain_ios.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keychain_ios.c @@ -96,12 +96,12 @@ int32_t AppleCryptoNative_X509StoreRemoveCertificate(CFTypeRef certOrIdentity, u assert(certOrIdentity != NULL); - const void* keys[] = {kSecValueRef}; - const void* values[] = {certOrIdentity}; + const void* keys1[] = {kSecValueRef}; + const void* values1[] = {certOrIdentity}; CFDictionaryRef query = CFDictionaryCreate(kCFAllocatorDefault, - keys, - values, - sizeof(keys) / sizeof(*keys), + keys1, + values1, + sizeof(keys1) / sizeof(*keys1), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); @@ -143,12 +143,12 @@ int32_t AppleCryptoNative_X509StoreRemoveCertificate(CFTypeRef certOrIdentity, u { OSStatus keyStatus; - const void* keys[] = {kSecClass, kSecAttrPublicKeyHash}; - const void* values[] = {kSecClassCertificate, publicKeyLabel}; + const void* keys2[] = {kSecClass, kSecAttrPublicKeyHash}; + const void* values2[] = {kSecClassCertificate, publicKeyLabel}; query = CFDictionaryCreate(kCFAllocatorDefault, - keys, - values, - sizeof(keys) / sizeof(*keys), + keys2, + values2, + sizeof(keys2) / sizeof(*keys2), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); @@ -170,12 +170,12 @@ int32_t AppleCryptoNative_X509StoreRemoveCertificate(CFTypeRef certOrIdentity, u if (keyStatus == errSecItemNotFound) { - const void* keys[] = {kSecClass, kSecAttrApplicationLabel}; - const void* values[] = {kSecClassKey, publicKeyLabel}; + const void* keys3[] = {kSecClass, kSecAttrApplicationLabel}; + const void* values3[] = {kSecClassKey, publicKeyLabel}; query = CFDictionaryCreate(kCFAllocatorDefault, - keys, - values, - sizeof(keys) / sizeof(*keys), + keys3, + values3, + sizeof(keys3) / sizeof(*keys3), &kCFTypeDictionaryKeyCallBacks, &kCFTypeDictionaryValueCallBacks); diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.c index 753d30d31d48b..9d3838be54700 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.c @@ -35,7 +35,7 @@ int32_t AppleCryptoNative_Pbkdf2(PAL_HashAlgorithm prfAlgorithm, int32_t saltLen, int32_t iterations, uint8_t* derivedKey, - uint32_t derivedKeyLen, + int32_t derivedKeyLen, int32_t* errorCode) { if (errorCode != NULL) @@ -73,8 +73,8 @@ int32_t AppleCryptoNative_Pbkdf2(PAL_HashAlgorithm prfAlgorithm, return -2; } - CCStatus result = CCKeyDerivationPBKDF(kCCPBKDF2, password, passwordLen, salt, - saltLen, prf, iterations, derivedKey, derivedKeyLen); + CCStatus result = CCKeyDerivationPBKDF(kCCPBKDF2, password, (size_t)passwordLen, salt, + (size_t)saltLen, prf, (uint32_t)iterations, derivedKey, (size_t)derivedKeyLen); *errorCode = result; return result == kCCSuccess ? 1 : 0; } diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.h b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.h index 7f02f0aa13c3f..dfd06fd190b21 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.h +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_keyderivation.h @@ -34,5 +34,5 @@ PALEXPORT int32_t AppleCryptoNative_Pbkdf2(PAL_HashAlgorithm prfAlgorithm, int32_t saltLen, int32_t iterations, uint8_t* derivedKey, - uint32_t derivedKeyLen, + int32_t derivedKeyLen, int32_t* errorCode); diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_signverify.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_signverify.c index 37f61c7b1215a..e7aac896311f5 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_signverify.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_signverify.c @@ -103,7 +103,7 @@ static int32_t ConfigureSignVerifyTransform(SecTransformRef xform, CFDataRef cfD #endif // Legacy algorithm identifiers -const SecKeyAlgorithm kSecKeyAlgorithmRSASignatureDigestPKCS1v15MD5 = CFSTR("algid:sign:RSA:digest-PKCS1v15:MD5"); +static const SecKeyAlgorithm kSecKeyAlgorithmRSASignatureDigestPKCS1v15MD5 = CFSTR("algid:sign:RSA:digest-PKCS1v15:MD5"); static CFStringRef GetSignatureAlgorithmIdentifier(PAL_HashAlgorithm hashAlgorithm, PAL_SignatureAlgorithm signatureAlgorithm) diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_ssl.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_ssl.c index 9b44cbbef8e09..2fba375bd423e 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_ssl.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_ssl.c @@ -262,7 +262,7 @@ int32_t AppleCryptoNative_SSLSetALPNProtocol(SSLContextRef sslContext, void* pro // This is extra consistency check to verify that the ALPN data appeared where we expect them // before dereferencing sslContext - if (tls != NULL && tls->alpnOwnData.length == length + 1) + if (tls != NULL && tls->alpnOwnData.length == (size_t)length + 1) { tls->alpn_announced = 1; tls->alpn_received = 1 ; @@ -700,10 +700,14 @@ PALEXPORT int32_t AppleCryptoNative_SslSetCertificateAuthorities(SSLContextRef s #pragma clang diagnostic push #pragma clang diagnostic ignored "-Wdeprecated-declarations" // The underlying call handles NULL inputs, so just pass it through - return SSLSetCertificateAuthorities(sslContext, certificates, replaceExisting); + return SSLSetCertificateAuthorities(sslContext, certificates, replaceExisting > 0 ? 1 : 0); #pragma clang diagnostic pop #else + // ignore unused parameters + (void)sslContext; + (void)certificates; + (void)replaceExisting; return 0; #endif } diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509_ios.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509_ios.c index 8ffa1751e1325..600ed61e0a56c 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509_ios.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509_ios.c @@ -70,7 +70,10 @@ int32_t AppleCryptoNative_X509ImportCertificate(uint8_t* pbData, if (CFArrayGetCount(p12Items) > 0) { CFDictionaryRef item_dict = CFArrayGetValueAtIndex(p12Items, 0); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-qual" *pIdentityOut = (SecIdentityRef)CFRetain(CFDictionaryGetValue(item_dict, kSecImportItemIdentity)); +#pragma clang diagnostic pop } CFRelease(p12Items); } @@ -167,8 +170,11 @@ int32_t AppleCryptoNative_X509ImportCollection(uint8_t* pbData, for (int i = 0; i < CFArrayGetCount(p12Items); i++) { CFDictionaryRef item_dict = CFArrayGetValueAtIndex(p12Items, i); +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Wcast-qual" SecIdentityRef identity = (SecIdentityRef)CFRetain(CFDictionaryGetValue(item_dict, kSecImportItemIdentity)); +#pragma clang diagnostic pop assert(identity != NULL); CFArrayAppendValue(outItems, identity); } @@ -179,4 +185,4 @@ int32_t AppleCryptoNative_X509ImportCollection(uint8_t* pbData, return status; } -} \ No newline at end of file +} diff --git a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509chain.c b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509chain.c index de1a84f26798d..5f84bd898c3ac 100644 --- a/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509chain.c +++ b/src/native/libs/System.Security.Cryptography.Native.Apple/pal_x509chain.c @@ -207,7 +207,7 @@ static void MergeStatusCodes(CFTypeRef key, CFTypeRef value, void* context) #if defined DEBUG || defined DEBUGGING_UNKNOWN_VALUE CFIndex keyStringLength = CFStringGetLength(keyString); CFIndex maxEncodedLength = CFStringGetMaximumSizeForEncoding(keyStringLength, kCFStringEncodingUTF8) + 1; - char* keyStringBuffer = malloc(maxEncodedLength); + char* keyStringBuffer = malloc((size_t)maxEncodedLength); if (keyStringBuffer) { diff --git a/src/native/libs/configure.cmake b/src/native/libs/configure.cmake index 55e794b42769b..bba930e0c0072 100644 --- a/src/native/libs/configure.cmake +++ b/src/native/libs/configure.cmake @@ -13,6 +13,7 @@ if (CLR_CMAKE_TARGET_OSX) # Xcode's clang does not include /usr/local/include by default, but brew's does. # This ensures an even playing field. include_directories(SYSTEM /usr/local/include) + add_compile_options(-Wno-poison-system-directories) elseif (CLR_CMAKE_TARGET_FREEBSD) include_directories(SYSTEM ${CROSS_ROOTFS}/usr/local/include) set(CMAKE_REQUIRED_INCLUDES ${CROSS_ROOTFS}/usr/local/include) @@ -33,7 +34,7 @@ endif() # which are not distinguished from the test failing. So no error for that one. # For clang-5.0 avoid errors like "unused variable 'err' [-Werror,-Wunused-variable]". set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Werror -Wno-error=unused-value -Wno-error=unused-variable") -if (CMAKE_C_COMPILER_ID STREQUAL "Clang") +if (CMAKE_C_COMPILER_ID MATCHES "Clang") set(CMAKE_REQUIRED_FLAGS "${CMAKE_REQUIRED_FLAGS} -Wno-error=builtin-requires-header") endif() diff --git a/src/native/minipal/getexepath.h b/src/native/minipal/getexepath.h index 601447a1af215..d9b6bdd85bdf4 100644 --- a/src/native/minipal/getexepath.h +++ b/src/native/minipal/getexepath.h @@ -37,7 +37,11 @@ static inline char* minipal_getexepath(void) return NULL; } +#pragma clang diagnostic push +#pragma clang diagnostic ignored "-Walloca" char* path_buf = (char*)alloca(path_length); +#pragma clang diagnostic pop + if (_NSGetExecutablePath(path_buf, &path_length) != 0) { errno = EINVAL; diff --git a/src/native/minipal/random.c b/src/native/minipal/random.c index bde7edc47d117..20fcc07802e65 100644 --- a/src/native/minipal/random.c +++ b/src/native/minipal/random.c @@ -80,16 +80,12 @@ int32_t minipal_get_cryptographically_secure_random_bytes(uint8_t* buffer, int32 return 0; } #elif defined(__APPLE__) && __APPLE__ - CCRNGStatus status = CCRandomGenerateBytes(buffer, bufferLength); + CCRNGStatus status = CCRandomGenerateBytes(buffer, (size_t)bufferLength); if (status == kCCSuccess) { return 0; } - else - { - return -1; - } #else static volatile int rand_des = -1;