Index: ObjFW.xcodeproj/project.pbxproj ================================================================== --- ObjFW.xcodeproj/project.pbxproj +++ ObjFW.xcodeproj/project.pbxproj @@ -915,22 +915,25 @@ isa = XCBuildConfiguration; buildSettings = { GCC_OPTIMIZATION_LEVEL = 2; GCC_VERSION = 4.2; OTHER_CFLAGS = ( - "-Wall", "-fexceptions", "-fobjc-exceptions", "-fconstant-string-class=OFConstantString", - "-pipe", + "-fno-constant-cfstrings", "-fno-common", - "-fno-constant-cfstrings", "-fblocks", + "-pipe", + ); + WARNING_CFLAGS = ( + "-Wall", + "-Werror", + "-Wshorten-64-to-32", "-Wwrite-strings", "-Wcast-align", "-Wpointer-arith", - "-Werror", ); }; name = Debug; }; 1DEB919508733D9F0010E9CD /* Release */ = { @@ -937,22 +940,25 @@ isa = XCBuildConfiguration; buildSettings = { GCC_OPTIMIZATION_LEVEL = 2; GCC_VERSION = 4.2; OTHER_CFLAGS = ( - "-Wall", "-fexceptions", "-fobjc-exceptions", "-fconstant-string-class=OFConstantString", - "-pipe", + "-fno-constant-cfstrings", "-fno-common", - "-fno-constant-cfstrings", "-fblocks", + "-pipe", + ); + WARNING_CFLAGS = ( + "-Wall", + "-Werror", + "-Wshorten-64-to-32", "-Wwrite-strings", "-Wcast-align", "-Wpointer-arith", - "-Werror", ); }; name = Release; }; 4B23CA8C133811610047A1D9 /* Debug */ = { Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -475,12 +475,12 @@ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") ]) ]) AS_IF([test x"$GOBJC" = x"yes"], [ - OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wcast-align -Wpointer-arith" - OBJCFLAGS="$OBJCFLAGS -Werror" + OBJCFLAGS="$OBJCFLAGS -Wwrite-strings -Wshorten-64-to-32 -Wcast-align" + OBJCFLAGS="$OBJCFLAGS -Wpointer-arith -Werror" AC_MSG_CHECKING(whether gcc has bug objc/27438) AC_TRY_COMPILE([ @interface OFConstantString { Index: src/OFArray.m ================================================================== --- src/OFArray.m +++ src/OFArray.m @@ -422,18 +422,21 @@ objects: (id*)objects count: (int)count_ { size_t count = [array count]; + if (count > INT_MAX) + @throw [OFOutOfRangeException newWithClass: isa]; + if (state->state >= count) return 0; state->state = count; state->itemsPtr = [array cArray]; state->mutationsPtr = (unsigned long*)self; - return count; + return (int)count; } - (OFEnumerator*)objectEnumerator { return [[[OFArrayEnumerator alloc] Index: src/OFDictionary.m ================================================================== --- src/OFDictionary.m +++ src/OFDictionary.m @@ -182,12 +182,11 @@ { self = [super init]; @try { id *objs_carray, *keys_carray; - size_t i, nsize; - uint32_t j; + uint32_t i, j, nsize; keys_carray = [keys cArray]; objs_carray = [objs cArray]; count = [keys count]; @@ -313,12 +312,11 @@ { self = [super init]; @try { id obj; - size_t i, nsize; - uint32_t j, hash; + uint32_t i, j, hash, nsize; va_list args2; BUCKET *b; va_copy(args2, args); Index: src/OFHTTPRequest.m ================================================================== --- src/OFHTTPRequest.m +++ src/OFHTTPRequest.m @@ -198,12 +198,12 @@ if (![line hasPrefix: @"HTTP/1.0 "] && ![line hasPrefix: @"HTTP/1.1 "]) @throw [OFInvalidServerReplyException newWithClass: isa]; - status = [[line substringFromIndex: 9 - toIndex: 12] decimalValue]; + status = (int)[[line substringFromIndex: 9 + toIndex: 12] decimalValue]; if (status != 200 && status != 301 && status != 302 && status != 303) @throw [OFHTTPRequestFailedException newWithClass: isa Index: src/OFMD5Hash.m ================================================================== --- src/OFMD5Hash.m +++ src/OFMD5Hash.m @@ -158,11 +158,11 @@ /* Update bitcount */ t = bits[0]; if ((bits[0] = t + ((uint32_t)size << 3)) < t) /* Carry from low to high */ bits[1]++; - bits[1] += size >> 29; + bits[1] += (uint32_t)size >> 29; /* Bytes already in shsInfo->data */ t = (t >> 3) & 0x3F; /* Handle any leading odd-sized chunks */ Index: src/OFMutableArray.m ================================================================== --- src/OFMutableArray.m +++ src/OFMutableArray.m @@ -205,18 +205,21 @@ objects: (id*)objects count: (int)count_ { size_t count = [array count]; + if (count > INT_MAX) + @throw [OFOutOfRangeException newWithClass: isa]; + if (state->state >= count) return 0; state->state = count; state->itemsPtr = [array cArray]; state->mutationsPtr = &mutations; - return count; + return (int)count; } - (OFEnumerator*)objectEnumerator { return [[[OFArrayEnumerator alloc] Index: src/OFMutableDictionary.m ================================================================== --- src/OFMutableDictionary.m +++ src/OFMutableDictionary.m @@ -28,13 +28,12 @@ @implementation OFMutableDictionary - (void)_resizeForCount: (size_t)newcount { size_t fill = newcount * 4 / size; - size_t newsize; struct of_dictionary_bucket **newdata; - uint32_t i; + uint32_t i, newsize; if (newcount > UINT32_MAX) @throw [OFOutOfRangeException newWithClass: isa]; if (fill >= 3) Index: src/OFObject.h ================================================================== --- src/OFObject.h +++ src/OFObject.h @@ -23,10 +23,11 @@ # define __STDC_CONSTANT_MACROS #endif #include #include +#include #ifdef OF_OBJFW_RUNTIME # import #else # import Index: src/OFObject.m ================================================================== --- src/OFObject.m +++ src/OFObject.m @@ -18,11 +18,10 @@ #include #include #include #include -#include #include #import "OFObject.h" #import "OFAutoreleasePool.h" #import "OFExceptions.h" Index: src/OFStreamObserver.h ================================================================== --- src/OFStreamObserver.h +++ src/OFStreamObserver.h @@ -79,11 +79,11 @@ OFMutableDictionary *fdToStream; #else fd_set readfds; fd_set writefds; fd_set exceptfds; - int nfds; + nfds_t nfds; #endif } #ifdef OF_HAVE_PROPERTIES @property (retain) id delegate; Index: src/OFStreamObserver.m ================================================================== --- src/OFStreamObserver.m +++ src/OFStreamObserver.m @@ -237,11 +237,15 @@ BOOL foundInCache = NO; OFStream **cArray; size_t i, count; #ifdef OF_HAVE_POLL struct pollfd *fds_c = [fds cArray]; - size_t nfds = [fds count]; + /* + * There is no way to find out the maximum number of fds, so we just + * cast. + */ + nfds_t nfds = (nfds_t)[fds count]; #else fd_set readfds_; fd_set writefds_; fd_set exceptfds_; struct timeval tv; Index: src/OFString.h ================================================================== --- src/OFString.h +++ src/OFString.h @@ -50,16 +50,13 @@ /** * \brief A class for handling strings. */ @interface OFString: OFObject { - char *string; - unsigned int length; -#if defined(OF_APPLE_RUNTIME) && __LP64__ - int _unused; -#endif - BOOL isUTF8; + char *string; + size_t length; + BOOL isUTF8; } /** * \return A new autoreleased OFString */ Index: src/OFThread.m ================================================================== --- src/OFThread.m +++ src/OFThread.m @@ -105,13 +105,19 @@ { if (sec < 0) @throw [OFOutOfRangeException newWithClass: self]; #ifndef _WIN32 - sleep(sec); + if (sec > UINT_MAX) + @throw [OFOutOfRangeException newWithClass: self]; + + sleep((unsigned int)sec); #else - Sleep(sec * 1000); + if (sec * 1000 > UINT_MAX) + @throw [OFOutOfRangeException newWithClass: self]; + + Sleep((unsigned int)sec * 1000); #endif } + (void)sleepForTimeInterval: (int64_t)sec microseconds: (uint32_t)usec @@ -118,14 +124,17 @@ { if (sec < 0) @throw [OFOutOfRangeException newWithClass: self]; #ifndef _WIN32 - sleep(sec); + sleep((unsigned int)sec); usleep(usec); #else - Sleep(sec * 1000 + usec / 1000); + if (sec * 1000 + usec / 1000 > UINT_MAX) + @throw [OFOutOfRangeException newWithClass: self]; + + Sleep((unsigned int)sec * 1000 + usec / 1000); #endif } + (void)sleepUntilDate: (OFDate*)date { @@ -140,13 +149,19 @@ usec = [date microsecondsOfTimeIntervalSinceDate: now]; [pool release]; #ifndef _WIN32 - sleep(sec); + if (sec > UINT_MAX) + @throw [OFOutOfRangeException newWithClass: self]; + + sleep((unsigned int)sec); usleep(usec); #else + if (sec * 1000 + usec / 1000 > UINT_MAX) + @throw [OFOutOfRangeException newWithClass: self]; + Sleep(sec * 1000 + usec / 1000); #endif } + (void)yield Index: src/of_asprintf.m ================================================================== --- src/of_asprintf.m +++ src/of_asprintf.m @@ -19,11 +19,10 @@ #define _GNU_SOURCE #include #include #include #include -#include #include #import "OFString.h" #import "OFAutoreleasePool.h" #import "asprintf.h" @@ -395,32 +394,35 @@ break; case 'n': switch (ctx->len_mod) { case LENGTH_MODIFIER_NONE: - *va_arg(ctx->args, int*) = ctx->buf_len; + *va_arg(ctx->args, int*) = (int)ctx->buf_len; break; case LENGTH_MODIFIER_HH: - *va_arg(ctx->args, signed char*) = ctx->buf_len; + *va_arg(ctx->args, signed char*) = + (signed char)ctx->buf_len; break; case LENGTH_MODIFIER_H: - *va_arg(ctx->args, short*) = ctx->buf_len; + *va_arg(ctx->args, short*) = (short)ctx->buf_len; break; case LENGTH_MODIFIER_L: - *va_arg(ctx->args, long*) = ctx->buf_len; + *va_arg(ctx->args, long*) = (long)ctx->buf_len; break; case LENGTH_MODIFIER_LL: - *va_arg(ctx->args, long long*) = ctx->buf_len; + *va_arg(ctx->args, long long*) = + (long long)ctx->buf_len; break; case LENGTH_MODIFIER_J: - *va_arg(ctx->args, intmax_t*) = ctx->buf_len; + *va_arg(ctx->args, intmax_t*) = (intmax_t)ctx->buf_len; break; case LENGTH_MODIFIER_Z: *va_arg(ctx->args, size_t*) = ctx->buf_len; break; case LENGTH_MODIFIER_T: - *va_arg(ctx->args, ptrdiff_t*) = ctx->buf_len; + *va_arg(ctx->args, ptrdiff_t*) = + (ptrdiff_t)ctx->buf_len; break; default: return false; } @@ -503,11 +505,11 @@ } ctx.buf[ctx.buf_len] = 0; *ret = ctx.buf; - return ctx.buf_len; + return (ctx.buf_len <= INT_MAX ? (int)ctx.buf_len : INT_MAX); } int of_asprintf(char **ret, const char *fmt, ...) { Index: tests/OFTCPSocketTests.m ================================================================== --- tests/OFTCPSocketTests.m +++ tests/OFTCPSocketTests.m @@ -37,11 +37,11 @@ OFTCPSocket *server, *client = nil, *accepted; OFString *msg; uint16_t port; char buf[6]; - srand(time(NULL)); + srand((unsigned)time(NULL)); port = (uint16_t)rand(); if (port < 1024) port += 1024; TEST(@"+[socket]", (server = [OFTCPSocket socket]) &&