From d7850617d5a0ec2391635cebf5d50477cde267ae Mon Sep 17 00:00:00 2001 From: Jens Ayton Date: Mon, 27 Aug 2012 18:57:41 +0000 Subject: [PATCH] Estranged nephew of more truncation fixes. git-svn-id: http://svn.berlios.de/svnroot/repos/oolite-linux/trunk@5265 127b21dd-08f5-0310-b4b7-95ae10353056 --- src/Core/Debug/OODebugMonitor.m | 2 +- src/Core/Debug/OODebugTCPConsoleClient.m | 24 ++++------------ src/Core/Debug/OOJSConsole.m | 6 ++-- src/Core/Entities/PlayerEntity.m | 2 -- src/Core/Materials/OOPlanetTextureGenerator.m | 6 ++-- src/Core/Materials/OOShaderUniform.m | 4 +-- src/Core/OOCPUInfo.h | 2 +- src/Core/OOCPUInfo.m | 2 +- src/Core/OOConvertSystemDescriptions.m | 4 +-- src/Core/OOMesh.m | 2 +- src/Core/OOOpenGLExtensionManager.m | 8 +++--- src/Core/OOProbabilisticTextureManager.m | 2 +- src/Core/OORoleSet.m | 2 +- src/Core/OOShipRegistry.m | 2 +- .../OOCheckEquipmentPListVerifierStage.m | 6 ++-- .../OOCheckShipDataPListVerifierStage.m | 2 +- src/Core/OXPVerifier/OOPListSchemaVerifier.m | 28 +++++++++---------- src/Core/OXPVerifier/OOTextureVerifierStage.m | 4 +-- src/Core/OldSchoolPropertyListWriting.m | 2 +- src/Core/Scripting/OOJSEquipmentInfo.m | 7 ++--- src/Core/Scripting/OOJSFunction.m | 7 +++-- src/Core/Scripting/OOJSMissionVariables.m | 4 ++- src/Core/Scripting/OOJSOolite.m | 2 +- src/Core/Scripting/OOJSPlayer.m | 4 +-- src/Core/Scripting/OOJSShip.m | 12 +++++--- src/Core/Scripting/OOJSStation.m | 2 +- src/Core/Scripting/OOJSSystemInfo.m | 4 ++- 27 files changed, 73 insertions(+), 79 deletions(-) diff --git a/src/Core/Debug/OODebugMonitor.m b/src/Core/Debug/OODebugMonitor.m index 6b69c3f1..e459efda 100644 --- a/src/Core/Debug/OODebugMonitor.m +++ b/src/Core/Debug/OODebugMonitor.m @@ -505,7 +505,7 @@ typedef struct for (texEnum = [allTextures objectEnumerator]; (tex = [texEnum nextObject]); ) { // We subtract one because allTextures retains the textures. - [textureRefCounts setObject:[NSNumber numberWithUnsignedInt:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]]; + [textureRefCounts setObject:[NSNumber numberWithUnsignedInteger:[tex retainCount] - 1] forKey:[NSValue valueWithNonretainedObject:tex]]; } size_t totalSize = 0; diff --git a/src/Core/Debug/OODebugTCPConsoleClient.m b/src/Core/Debug/OODebugTCPConsoleClient.m index 041edf65..54c8b441 100644 --- a/src/Core/Debug/OODebugTCPConsoleClient.m +++ b/src/Core/Debug/OODebugTCPConsoleClient.m @@ -242,8 +242,8 @@ OOINLINE BOOL StatusIsSendable(OOTCPClientConnectionStatus status) if (emphasisRange.length != 0) { range = [NSArray arrayWithObjects: - [NSNumber numberWithUnsignedInt:emphasisRange.location], - [NSNumber numberWithUnsignedInt:emphasisRange.length], + [NSNumber numberWithUnsignedInteger:emphasisRange.location], + [NSNumber numberWithUnsignedInteger:emphasisRange.length], nil]; [parameters setObject:range forKey:kOOTCPEmphasisRanges]; } @@ -338,14 +338,12 @@ noteChangedConfigrationValue:(in id)newValue - (BOOL) sendBytes:(const void *)bytes count:(size_t)count { - int written; - if (bytes == NULL || count == 0) return YES; if (!StatusIsSendable(_status) || _outStream == nil) return NO; do { - written = [_outStream write:bytes maxLength:count]; + OOInteger written = [_outStream write:bytes maxLength:count]; if (written < 1) return NO; count -= written; @@ -471,24 +469,12 @@ noteChangedConfigrationValue:(in id)newValue enum { kBufferSize = 16 << 10 }; uint8_t buffer[kBufferSize]; - int length; + OOInteger length; NSData *data; length = [_inStream read:buffer maxLength:kBufferSize]; - while( length > 0 ) + while (length > 0) { - /* This test is superfluous after the rewrite to fix Bug#014643 - * TODO: Put the BadStream test back into the code - if (length < 1) - { - // Under GNUstep, but not OS X (currently), -hasBytesAvailable will return YES when the buffer is in fact empty. - if ([_inStream streamStatus] == NSStreamStatusReading) break; - - [self breakConnectionWithBadStream:_inStream]; - return; - } - */ - data = [NSData dataWithBytesNoCopy:buffer length:length freeWhenDone:NO]; OOTCPStreamDecoderReceiveData(_decoder, data); length = [_inStream read:buffer maxLength:kBufferSize]; diff --git a/src/Core/Debug/OOJSConsole.m b/src/Core/Debug/OOJSConsole.m index 43c0398f..11e93bc8 100644 --- a/src/Core/Debug/OOJSConsole.m +++ b/src/Core/Debug/OOJSConsole.m @@ -315,7 +315,7 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID { #ifndef NDEBUG case kConsole_debugFlags: - *value = INT_TO_JSVAL(gDebugFlags); + *value = INT_TO_JSVAL((uint32_t)gDebugFlags); break; #endif @@ -372,11 +372,11 @@ static JSBool ConsoleGetProperty(JSContext *context, JSObject *this, jsid propID break; case kConsole_glFixedFunctionTextureUnitCount: - *value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureUnitCount]); + *value = INT_TO_JSVAL((uint32_t)[[OOOpenGLExtensionManager sharedManager] textureUnitCount]); break; case kConsole_glFragmentShaderTextureUnitCount: - *value = INT_TO_JSVAL([[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]); + *value = INT_TO_JSVAL((uint32_t)[[OOOpenGLExtensionManager sharedManager] textureImageUnitCount]); break; #define DEBUG_FLAG_CASE(x) case kConsole_##x: *value = INT_TO_JSVAL(x); break; diff --git a/src/Core/Entities/PlayerEntity.m b/src/Core/Entities/PlayerEntity.m index 61098628..5b53f838 100644 --- a/src/Core/Entities/PlayerEntity.m +++ b/src/Core/Entities/PlayerEntity.m @@ -298,8 +298,6 @@ static GLfloat sBaseMass = 0.0; [shipCommodityData release]; shipCommodityData = manifest; - //[cargo removeAllObjects]; // empty the hold - not needed, done individually inside unloadAllCargoPodsForType - [self calculateCurrentCargo]; // work out the correct value for current_cargo } diff --git a/src/Core/Materials/OOPlanetTextureGenerator.m b/src/Core/Materials/OOPlanetTextureGenerator.m index 3117ca14..e821bb8b 100644 --- a/src/Core/Materials/OOPlanetTextureGenerator.m +++ b/src/Core/Materials/OOPlanetTextureGenerator.m @@ -736,7 +736,7 @@ OOINLINE float Hermite(float q) } -#if __BIG_ENDIAN_ +#if __BIG_ENDIAN__ #define iman_ 1 #else #define iman_ 0 @@ -744,10 +744,10 @@ OOINLINE float Hermite(float q) // (same behaviour as, but faster than, FLOAT->INT) //Works OK for -32728 to 32727.99999236688 -OOINLINE long fast_floor(double val) +OOINLINE int32_t fast_floor(double val) { val += 68719476736.0 * 1.5; - return (((long*)&val)[iman_] >> 16); + return (((int32_t*)&val)[iman_] >> 16); } diff --git a/src/Core/Materials/OOShaderUniform.m b/src/Core/Materials/OOShaderUniform.m index 708b1fb0..bf55c875 100644 --- a/src/Core/Materials/OOShaderUniform.m +++ b/src/Core/Materials/OOShaderUniform.m @@ -321,7 +321,7 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type) { BOOL OK = YES; NSMethodSignature *signature = nil; - unsigned argCount; + OOUInteger argCount; NSString *methodProblem = nil; id superCandidate = nil; @@ -496,7 +496,7 @@ OOINLINE BOOL ValidBindingType(OOShaderUniformType type) case kOOShaderUniformTypeUnsignedInt: case kOOShaderUniformTypeLong: case kOOShaderUniformTypeUnsignedLong: - iVal = OOCallIntegerMethod(object, value.binding.selector, value.binding.method, type); + iVal = (GLint)OOCallIntegerMethod(object, value.binding.selector, value.binding.method, type); isInt = YES; break; diff --git a/src/Core/OOCPUInfo.h b/src/Core/OOCPUInfo.h index e0f61f23..64818b62 100644 --- a/src/Core/OOCPUInfo.h +++ b/src/Core/OOCPUInfo.h @@ -34,7 +34,7 @@ void OOCPUInfoInit(void); /* Number of processors (whether they be individual or cores), used to select number of threads to use for things like texture loading. */ -unsigned OOCPUCount(void); +OOUInteger OOCPUCount(void); /* Set up OOLITE_BIG_ENDIAN and OOLITE_LITTLE_ENDIAN macros. Exactly one must diff --git a/src/Core/OOCPUInfo.m b/src/Core/OOCPUInfo.m index 4aa395fb..0b5b6843 100644 --- a/src/Core/OOCPUInfo.m +++ b/src/Core/OOCPUInfo.m @@ -98,7 +98,7 @@ void OOCPUInfoInit(void) } -unsigned OOCPUCount(void) +OOUInteger OOCPUCount(void) { if (!sInited) OOCPUInfoInit(); return (sNumberOfCPUs != 0) ? sNumberOfCPUs : 1; diff --git a/src/Core/OOConvertSystemDescriptions.m b/src/Core/OOConvertSystemDescriptions.m index 9e5e75b2..194a0af0 100644 --- a/src/Core/OOConvertSystemDescriptions.m +++ b/src/Core/OOConvertSystemDescriptions.m @@ -186,7 +186,7 @@ NSArray *OOConvertSystemDescriptionsToArrayFormat(NSDictionary *descriptionsInDi realResult = [NSMutableArray arrayWithCapacity:count]; for (i = 0; i < count; i++) { - entry = [result objectForKey:[NSNumber numberWithUnsignedInt:i]]; + entry = [result objectForKey:[NSNumber numberWithUnsignedInteger:i]]; if (entry == nil) entry = [NSArray array]; [realResult addObject:entry]; } @@ -323,7 +323,7 @@ static NSNumber *KeyToIndex(NSString *key, NSMutableDictionary *ioKeysToIndices, // Search for free index do { - result = [NSNumber numberWithUnsignedInt:(*ioSlotCache)++]; + result = [NSNumber numberWithUnsignedInteger:(*ioSlotCache)++]; } while ([ioUsedIndicies containsObject:result]); diff --git a/src/Core/OOMesh.m b/src/Core/OOMesh.m index 1b74f9d0..984996c1 100644 --- a/src/Core/OOMesh.m +++ b/src/Core/OOMesh.m @@ -2235,7 +2235,7 @@ static void VFRAddFace(VertexFaceRef *vfr, OOUInteger index) else { if (vfr->extra == nil) vfr->extra = [NSMutableArray array]; - [vfr->extra addObject:[NSNumber numberWithInt:index]]; + [vfr->extra addObject:[NSNumber numberWithInteger:index]]; } } diff --git a/src/Core/OOOpenGLExtensionManager.m b/src/Core/OOOpenGLExtensionManager.m index 2f3a7a4e..e0990da7 100644 --- a/src/Core/OOOpenGLExtensionManager.m +++ b/src/Core/OOOpenGLExtensionManager.m @@ -261,8 +261,8 @@ static NSArray *ArrayOfExtensions(NSString *extensionString) maximumShaderSetting = SHADERS_NOT_SUPPORTED; } - GLint texImageUnitOverride = [gpuConfig oo_unsignedIntegerForKey:@"texture_image_units" defaultValue:textureImageUnitCount]; - if (texImageUnitOverride < textureImageUnitCount) textureImageUnitCount = texImageUnitOverride; + GLint texImageUnitOverride = [gpuConfig oo_intForKey:@"texture_image_units" defaultValue:textureImageUnitCount]; + if (texImageUnitOverride < textureImageUnitCount) textureImageUnitCount = MAX(texImageUnitOverride, 0); #endif #if OO_USE_VBO @@ -273,8 +273,8 @@ static NSArray *ArrayOfExtensions(NSString *extensionString) #endif #if OO_MULTITEXTURE [self checkTextureCombinersSupported]; - GLint texUnitOverride = [gpuConfig oo_unsignedIntegerForKey:@"texture_units" defaultValue:textureUnitCount]; - if (texUnitOverride < textureUnitCount) textureUnitCount = texUnitOverride; + GLint texUnitOverride = [gpuConfig oo_intForKey:@"texture_units" defaultValue:textureUnitCount]; + if (texUnitOverride < textureUnitCount) textureUnitCount = MAX(texUnitOverride, 0); #endif usePointSmoothing = [gpuConfig oo_boolForKey:@"smooth_points" defaultValue:YES]; diff --git a/src/Core/OOProbabilisticTextureManager.m b/src/Core/OOProbabilisticTextureManager.m index 420de00d..e3b1381d 100644 --- a/src/Core/OOProbabilisticTextureManager.m +++ b/src/Core/OOProbabilisticTextureManager.m @@ -54,7 +54,7 @@ SOFTWARE. { BOOL OK = YES; NSArray *config = nil; - unsigned i, count; + OOUInteger i, count; id entry = nil; NSString *name = nil; float probability; diff --git a/src/Core/OORoleSet.m b/src/Core/OORoleSet.m index ee91a8f5..c267e7e0 100644 --- a/src/Core/OORoleSet.m +++ b/src/Core/OORoleSet.m @@ -316,7 +316,7 @@ NSDictionary *OOParseRolesFromString(NSString *string) { NSMutableDictionary *result = nil; NSArray *tokens = nil; - unsigned i, count; + OOUInteger i, count; NSString *role = nil; float probability; NSScanner *scanner = nil; diff --git a/src/Core/OOShipRegistry.m b/src/Core/OOShipRegistry.m index 551dd1a5..8eafada4 100644 --- a/src/Core/OOShipRegistry.m +++ b/src/Core/OOShipRegistry.m @@ -485,7 +485,7 @@ static NSString * const kVisualEffectDataCacheKey = @"visual effect data"; NSString *parentKey = nil; NSDictionary *shipEntry = nil; NSDictionary *parentEntry = nil; - unsigned count, lastCount; + OOUInteger count, lastCount; NSMutableArray *reportedBadShips = nil; // Build set of ships with like_ship references diff --git a/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m b/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m index 986985c2..458bdd2f 100644 --- a/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m +++ b/src/Core/OXPVerifier/OOCheckEquipmentPListVerifierStage.m @@ -96,7 +96,7 @@ static NSString * const kStageName = @"Checking equipment.plist"; NSEnumerator *entryEnum = nil; NSArray *entry = nil; unsigned entryIndex = 0; - unsigned elemCount; + OOUInteger elemCount; NSString *name = nil; NSString *entryDesc = nil; @@ -123,12 +123,12 @@ static NSString * const kStageName = @"Checking equipment.plist"; // Check that the entry has an acceptable number of elements. if (elemCount < 5) { - OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"***** ERROR: equipment.plist entry %@ has too few elements (%u, should be 5 or 6).", entryDesc, elemCount); + OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"***** ERROR: equipment.plist entry %@ has too few elements (%lu, should be 5 or 6).", entryDesc, elemCount); continue; } if (6 < elemCount) { - OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"----- WARNING: equipment.plist entry %@ has too many elements (%u, should be 5 or 6).", entryDesc, elemCount); + OOLog(@"verifyOXP.equipmentPList.badEntrySize", @"----- WARNING: equipment.plist entry %@ has too many elements (%lu, should be 5 or 6).", entryDesc, elemCount); } /* Check element types. The numbers are required to be unsigned diff --git a/src/Core/OXPVerifier/OOCheckShipDataPListVerifierStage.m b/src/Core/OXPVerifier/OOCheckShipDataPListVerifierStage.m index ab8b67cf..44f4da50 100644 --- a/src/Core/OXPVerifier/OOCheckShipDataPListVerifierStage.m +++ b/src/Core/OXPVerifier/OOCheckShipDataPListVerifierStage.m @@ -326,7 +326,7 @@ static NSString * const kStageName = @"Checking shipdata.plist"; { NSArray *parts = nil; NSMutableSet *result = nil; - unsigned i, count; + OOUInteger i, count; NSString *role = nil; NSRange parenRange; diff --git a/src/Core/OXPVerifier/OOPListSchemaVerifier.m b/src/Core/OXPVerifier/OOPListSchemaVerifier.m index 0dcd8906..146c06a1 100644 --- a/src/Core/OXPVerifier/OOPListSchemaVerifier.m +++ b/src/Core/OXPVerifier/OOPListSchemaVerifier.m @@ -121,9 +121,9 @@ OOINLINE BackLinkChain BackLink(BackLinkChain *link, id element) return result; } -OOINLINE BackLinkChain BackLinkIndex(BackLinkChain *link, unsigned index) +OOINLINE BackLinkChain BackLinkIndex(BackLinkChain *link, OOUInteger index) { - BackLinkChain result = { link, [NSNumber numberWithInt:index] }; + BackLinkChain result = { link, [NSNumber numberWithInteger:index] }; return result; } @@ -761,7 +761,7 @@ static NSString *ArrayForErrorReport(NSArray *array) { NSString *result = nil; NSString *string = nil; - unsigned i, count; + OOUInteger i, count; NSAutoreleasePool *pool = nil; count = [array count]; @@ -830,8 +830,8 @@ static NSError *Verify_String(OOPListSchemaVerifier *verifier, id value, NSDicti { NSString *filteredString = nil; id testValue = nil; - unsigned length; - unsigned lengthConstraint; + OOUInteger length; + OOUInteger lengthConstraint; NSError *error = nil; REQUIRE_TYPE(NSString, @"string"); @@ -875,13 +875,13 @@ static NSError *Verify_String(OOPListSchemaVerifier *verifier, id value, NSDicti // Apply length bounds. length = [filteredString length]; - lengthConstraint = [params oo_unsignedIntForKey:@"minLength"]; + lengthConstraint = [params oo_unsignedIntegerForKey:@"minLength"]; if (length < lengthConstraint) { return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"String \"%@\" is too short (%u bytes, minimum is %u).", StringForErrorReport(filteredString), length, lengthConstraint); } - lengthConstraint = [params oo_unsignedIntForKey:@"maxLength" defaultValue:UINT_MAX]; + lengthConstraint = [params oo_unsignedIntegerForKey:@"maxLength" defaultValue:NSUIntegerMax]; if (lengthConstraint < length) { return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"String \"%@\" is too long (%u bytes, maximum is %u).", StringForErrorReport(filteredString), length, lengthConstraint); @@ -896,9 +896,9 @@ static NSError *Verify_Array(OOPListSchemaVerifier *verifier, id value, NSDictio { id valueType = nil; BOOL OK = YES, stop = NO; - unsigned i, count; + OOUInteger i, count; id subProperty = nil; - unsigned constraint; + OOUInteger constraint; REQUIRE_TYPE(NSArray, @"array"); @@ -906,13 +906,13 @@ static NSError *Verify_Array(OOPListSchemaVerifier *verifier, id value, NSDictio // Apply count bounds. count = [value count]; - constraint = [params oo_unsignedIntForKey:@"minCount" defaultValue:0]; + constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0]; if (count < constraint) { return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Array has too few members (%u, minimum is %u).", count, constraint); } - constraint = [params oo_unsignedIntForKey:@"maxCount" defaultValue:UINT_MAX]; + constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax]; if (constraint < count) { return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Array has too many members (%u, maximum is %u).", count, constraint); @@ -961,7 +961,7 @@ static NSError *Verify_Dictionary(OOPListSchemaVerifier *verifier, id value, NSD BOOL allowOthers; NSMutableSet *requiredKeys = nil; NSArray *requiredKeyList = nil; - unsigned count, constraint; + OOUInteger count, constraint; REQUIRE_TYPE(NSDictionary, @"dictionary"); @@ -969,12 +969,12 @@ static NSError *Verify_Dictionary(OOPListSchemaVerifier *verifier, id value, NSD // Apply count bounds. count = [value count]; - constraint = [params oo_unsignedIntForKey:@"minCount" defaultValue:0]; + constraint = [params oo_unsignedIntegerForKey:@"minCount" defaultValue:0]; if (count < constraint) { return Error(kPListErrorMinimumConstraintNotMet, &keyPath, @"Dictionary has too few pairs (%u, minimum is %u).", count, constraint); } - constraint = [params oo_unsignedIntForKey:@"maxCount" defaultValue:UINT_MAX]; + constraint = [params oo_unsignedIntegerForKey:@"maxCount" defaultValue:NSUIntegerMax]; if (constraint < count) { return Error(kPListErrorMaximumConstraintNotMet, &keyPath, @"Dictionary has too manu pairs (%u, maximum is %u).", count, constraint); diff --git a/src/Core/OXPVerifier/OOTextureVerifierStage.m b/src/Core/OXPVerifier/OOTextureVerifierStage.m index 0562077f..05633df8 100644 --- a/src/Core/OXPVerifier/OOTextureVerifierStage.m +++ b/src/Core/OXPVerifier/OOTextureVerifierStage.m @@ -164,8 +164,8 @@ static NSString * const kStageName = @"Testing textures and images"; if (success) { - rWidth = OORoundUpToPowerOf2((2 * pixmap.width) / 3); - rHeight = OORoundUpToPowerOf2((2 * pixmap.height) / 3); + rWidth = (uint32_t)OORoundUpToPowerOf2((2 * pixmap.width) / 3); + rHeight = (uint32_t)OORoundUpToPowerOf2((2 * pixmap.height) / 3); if (pixmap.width != rWidth || pixmap.height != rHeight) { OOLog(@"verifyOXP.texture.notPOT", @"----- WARNING: image %@ has non-power-of-two dimensions; it will have to be rescaled (from %ux%u pixels to %ux%u pixels) at runtime.", displayName, pixmap.width, pixmap.height, rWidth, rHeight); diff --git a/src/Core/OldSchoolPropertyListWriting.m b/src/Core/OldSchoolPropertyListWriting.m index 97848ba7..d0ab13b1 100644 --- a/src/Core/OldSchoolPropertyListWriting.m +++ b/src/Core/OldSchoolPropertyListWriting.m @@ -35,7 +35,7 @@ static void AppendNewLineAndIndent(NSMutableString *ioString, unsigned indentDep NSRange foundRange, searchRange; NSString *foundString; NSMutableString *newString; - unsigned length; + NSUInteger length; length = [self length]; if (0 != length diff --git a/src/Core/Scripting/OOJSEquipmentInfo.m b/src/Core/Scripting/OOJSEquipmentInfo.m index c31ff04f..16630524 100644 --- a/src/Core/Scripting/OOJSEquipmentInfo.m +++ b/src/Core/Scripting/OOJSEquipmentInfo.m @@ -263,16 +263,15 @@ static JSBool EquipmentInfoGetProperty(JSContext *context, JSObject *this, jsid return JS_NewNumberValue(context, [eqType damageProbability], value); case kEquipmentInfo_techLevel: - *value = INT_TO_JSVAL([eqType techLevel]); + *value = INT_TO_JSVAL((int32_t)[eqType techLevel]); return YES; case kEquipmentInfo_effectiveTechLevel: - *value = INT_TO_JSVAL([eqType effectiveTechLevel]); + *value = INT_TO_JSVAL((int32_t)[eqType effectiveTechLevel]); return YES; case kEquipmentInfo_price: - *value = INT_TO_JSVAL([eqType price]); - return YES; + return JS_NewNumberValue(context, [eqType price], value); case kEquipmentInfo_isAvailableToAll: *value = OOJSValueFromBOOL([eqType isAvailableToAll]); diff --git a/src/Core/Scripting/OOJSFunction.m b/src/Core/Scripting/OOJSFunction.m index 7145f660..84b67157 100644 --- a/src/Core/Scripting/OOJSFunction.m +++ b/src/Core/Scripting/OOJSFunction.m @@ -92,9 +92,11 @@ MA 02110-1301, USA. if (OK) { + assert(argCount < UINT32_MAX); + [code getCharacters:buffer]; - function = JS_CompileUCFunction(context, scope, [name UTF8String], argCount, argNames, buffer, length, [fileName UTF8String], lineNumber); + function = JS_CompileUCFunction(context, scope, [name UTF8String], (uint32_t)argCount, argNames, buffer, length, [fileName UTF8String], (uint32_t)lineNumber); if (function == NULL) OK = NO; free(buffer); @@ -196,6 +198,7 @@ MA 02110-1301, USA. result:(jsval *)result { OOUInteger i, argc = [arguments count]; + assert(argc < UINT32_MAX); jsval argv[argc]; for (i = 0; i < argc; i++) @@ -209,7 +212,7 @@ MA 02110-1301, USA. if (jsThis != nil) OK = JS_ValueToObject(context, [jsThis oo_jsValueInContext:context], &scopeObj); if (OK) OK = [self evaluateWithContext:context scope:scopeObj - argc:argc + argc:(uint32_t)argc argv:argv result:result]; diff --git a/src/Core/Scripting/OOJSMissionVariables.m b/src/Core/Scripting/OOJSMissionVariables.m index 27529e6f..6520efcc 100644 --- a/src/Core/Scripting/OOJSMissionVariables.m +++ b/src/Core/Scripting/OOJSMissionVariables.m @@ -175,7 +175,9 @@ static JSBool MissionVariablesEnumerate(JSContext *context, JSObject *object, JS enumerator = [[mvars objectEnumerator] retain]; *state = PRIVATE_TO_JSVAL(enumerator); - if (idp != NULL) *idp = INT_TO_JSID([mvars count]); + OOUInteger count = [mvars count]; + assert(count <= INT32_MAX); + if (idp != NULL) *idp = INT_TO_JSID((uint32_t)count); return YES; } diff --git a/src/Core/Scripting/OOJSOolite.m b/src/Core/Scripting/OOJSOolite.m index 967e1d5e..79b5a78a 100644 --- a/src/Core/Scripting/OOJSOolite.m +++ b/src/Core/Scripting/OOJSOolite.m @@ -185,7 +185,7 @@ static JSBool OoliteCompareVersion(JSContext *context, uintN argc, jsval *vp) if (components != nil) { - OOJS_RETURN_INT(CompareVersions(components, VersionComponents())); + OOJS_RETURN_INT((int32_t)CompareVersions(components, VersionComponents())); } else { diff --git a/src/Core/Scripting/OOJSPlayer.m b/src/Core/Scripting/OOJSPlayer.m index 4145b8ba..60a0b2fa 100644 --- a/src/Core/Scripting/OOJSPlayer.m +++ b/src/Core/Scripting/OOJSPlayer.m @@ -200,7 +200,7 @@ static JSBool PlayerGetProperty(JSContext *context, JSObject *this, jsid propID, return YES; case kPlayer_legalStatus: - *value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player bounty])); + *value = OOJSValueFromNativeObject(context, OODisplayStringFromLegalStatus([player legalStatus])); return YES; case kPlayer_alertCondition: @@ -517,7 +517,7 @@ static JSBool PlayerSetEscapePodDestination(JSContext *context, uintN argc, jsva rescueRange = [UNIVERSE strict] ? MAX_JUMP_RANGE / 3.0 : MAX_JUMP_RANGE / 2.0; } NSMutableArray *sDests = [UNIVERSE nearbyDestinationsWithinRange:rescueRange]; - int i = 0, nDests = [sDests count]; + OOUInteger i = 0, nDests = [sDests count]; if (nDests > 0) for (i = --nDests; i > 0; i--) { diff --git a/src/Core/Scripting/OOJSShip.m b/src/Core/Scripting/OOJSShip.m index 95cf6946..93df8e18 100644 --- a/src/Core/Scripting/OOJSShip.m +++ b/src/Core/Scripting/OOJSShip.m @@ -477,7 +477,7 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j return JS_NewNumberValue(context, [entity fuelChargeRate], value); case kShip_bounty: - *value = INT_TO_JSVAL([entity bounty]); + return JS_NewNumberValue(context, [entity bounty], value); return YES; case kShip_subEntities: @@ -485,7 +485,7 @@ static JSBool ShipGetProperty(JSContext *context, JSObject *this, jsid propID, j break; case kShip_subEntityCapacity: - *value = INT_TO_JSVAL([entity maxShipSubEntities]); + return JS_NewNumberValue(context, [entity maxShipSubEntities], value); return YES; case kShip_hasSuspendedAI: @@ -1996,8 +1996,12 @@ static JSBool ShipRestoreSubEntities(JSContext *context, uintN argc, jsval *vp) if ([[thisEnt subEntitiesForScript] count] - subCount > 0) numSubEntitiesRestored = [[thisEnt subEntitiesForScript] count] - subCount; - // for each subentitiy restored, slightly increase the trade-in factor - if ([thisEnt isPlayer]) [(PlayerEntity *)thisEnt adjustTradeInFactorBy:(PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE * numSubEntitiesRestored)]; + // for each subentity restored, slightly increase the trade-in factor + if ([thisEnt isPlayer]) + { + int tradeInFactorChange = (int)MAX(PLAYER_SHIP_SUBENTITY_TRADE_IN_VALUE * numSubEntitiesRestored, 25U); + [(PlayerEntity *)thisEnt adjustTradeInFactorBy:tradeInFactorChange]; + } OOJS_RETURN_BOOL(numSubEntitiesRestored > 0); diff --git a/src/Core/Scripting/OOJSStation.m b/src/Core/Scripting/OOJSStation.m index 4f42ee71..19ebfba8 100644 --- a/src/Core/Scripting/OOJSStation.m +++ b/src/Core/Scripting/OOJSStation.m @@ -225,7 +225,7 @@ static JSBool StationGetProperty(JSContext *context, JSObject *this, jsid propID return YES; case kStation_equivalentTechLevel: - *value = INT_TO_JSVAL([entity equivalentTechLevel]); + *value = INT_TO_JSVAL((int32_t)[entity equivalentTechLevel]); return YES; case kStation_equipmentPriceFactor: diff --git a/src/Core/Scripting/OOJSSystemInfo.m b/src/Core/Scripting/OOJSSystemInfo.m index 80e5acf2..7337cf81 100644 --- a/src/Core/Scripting/OOJSSystemInfo.m +++ b/src/Core/Scripting/OOJSSystemInfo.m @@ -350,7 +350,9 @@ static JSBool SystemInfoEnumerate(JSContext *context, JSObject *this, JSIterateO enumerator = [[keys objectEnumerator] retain]; *state = PRIVATE_TO_JSVAL(enumerator); - if (idp != NULL) *idp = INT_TO_JSID([keys count]); + OOUInteger count = [keys count]; + assert(count <= INT32_MAX); + if (idp != NULL) *idp = INT_TO_JSID((int32_t)count); return YES; }