5611: Fix minor clang-tidy 14 issues r=def- a=Robyt3

<!-- What is the motivation for the changes of this pull request -->

## Checklist

- [ ] Tested the change ingame
- [ ] Provided screenshots if it is a visual change
- [ ] Tested in combination with possibly related configuration options
- [ ] Written a unit test (especially base/) or added coverage to integration test
- [ ] Considered possible null pointers and out of bounds array indexing
- [ ] Changed no physics that affect existing maps
- [ ] Tested the change with [ASan+UBSan or valgrind's memcheck](https://github.com/ddnet/ddnet/#using-addresssanitizer--undefinedbehavioursanitizer-or-valgrinds-memcheck) (optional)


Co-authored-by: Robert Müller <robytemueller@gmail.com>
This commit is contained in:
bors[bot] 2022-07-10 20:41:17 +00:00 committed by GitHub
commit 60f44546e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
15 changed files with 51 additions and 58 deletions

View file

@ -6,7 +6,6 @@
#include <SDL.h> #include <SDL.h>
#include <base/detect.h>
#include <base/math.h> #include <base/math.h>
#include <cstdlib> #include <cstdlib>
@ -1416,7 +1415,7 @@ bool CGraphicsBackend_SDL_GL::ResizeWindow(int w, int h, int RefreshRate)
{ {
#ifdef CONF_FAMILY_WINDOWS #ifdef CONF_FAMILY_WINDOWS
// in windows make the window windowed mode first, this prevents strange window glitches (other games probably do something similar) // in windows make the window windowed mode first, this prevents strange window glitches (other games probably do something similar)
SetWindowParams(0, 1, true); SetWindowParams(0, true, true);
#endif #endif
SDL_DisplayMode SetMode = {}; SDL_DisplayMode SetMode = {};
SDL_DisplayMode ClosestMode = {}; SDL_DisplayMode ClosestMode = {};
@ -1428,7 +1427,7 @@ bool CGraphicsBackend_SDL_GL::ResizeWindow(int w, int h, int RefreshRate)
#ifdef CONF_FAMILY_WINDOWS #ifdef CONF_FAMILY_WINDOWS
// now change it back to fullscreen, this will restore the above set state, bcs SDL saves fullscreen modes appart from other video modes (as of SDL 2.0.16) // now change it back to fullscreen, this will restore the above set state, bcs SDL saves fullscreen modes appart from other video modes (as of SDL 2.0.16)
// see implementation of SDL_SetWindowDisplayMode // see implementation of SDL_SetWindowDisplayMode
SetWindowParams(1, 0, true); SetWindowParams(1, false, true);
#endif #endif
return true; return true;
} }

View file

@ -48,8 +48,6 @@
#include <engine/shared/snapshot.h> #include <engine/shared/snapshot.h>
#include <engine/shared/uuid_manager.h> #include <engine/shared/uuid_manager.h>
#include <base/system.h>
#include <game/localization.h> #include <game/localization.h>
#include <game/version.h> #include <game/version.h>
@ -4775,7 +4773,7 @@ SWarning *CClient::GetCurWarning()
} }
else else
{ {
return &m_vWarnings[0]; return m_vWarnings.data();
} }
} }

View file

