Skip to content

Commit

Permalink
Fix some clang-tidy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhasse committed Nov 9, 2024
1 parent c5b9ef9 commit c99052b
Show file tree
Hide file tree
Showing 9 changed files with 26 additions and 26 deletions.
1 change: 1 addition & 0 deletions .clang-tidy
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ Checks: '
,-altera-unroll-loops,
,-android-cloexec-fopen,
,-bugprone-easily-swappable-parameters,
,-cert-err33-c,
,-cert-err52-cpp,
,-cert-err58-cpp,
,-cert-flp30-c,
Expand Down
4 changes: 2 additions & 2 deletions src/audio/effect/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct pause_control_impl : pause_control {
auto result = stream_->read(data, std::min(sample_count, level_));

for (std::size_t i = 0; i < result; i += 2) {
float gain = static_cast<float>(level_) / length_.samples();
float gain = static_cast<float>(level_) / static_cast<float>(length_.samples());
data[i + 0] *= gain;
data[i + 1] *= gain;
level_ -= 2;
Expand All @@ -46,7 +46,7 @@ struct pause_control_impl : pause_control {
auto const max_level = static_cast<std::size_t>(length_.samples());

for (std::size_t i = 0; i < result; i += 2) {
float gain = static_cast<float>(level_) / max_level;
float gain = static_cast<float>(level_) / static_cast<float>(max_level);
data[i + 0] *= gain;
data[i + 1] *= gain;

Expand Down
3 changes: 2 additions & 1 deletion src/jngl/Drawable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,8 @@ void Drawable::setY(const double y) {
}

Vec2 Drawable::getSize() const {
return { double(width) / getScaleFactor(), double(height) / getScaleFactor() };
return { static_cast<double>(width) / getScaleFactor(),
static_cast<double>(height) / getScaleFactor() };
}

float Drawable::getWidth() const {
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/Pixels.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ bool operator>(const jngl::Pixels a, const jngl::Pixels b) {
}

Pixels operator/(const jngl::Pixels a, const float b) {
return Pixels(float(a) / b);
return Pixels(static_cast<float>(a) / b);
}

} // namespace jngl
Expand Down
3 changes: 2 additions & 1 deletion src/jngl/Shader.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,8 @@ Shader::Shader(const char* source, const Type type, const char* const gles20Sour
#endif
#ifdef GLAD_GL
if (const auto version = glGetString(GL_SHADING_LANGUAGE_VERSION)) {
std::istringstream tmp(reinterpret_cast<const char*>(version)); // e.g. "4.60 NVIDIA"
std::istringstream tmp(
/*NOLINT*/ reinterpret_cast<const char*>(version)); // e.g. "4.60 NVIDIA"
uint32_t major;
uint32_t minor;
tmp >> major;
Expand Down
2 changes: 1 addition & 1 deletion src/jngl/SoundFile.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ SoundFile::SoundFile(const std::string& filename, std::launch)
}

internal::debug("Decoded {} ({:.2f} MB, {})", filename,
buffer->size() * sizeof(float) / 1024. / 1024.,
static_cast<double>(buffer->size()) * sizeof(float) / 1024. / 1024.,
#if !defined(__APPLE__) /* FIXME: Remove when AppleClang's libc++ supports this C++20 feature */ \
&& defined(__GNUC__) && __GNUC__ > 13 // Ubuntu 22.04's GCC doesn't fully support C++20
std::chrono::duration_cast<std::chrono::seconds>(length())
Expand Down
6 changes: 3 additions & 3 deletions src/sdl/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@ void Window::UpdateInput() {
if (getKeyDown(key::ShiftL) || getKeyDown(key::ShiftR)) {
tmp.append(1, name[0]);
} else {
tmp.append(1, tolower(name[0]));
tmp.append(1, static_cast<char>(tolower(name[0])));
}
characterDown_[tmp] = true;
characterPressed_[tmp] = true;
Expand Down Expand Up @@ -510,7 +510,7 @@ int Window::getMouseX() const {
}
return std::lround(
(mousex_ * impl->hidpiScaleFactor - (impl->actualWidth - impl->actualCanvasWidth) / 2) *
(float(canvasWidth) / impl->actualCanvasWidth));
(static_cast<float>(canvasWidth) / impl->actualCanvasWidth));
}

int Window::getMouseY() const {
Expand All @@ -519,7 +519,7 @@ int Window::getMouseY() const {
}
return std::lround(
(mousey_ * impl->hidpiScaleFactor - (impl->actualHeight - impl->actualCanvasHeight) / 2) *
(float(canvasHeight) / impl->actualCanvasHeight));
(static_cast<float>(canvasHeight) / impl->actualCanvasHeight));
}

void setCursor(Cursor type) {
Expand Down
29 changes: 13 additions & 16 deletions src/theoraplay/theoraplay.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,9 +88,9 @@ struct THEORAPLAY_Decoder {
std::unique_ptr<uint8_t[]> ringBuffer;
};

static int FeedMoreOggData(THEORAPLAY_Io *io, ogg_sync_state *sync)
{
long buflen = 4096;
namespace {
int FeedMoreOggData(THEORAPLAY_Io* io, ogg_sync_state* sync) {
long buflen = 4096;
char *buffer = ogg_sync_buffer(sync, buflen);
if (buffer == nullptr) {
return -1;
Expand All @@ -102,12 +102,12 @@ static int FeedMoreOggData(THEORAPLAY_Io *io, ogg_sync_state *sync)
return (ogg_sync_wrote(sync, buflen) == 0) ? 1 : -1;
}


// This massive function is where all the effort happens.
static void WorkerThread(THEORAPLAY_Decoder* const ctx) {
// make sure we initialized the stream before using pagein, but the stream
// will know to ignore pages that aren't meant for it, so pass to both.
#define queue_ogg_page(ctx) do { \
void WorkerThread(THEORAPLAY_Decoder* const ctx) {
// make sure we initialized the stream before using pagein, but the stream
// will know to ignore pages that aren't meant for it, so pass to both.
#define queue_ogg_page(ctx) \
do { \
if (tpackets) ogg_stream_pagein(&tstream, &page); \
if (vpackets) ogg_stream_pagein(&vstream, &page); \
} while (0)
Expand Down Expand Up @@ -496,29 +496,26 @@ static void WorkerThread(THEORAPLAY_Decoder* const ctx) {
ctx->thread_done = true;
}


static void *WorkerThreadEntry(void *_this)
{
void* WorkerThreadEntry(void* _this) {
WorkerThread(static_cast<THEORAPLAY_Decoder*>(_this));
return nullptr;
}


static long IoFopenRead(THEORAPLAY_Io *io, void *buf, long buflen)
{
FILE *f = (FILE *) io->userdata;
long IoFopenRead(THEORAPLAY_Io* io, void* buf, long buflen) {
FILE *f = (FILE *) io->userdata;
const size_t br = fread(buf, 1, buflen, f);
if ((br == 0) && ferror(f)) {
return -1;
}
return (long) br;
}

static void IoFopenClose(THEORAPLAY_Io* io) {
void IoFopenClose(THEORAPLAY_Io* io) {
FILE* f = static_cast<FILE*>(io->userdata);
fclose(f);
free(io);
}
} // namespace

THEORAPLAY_Decoder* THEORAPLAY_startDecodeFile(const char* fname, const unsigned int maxframes,
THEORAPLAY_VideoFormat vidfmt) {
Expand Down
2 changes: 1 addition & 1 deletion src/unittest/ImageDataTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

namespace {
boost::ut::suite _ = [] {
using namespace boost::ut;
using namespace boost::ut; // NOLINT
"ImageData"_test = [] {
try {
jngl::ImageData::load("foo.tga");
Expand Down

0 comments on commit c99052b

Please sign in to comment.