internal
| 1417 | |
| 1418 | // internal |
| 1419 | void CScriptArray::Sort(asUINT startAt, asUINT count, bool asc) |
| 1420 | { |
| 1421 | // Subtype isn't primitive and doesn't have opCmp |
| 1422 | SArrayCache *cache = reinterpret_cast<SArrayCache*>(objType->GetUserData(ARRAY_CACHE)); |
| 1423 | if( subTypeId & ~asTYPEID_MASK_SEQNBR ) |
| 1424 | { |
| 1425 | if( !cache || cache->cmpFunc == 0 ) |
| 1426 | { |
| 1427 | asIScriptContext *ctx = asGetActiveContext(); |
| 1428 | asITypeInfo* subType = objType->GetEngine()->GetTypeInfoById(subTypeId); |
| 1429 | |
| 1430 | // Throw an exception |
| 1431 | if( ctx ) |
| 1432 | { |
| 1433 | char tmp[512]; |
| 1434 | |
| 1435 | if( cache && cache->cmpFuncReturnCode == asMULTIPLE_FUNCTIONS ) |
| 1436 | #if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__) |
| 1437 | sprintf_s(tmp, 512, "Type '%s' has multiple matching opCmp methods", subType->GetName()); |
| 1438 | #else |
| 1439 | sprintf(tmp, "Type '%s' has multiple matching opCmp methods", subType->GetName()); |
| 1440 | #endif |
| 1441 | else |
| 1442 | #if defined(_MSC_VER) && _MSC_VER >= 1500 && !defined(__S3E__) |
| 1443 | sprintf_s(tmp, 512, "Type '%s' does not have a matching opCmp method", subType->GetName()); |
| 1444 | #else |
| 1445 | sprintf(tmp, "Type '%s' does not have a matching opCmp method", subType->GetName()); |
| 1446 | #endif |
| 1447 | |
| 1448 | ctx->SetException(tmp); |
| 1449 | } |
| 1450 | |
| 1451 | return; |
| 1452 | } |
| 1453 | } |
| 1454 | |
| 1455 | // No need to sort |
| 1456 | if( count < 2 ) |
| 1457 | { |
| 1458 | return; |
| 1459 | } |
| 1460 | |
| 1461 | int start = startAt; |
| 1462 | int end = startAt + count; |
| 1463 | |
| 1464 | // Check if we could access invalid item while sorting |
| 1465 | if( start >= (int)buffer->numElements || end > (int)buffer->numElements ) |
| 1466 | { |
| 1467 | asIScriptContext *ctx = asGetActiveContext(); |
| 1468 | |
| 1469 | // Throw an exception |
| 1470 | if( ctx ) |
| 1471 | { |
| 1472 | ctx->SetException("Index out of bounds"); |
| 1473 | } |
| 1474 | |
| 1475 | return; |
| 1476 | } |
no test coverage detected