@ -354,9 +354,9 @@ IGraphics::CTextureHandle CGraphics_Threaded::LoadSpriteTextureImpl(CImageInfo &
m_vSpriteHelper.resize((size_t)w * h * bpp); m_vSpriteHelper.resize((size_t)w * h * bpp);
CopyTextureFromTextureBufferSub(&m_vSpriteHelper[0], w, h, (uint8_t *)FromImageInfo.m_pData, FromImageInfo.m_Width, FromImageInfo.m_Height, bpp, x, y, w, h); CopyTextureFromTextureBufferSub(m_vSpriteHelper.data(), w, h, (uint8_t *)FromImageInfo.m_pData, FromImageInfo.m_Width, FromImageInfo.m_Height, bpp, x, y, w, h);
IGraphics::CTextureHandle RetHandle = LoadTextureRaw(w, h, FromImageInfo.m_Format, &m_vSpriteHelper[0], FromImageInfo.m_Format, 0); IGraphics::CTextureHandle RetHandle = LoadTextureRaw(w, h, FromImageInfo.m_Format, m_vSpriteHelper.data(), FromImageInfo.m_Format, 0);
return RetHandle; return RetHandle;
} }
@ -1413,12 +1413,12 @@ void CGraphics_Threaded::QuadContainerUpload(int ContainerIndex)
if(Container.m_QuadBufferObjectIndex == -1) if(Container.m_QuadBufferObjectIndex == -1)
{ {
size_t UploadDataSize = Container.m_vQuads.size() * sizeof(SQuadContainer::SQuad); size_t UploadDataSize = Container.m_vQuads.size() * sizeof(SQuadContainer::SQuad);
Container.m_QuadBufferObjectIndex = CreateBufferObject(UploadDataSize, &Container.m_vQuads[0], 0); Container.m_QuadBufferObjectIndex = CreateBufferObject(UploadDataSize, Container.m_vQuads.data(), 0);
} }
else else
{ {
size_t UploadDataSize = Container.m_vQuads.size() * sizeof(SQuadContainer::SQuad); size_t UploadDataSize = Container.m_vQuads.size() * sizeof(SQuadContainer::SQuad);
RecreateBufferObject(Container.m_QuadBufferObjectIndex, UploadDataSize, &Container.m_vQuads[0], 0); RecreateBufferObject(Container.m_QuadBufferObjectIndex, UploadDataSize, Container.m_vQuads.data(), 0);
} }
if(Container.m_QuadBufferContainerIndex == -1) if(Container.m_QuadBufferContainerIndex == -1)
@ -2808,7 +2808,7 @@ SWarning *CGraphics_Threaded::GetCurWarning()
return NULL; return NULL;
else else
{ {
SWarning *pCurWarning = &m_vWarnings[0]; SWarning *pCurWarning = m_vWarnings.data();
return pCurWarning; return pCurWarning;
} }
} }

View file

@ -137,7 +137,7 @@ void CInput::UpdateActiveJoystick()
} }
// Fall back to first joystick if no match was found // Fall back to first joystick if no match was found
if(!m_pActiveJoystick) if(!m_pActiveJoystick)
m_pActiveJoystick = &m_vJoysticks[0]; m_pActiveJoystick = &m_vJoysticks[0]; // NOLINT(readability-container-data-pointer)
} }
void CInput::ConchainJoystickGuidChanged(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData) void CInput::ConchainJoystickGuidChanged(IConsole::IResult *pResult, void *pUserData, IConsole::FCommandCallback pfnCallback, void *pCallbackUserData)

View file

@ -1442,7 +1442,7 @@ public:
if(Graphics()->IsTextBufferingEnabled()) if(Graphics()->IsTextBufferingEnabled())
{ {
size_t DataSize = TextContainer.m_StringInfo.m_vCharacterQuads.size() * sizeof(STextCharQuad); size_t DataSize = TextContainer.m_StringInfo.m_vCharacterQuads.size() * sizeof(STextCharQuad);
void *pUploadData = &TextContainer.m_StringInfo.m_vCharacterQuads[0]; void *pUploadData = TextContainer.m_StringInfo.m_vCharacterQuads.data();
if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1 && (TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0) if(TextContainer.m_StringInfo.m_QuadBufferObjectIndex != -1 && (TextContainer.m_RenderFlags & TEXT_RENDER_FLAG_NO_AUTOMATIC_QUAD_UPLOAD) == 0)
{ {
@ -1503,7 +1503,7 @@ public:
if(HasCursor) if(HasCursor)
Graphics()->QuadContainerAddQuads(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, aCursorQuads, 2); Graphics()->QuadContainerAddQuads(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, aCursorQuads, 2);
if(HasSelection) if(HasSelection)
Graphics()->QuadContainerAddQuads(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, &vSelectionQuads[0], (int)vSelectionQuads.size()); Graphics()->QuadContainerAddQuads(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex, vSelectionQuads.data(), (int)vSelectionQuads.size());
Graphics()->QuadContainerUpload(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex); Graphics()->QuadContainerUpload(TextContainer.m_StringInfo.m_SelectionQuadContainerIndex);
TextContainer.m_HasCursor = HasCursor; TextContainer.m_HasCursor = HasCursor;

View file

@ -27,7 +27,7 @@ static void LibPNGWarning(png_structp png_ptr, png_const_charp warning_msg)
static bool FileMatchesImageType(SImageByteBuffer &ByteLoader) static bool FileMatchesImageType(SImageByteBuffer &ByteLoader)
{ {
if(ByteLoader.m_pLoadedImageBytes->size() >= 8) if(ByteLoader.m_pLoadedImageBytes->size() >= 8)
return png_sig_cmp((png_bytep) & (*ByteLoader.m_pLoadedImageBytes)[0], 0, 8) == 0; return png_sig_cmp((png_bytep)ByteLoader.m_pLoadedImageBytes->data(), 0, 8) == 0;
return false; return false;
} }

View file

@ -833,8 +833,8 @@ void CMapLayers::OnMapLoad()
vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderRightTilesTexCoords.begin(), vtmpBorderRightTilesTexCoords.end()); vtmpTileTexCoords.insert(vtmpTileTexCoords.end(), vtmpBorderRightTilesTexCoords.begin(), vtmpBorderRightTilesTexCoords.end());
//setup params //setup params
float *pTmpTiles = (vtmpTiles.empty()) ? NULL : (float *)&vtmpTiles[0]; float *pTmpTiles = vtmpTiles.empty() ? NULL : (float *)vtmpTiles.data();
unsigned char *pTmpTileTexCoords = (vtmpTileTexCoords.empty()) ? NULL : (unsigned char *)&vtmpTileTexCoords[0]; unsigned char *pTmpTileTexCoords = vtmpTileTexCoords.empty() ? NULL : (unsigned char *)vtmpTileTexCoords.data();
Visuals.m_BufferContainerIndex = -1; Visuals.m_BufferContainerIndex = -1;
size_t UploadDataSize = vtmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + vtmpTiles.size() * sizeof(SGraphicTile); size_t UploadDataSize = vtmpTileTexCoords.size() * sizeof(SGraphicTileTexureCoords) + vtmpTiles.size() * sizeof(SGraphicTile);
@ -951,9 +951,9 @@ void CMapLayers::OnMapLoad()
{ {
void *pUploadData = NULL; void *pUploadData = NULL;
if(Textured) if(Textured)
pUploadData = &vtmpQuadsTextured[0]; pUploadData = vtmpQuadsTextured.data();
else else
pUploadData = &vtmpQuads[0]; pUploadData = vtmpQuads.data();
// create the buffer object // create the buffer object
int BufferObjectIndex = Graphics()->CreateBufferObject(UploadDataSize, pUploadData, 0); int BufferObjectIndex = Graphics()->CreateBufferObject(UploadDataSize, pUploadData, 0);
// then create the buffer container // then create the buffer container
@ -1087,7 +1087,7 @@ void CMapLayers::RenderTileLayer(int LayerIndex, ColorRGBA &Color, CMapItemLayer
int DrawCount = s_vpIndexOffsets.size(); int DrawCount = s_vpIndexOffsets.size();
if(DrawCount != 0) if(DrawCount != 0)
{ {
Graphics()->RenderTileLayer(Visuals.m_BufferContainerIndex, Color, &s_vpIndexOffsets[0], &s_vDrawCounts[0], DrawCount); Graphics()->RenderTileLayer(Visuals.m_BufferContainerIndex, Color, s_vpIndexOffsets.data(), s_vDrawCounts.data(), DrawCount);
} }
} }
@ -1416,7 +1416,7 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer,
if(NeedsFlush) if(NeedsFlush)
{ {
// render quads of the current offset directly(cancel batching) // render quads of the current offset directly(cancel batching)
Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, &s_vQuadRenderInfo[0], QuadsRenderCount, CurQuadOffset); Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, s_vQuadRenderInfo.data(), QuadsRenderCount, CurQuadOffset);
QuadsRenderCount = 0; QuadsRenderCount = 0;
CurQuadOffset = i; CurQuadOffset = i;
if(Color.a == 0) if(Color.a == 0)
@ -1435,7 +1435,7 @@ void CMapLayers::RenderQuadLayer(int LayerIndex, CMapItemLayerQuads *pQuadLayer,
QInfo.m_Rotation = Rot; QInfo.m_Rotation = Rot;
} }
} }
Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, &s_vQuadRenderInfo[0], QuadsRenderCount, CurQuadOffset); Graphics()->RenderQuadLayer(Visuals.m_BufferContainerIndex, s_vQuadRenderInfo.data(), QuadsRenderCount, CurQuadOffset);
} }
void CMapLayers::LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer) void CMapLayers::LayersOfGroupCount(CMapItemGroup *pGroup, int &TileLayerCount, int &QuadLayerCount, bool &PassedGameLayer)

View file

@ -290,7 +290,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
// add the data // add the data
Item.m_NumQuads = pLayerQuads->m_vQuads.size(); Item.m_NumQuads = pLayerQuads->m_vQuads.size();
Item.m_Data = df.AddDataSwapped(pLayerQuads->m_vQuads.size() * sizeof(CQuad), &pLayerQuads->m_vQuads[0]); Item.m_Data = df.AddDataSwapped(pLayerQuads->m_vQuads.size() * sizeof(CQuad), pLayerQuads->m_vQuads.data());
// save layer name // save layer name
StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerQuads->m_aName); StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerQuads->m_aName);
@ -319,7 +319,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
// add the data // add the data
Item.m_NumSources = pLayerSounds->m_vSources.size(); Item.m_NumSources = pLayerSounds->m_vSources.size();
Item.m_Data = df.AddDataSwapped(pLayerSounds->m_vSources.size() * sizeof(CSoundSource), &pLayerSounds->m_vSources[0]); Item.m_Data = df.AddDataSwapped(pLayerSounds->m_vSources.size() * sizeof(CSoundSource), pLayerSounds->m_vSources.data());
// save layer name // save layer name
StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerSounds->m_aName); StrToInts(Item.m_aName, sizeof(Item.m_aName) / sizeof(int), pLayerSounds->m_aName);
@ -358,7 +358,7 @@ int CEditorMap::Save(class IStorage *pStorage, const char *pFileName)
for(const auto &pEnvelope : m_vpEnvelopes) for(const auto &pEnvelope : m_vpEnvelopes)
{ {
int Count = pEnvelope->m_vPoints.size(); int Count = pEnvelope->m_vPoints.size();
mem_copy(&pPoints[PointCount], &pEnvelope->m_vPoints[0], sizeof(CEnvPoint) * Count); mem_copy(&pPoints[PointCount], pEnvelope->m_vPoints.data(), sizeof(CEnvPoint) * Count);
PointCount += Count; PointCount += Count;
} }
@ -848,7 +848,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
void *pData = DataFile.GetDataSwapped(pQuadsItem->m_Data); void *pData = DataFile.GetDataSwapped(pQuadsItem->m_Data);
pGroup->AddLayer(pQuads); pGroup->AddLayer(pQuads);
pQuads->m_vQuads.resize(pQuadsItem->m_NumQuads); pQuads->m_vQuads.resize(pQuadsItem->m_NumQuads);
mem_copy(&pQuads->m_vQuads[0], pData, sizeof(CQuad) * pQuadsItem->m_NumQuads); mem_copy(pQuads->m_vQuads.data(), pData, sizeof(CQuad) * pQuadsItem->m_NumQuads);
DataFile.UnloadData(pQuadsItem->m_Data); DataFile.UnloadData(pQuadsItem->m_Data);
} }
else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS) else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS)
@ -874,7 +874,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
void *pData = DataFile.GetDataSwapped(pSoundsItem->m_Data); void *pData = DataFile.GetDataSwapped(pSoundsItem->m_Data);
pGroup->AddLayer(pSounds); pGroup->AddLayer(pSounds);
pSounds->m_vSources.resize(pSoundsItem->m_NumSources); pSounds->m_vSources.resize(pSoundsItem->m_NumSources);
mem_copy(&pSounds->m_vSources[0], pData, sizeof(CSoundSource) * pSoundsItem->m_NumSources); mem_copy(pSounds->m_vSources.data(), pData, sizeof(CSoundSource) * pSoundsItem->m_NumSources);
DataFile.UnloadData(pSoundsItem->m_Data); DataFile.UnloadData(pSoundsItem->m_Data);
} }
else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS_DEPRECATED) else if(pLayerItem->m_Type == LAYERTYPE_SOUNDS_DEPRECATED)
@ -949,7 +949,7 @@ int CEditorMap::Load(class IStorage *pStorage, const char *pFileName, int Storag
CMapItemEnvelope *pItem = (CMapItemEnvelope *)DataFile.GetItem(Start + e, nullptr, nullptr); CMapItemEnvelope *pItem = (CMapItemEnvelope *)DataFile.GetItem(Start + e, nullptr, nullptr);
CEnvelope *pEnv = new CEnvelope(pItem->m_Channels); CEnvelope *pEnv = new CEnvelope(pItem->m_Channels);
pEnv->m_vPoints.resize(pItem->m_NumPoints); pEnv->m_vPoints.resize(pItem->m_NumPoints);
mem_copy(&pEnv->m_vPoints[0], &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint) * pItem->m_NumPoints); mem_copy(pEnv->m_vPoints.data(), &pPoints[pItem->m_StartPoint], sizeof(CEnvPoint) * pItem->m_NumPoints);
if(pItem->m_aName[0] != -1) // compatibility with old maps if(pItem->m_aName[0] != -1) // compatibility with old maps
IntsToStr(pItem->m_aName, sizeof(pItem->m_aName) / sizeof(int), pEnv->m_aName); IntsToStr(pItem->m_aName, sizeof(pItem->m_aName) / sizeof(int), pEnv->m_aName);
m_vpEnvelopes.push_back(pEnv); m_vpEnvelopes.push_back(pEnv);

View file

@ -23,9 +23,9 @@ void CLayerQuads::Render(bool QuadPicker)
Graphics()->TextureSet(m_pEditor->m_Map.m_vpImages[m_Image]->m_Texture); Graphics()->TextureSet(m_pEditor->m_Map.m_vpImages[m_Image]->m_Texture);
Graphics()->BlendNone(); Graphics()->BlendNone();
m_pEditor->RenderTools()->ForceRenderQuads(&m_vQuads[0], m_vQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor); m_pEditor->RenderTools()->ForceRenderQuads(m_vQuads.data(), m_vQuads.size(), LAYERRENDERFLAG_OPAQUE, m_pEditor->EnvelopeEval, m_pEditor);
Graphics()->BlendNormal(); Graphics()->BlendNormal();
m_pEditor->RenderTools()->ForceRenderQuads(&m_vQuads[0], m_vQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor); m_pEditor->RenderTools()->ForceRenderQuads(m_vQuads.data(), m_vQuads.size(), LAYERRENDERFLAG_TRANSPARENT, m_pEditor->EnvelopeEval, m_pEditor);
} }
CQuad *CLayerQuads::NewQuad(int x, int y, int Width, int Height) CQuad *CLayerQuads::NewQuad(int x, int y, int Width, int Height)

View file

@ -5,27 +5,24 @@
#include <base/system.h> #include <base/system.h>
static const int INT_DATA[] = {0, 1, -1, 32, 64, 256, -512, 12345, -123456, 1234567, 12345678, 123456789, 2147483647, (-2147483647 - 1)}; static const int INT_DATA[] = {0, 1, -1, 32, 64, 256, -512, 12345, -123456, 1234567, 12345678, 123456789, 2147483647, (-2147483647 - 1)};
static const int INT_NUM = std::size(INT_DATA);
static const unsigned UINT_DATA[] = {0u, 1u, 2u, 32u, 64u, 256u, 512u, 12345u, 123456u, 1234567u, 12345678u, 123456789u, 2147483647u, 2147483648u, 4294967295u}; static const unsigned UINT_DATA[] = {0u, 1u, 2u, 32u, 64u, 256u, 512u, 12345u, 123456u, 1234567u, 12345678u, 123456789u, 2147483647u, 2147483648u, 4294967295u};
static const int UINT_NUM = std::size(INT_DATA);
TEST(BytePacking, RoundtripInt) TEST(BytePacking, RoundtripInt)
{ {
for(int i = 0; i < INT_NUM; i++) for(auto i : INT_DATA)
{ {
unsigned char aPacked[4]; unsigned char aPacked[4];
int_to_bytes_be(aPacked, INT_DATA[i]); int_to_bytes_be(aPacked, i);
EXPECT_EQ(bytes_be_to_int(aPacked), INT_DATA[i]); EXPECT_EQ(bytes_be_to_int(aPacked), i);
} }
} }
TEST(BytePacking, RoundtripUnsigned) TEST(BytePacking, RoundtripUnsigned)
{ {
for(int i = 0; i < UINT_NUM; i++) for(auto u : UINT_DATA)
{ {
unsigned char aPacked[4]; unsigned char aPacked[4];
uint_to_bytes_be(aPacked, UINT_DATA[i]); uint_to_bytes_be(aPacked, u);
EXPECT_EQ(bytes_be_to_uint(aPacked), UINT_DATA[i]); EXPECT_EQ(bytes_be_to_uint(aPacked), u);
} }
} }

View file

@ -21,8 +21,8 @@ TEST(CVariableInt, RoundtripPackUnpack)
TEST(CVariableInt, UnpackInvalid) TEST(CVariableInt, UnpackInvalid)
{ {
unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED]; unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED];
for(unsigned i = 0; i < sizeof(aPacked); i++) for(auto &Byte : aPacked)
aPacked[i] = 0xFF; Byte = 0xFF;
int Result; int Result;
EXPECT_EQ(int(CVariableInt::Unpack(aPacked, &Result, sizeof(aPacked)) - aPacked), int(CVariableInt::MAX_BYTES_PACKED)); EXPECT_EQ(int(CVariableInt::Unpack(aPacked, &Result, sizeof(aPacked)) - aPacked), int(CVariableInt::MAX_BYTES_PACKED));
@ -43,8 +43,8 @@ TEST(CVariableInt, PackBufferTooSmall)
TEST(CVariableInt, UnpackBufferTooSmall) TEST(CVariableInt, UnpackBufferTooSmall)
{ {
unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED / 2]; unsigned char aPacked[CVariableInt::MAX_BYTES_PACKED / 2];
for(unsigned i = 0; i < sizeof(aPacked); i++) for(auto &Byte : aPacked)
aPacked[i] = 0xFF; // extended bits are set, but buffer ends too early Byte = 0xFF; // extended bits are set, but buffer ends too early
int UnusedResult; int UnusedResult;
EXPECT_EQ(CVariableInt::Unpack(aPacked, &UnusedResult, sizeof(aPacked)), (const unsigned char *)0x0); EXPECT_EQ(CVariableInt::Unpack(aPacked, &UnusedResult, sizeof(aPacked)), (const unsigned char *)0x0);
@ -55,8 +55,8 @@ TEST(CVariableInt, RoundtripCompressDecompress)
unsigned char aCompressed[NUM * CVariableInt::MAX_BYTES_PACKED]; unsigned char aCompressed[NUM * CVariableInt::MAX_BYTES_PACKED];
int aDecompressed[NUM]; int aDecompressed[NUM];
long ExpectedCompressedSize = 0; long ExpectedCompressedSize = 0;
for(int i = 0; i < NUM; i++) for(auto Size : SIZES)
ExpectedCompressedSize += SIZES[i]; ExpectedCompressedSize += Size;
long CompressedSize = CVariableInt::Compress(DATA, sizeof(DATA), aCompressed, sizeof(aCompressed)); long CompressedSize = CVariableInt::Compress(DATA, sizeof(DATA), aCompressed, sizeof(aCompressed));
ASSERT_EQ(CompressedSize, ExpectedCompressedSize); ASSERT_EQ(CompressedSize, ExpectedCompressedSize);

View file

@ -56,9 +56,9 @@ TEST(Prng, EqualsPcg32GlobalDemo)
CPrng Prng; CPrng Prng;
Prng.Seed(aSeed); Prng.Seed(aSeed);
for(unsigned i = 0; i < std::size(PCG32_GLOBAL_DEMO); i++) for(auto Expected : PCG32_GLOBAL_DEMO)
{ {
EXPECT_EQ(Prng.RandomBits(), PCG32_GLOBAL_DEMO[i]); EXPECT_EQ(Prng.RandomBits(), Expected);
} }
} }

View file

@ -106,7 +106,7 @@ struct Score : public testing::TestWithParam<IDbConnection *>
ASSERT_FALSE(CScoreWorker::SaveScore(m_pConn, &ScoreData, false, m_aError, sizeof(m_aError))) << m_aError; ASSERT_FALSE(CScoreWorker::SaveScore(m_pConn, &ScoreData, false, m_aError, sizeof(m_aError))) << m_aError;
} }
void ExpectLines(std::shared_ptr<CScorePlayerResult> pPlayerResult, std::initializer_list<const char *> Lines, bool All = false) void ExpectLines(const std::shared_ptr<CScorePlayerResult> &pPlayerResult, std::initializer_list<const char *> Lines, bool All = false)
{ {
EXPECT_EQ(pPlayerResult->m_MessageKind, All ? CScorePlayerResult::ALL : CScorePlayerResult::DIRECT); EXPECT_EQ(pPlayerResult->m_MessageKind, All ? CScorePlayerResult::ALL : CScorePlayerResult::DIRECT);
@ -183,9 +183,9 @@ TEST_P(SingleScore, LoadPlayerData)
EXPECT_EQ(m_pPlayerResult->m_MessageKind, CScorePlayerResult::PLAYER_INFO); EXPECT_EQ(m_pPlayerResult->m_MessageKind, CScorePlayerResult::PLAYER_INFO);
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0); ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_Time, 0.0);
for(int i = 0; i < NUM_CHECKPOINTS; i++) for(auto &Time : m_pPlayerResult->m_Data.m_Info.m_aTimeCp)
{ {
ASSERT_EQ(m_pPlayerResult->m_Data.m_Info.m_aTimeCp[i], 0); ASSERT_EQ(Time, 0);
} }
str_copy(m_PlayerRequest.m_aRequestingPlayer, "nameless tee", sizeof(m_PlayerRequest.m_aRequestingPlayer)); str_copy(m_PlayerRequest.m_aRequestingPlayer, "nameless tee", sizeof(m_PlayerRequest.m_aRequestingPlayer));

View file

@ -22,9 +22,8 @@ TEST(SecureRandom, Below1)
TEST(SecureRandom, Below) TEST(SecureRandom, Below)
{ {
int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129}; int BOUNDS[] = {2, 3, 4, 5, 10, 100, 127, 128, 129};
for(unsigned i = 0; i < std::size(BOUNDS); i++) for(auto Below : BOUNDS)
{ {
int Below = BOUNDS[i];
for(int j = 0; j < 10; j++) for(int j = 0; j < 10; j++)
{ {
int Random = secure_rand_below(Below); int Random = secure_rand_below(Below);

View file

@ -690,13 +690,13 @@ TEST_F(TeeHistorian, TeamPractice)
0x40}; 0x40};
Tick(1); Tick(1);
m_TH.RecordTeamPractice(1, 0); m_TH.RecordTeamPractice(1, false);
m_TH.RecordTeamPractice(16, 0); m_TH.RecordTeamPractice(16, false);
m_TH.RecordTeamPractice(23, 1); m_TH.RecordTeamPractice(23, true);
Tick(2); Tick(2);
m_TH.RecordTeamPractice(1, 1); m_TH.RecordTeamPractice(1, true);
m_TH.RecordTeamPractice(16, 0); m_TH.RecordTeamPractice(16, false);
m_TH.RecordTeamPractice(23, 0); m_TH.RecordTeamPractice(23, false);
Finish(); Finish();
Expect(EXPECTED, sizeof(EXPECTED)); Expect(EXPECTED, sizeof(EXPECTED));
} }