Skip to content

Commit

Permalink
global: make cppcheck more strict
Browse files Browse the repository at this point in the history
  • Loading branch information
and3rson committed Mar 10, 2024
1 parent 8f7f1b8 commit bd09954
Show file tree
Hide file tree
Showing 18 changed files with 28 additions and 33 deletions.
5 changes: 0 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,6 @@ clang-format: ## Run clang-format check
.PHONY: cppcheck
cppcheck: ## Run cppcheck check
cppcheck . -i.ccls-cache -ipio -imjs -idoomgeneric -ibak --enable=performance,style \
--suppress=cstyleCast \
--suppress=constVariablePointer \
--suppress=constParameterPointer \
--suppress=constVariableReference \
--suppress=noExplicitConstructor \
--suppress=knownPointerToBool \
--suppress=noCopyConstructor \
--suppress=noOperatorEq \
Expand Down
4 changes: 2 additions & 2 deletions firmware/doom/src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ void setup() {

D_AllocBuffers();
// Back buffer must be allocated before doomgeneric_Create since it calls DG_DrawFrame
backBuffer = (uint32_t*)malloc(DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4);
backBuffer = static_cast<uint32_t*>(malloc(DOOMGENERIC_RESX * DOOMGENERIC_RESY * 4));
doomgeneric_Create(argc, argv);
if (backBuffer == NULL) {
DG_printf("Failed to allocate back buffer\n");
Expand Down Expand Up @@ -224,7 +224,7 @@ extern "C" int DG_GetKey(int* pressed, unsigned char* doomKey) {
xSemaphoreTake(inputMutex, portMAX_DELAY);
int ret;
if (keyqueueRead != keyqueueWrite) {
doomkey_t* key = &keyqueue[keyqueueRead];
const doomkey_t* key = &keyqueue[keyqueueRead];
printf("Got key: %d, pressed: %d\n", key->key, key->pressed);
*pressed = key->pressed;
*doomKey = key->key;
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/app.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ void App::start() {
}

void App::_run(void* data) {
App* app = (App*)data;
App* app = static_cast<App*>(data);
app->run();
if (app->getState() != eTaskState::eDeleted) {
// App might have been stopped by itself. If not, stop it, or we'll get panic from FreeRTOS kernel.
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/demos/letris.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@ class Field {
}
}
}
void addShape(Shape* shape) {
void addShape(const Shape* shape) {
// Додає фігуру як частину поля
for (int yy = 0; yy < 4; yy++) {
for (int xx = 0; xx < 4; xx++) {
Expand Down Expand Up @@ -163,7 +163,7 @@ class Field {
}
}
}
bool willCollide(Shape* shape, int dx, int dy) {
bool willCollide(const Shape* shape, int dx, int dy) {
// Повертає true, якщо фігура зіткнеться з іншими блоками, якщо зміститься на (dx, dy)
for (int yy = 0; yy < 4; yy++) {
for (int xx = 0; xx < 4; xx++) {
Expand Down
6 changes: 3 additions & 3 deletions firmware/keira/src/apps/lua/lualilka_display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

Arduino_GFX* getDrawable(lua_State* L) {
lua_getfield(L, LUA_REGISTRYINDEX, "app");
App* app = (App*)lua_touserdata(L, -1);
const App* app = static_cast<App*>(lua_touserdata(L, -1));
return app->canvas;
}

Expand Down Expand Up @@ -255,7 +255,7 @@ int lualilka_display_drawImage(lua_State* L) {
int lualilka_display_queueDraw(lua_State* L) {
// Get App from registry
lua_getfield(L, LUA_REGISTRYINDEX, "app");
App* app = (App*)lua_touserdata(L, -1);
App* app = static_cast<App*>(app);
lua_pop(L, 1);
// Queue draw
app->queueDraw();
Expand Down Expand Up @@ -293,7 +293,7 @@ int lualilka_display_register(lua_State* L) {
// Add display width & height as library properties

lua_getfield(L, LUA_REGISTRYINDEX, "app");
App* app = (App*)lua_touserdata(L, -1);
App* app = static_cast<App*>(lua_touserdata(L, -1));
lua_pop(L, 1);

lua_pushinteger(L, app->canvas->width());
Expand Down
8 changes: 4 additions & 4 deletions firmware/keira/src/apps/lua/luarunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// Does not implement the run method.
class AbstractLuaRunnerApp : public App {
public:
AbstractLuaRunnerApp(const char* name);
explicit AbstractLuaRunnerApp(const char* name);

protected:
void luaSetup(const char* dir);
Expand All @@ -20,7 +20,7 @@ class AbstractLuaRunnerApp : public App {
// Lua runner app that runs a file.
class LuaFileRunnerApp : public AbstractLuaRunnerApp {
public:
LuaFileRunnerApp(String path);
explicit LuaFileRunnerApp(String path);

private:
void run();
Expand All @@ -30,7 +30,7 @@ class LuaFileRunnerApp : public AbstractLuaRunnerApp {
// Lua runner app that runs a string.
class LuaLiveRunnerApp : public AbstractLuaRunnerApp {
public:
LuaLiveRunnerApp();
explicit LuaLiveRunnerApp();

private:
void run();
Expand All @@ -39,7 +39,7 @@ class LuaLiveRunnerApp : public AbstractLuaRunnerApp {

class LuaReplApp : public AbstractLuaRunnerApp {
public:
LuaReplApp();
explicit LuaReplApp();

private:
void run();
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/mjs/mjsrunner.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

class MJSApp : public App {
public:
MJSApp(String path);
explicit MJSApp(String path);
void run() override;
static void* ffi_resolver(void* handle, const char* name);

Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/nes/driver.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ void Driver::clear(uint8 color) {
}

bitmap_t* Driver::lockWrite() {
bitmap = bmp_createhw((uint8*)fb, NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, NES_SCREEN_WIDTH * 2);
bitmap = bmp_createhw(reinterpret_cast<uint8*>(fb), NES_SCREEN_WIDTH, NES_SCREEN_HEIGHT, NES_SCREEN_WIDTH * 2);
return bitmap;
}

Expand All @@ -83,7 +83,7 @@ void Driver::customBlit(bitmap_t* bmp, int numDirties, rect_t* dirtyRects) {
lilka::Canvas* canvas = app->canvas;

for (int y = 0; y < frame_height; y++) {
uint8_t* line = bmp->line[y];
const uint8_t* line = bmp->line[y];
for (int x = 0; x < frame_width; x++) {
uint8_t index = line[x];
uint16_t color = nesPalette[index];
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/nes/nesapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
#include "driver.h"

NesApp::NesApp(String path) : App("NES", 0, 0, lilka::display.width(), lilka::display.height()) {
argv[0] = (char*)path.c_str();
argv[0] = const_cast<char*>(path.c_str());
setFlags(AppFlags::APP_FLAG_FULLSCREEN);
}

Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/apps/nes/nesapp.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

class NesApp : public App {
public:
NesApp(String path);
explicit NesApp(String path);

private:
void run();
Expand Down
4 changes: 2 additions & 2 deletions firmware/keira/src/apps/nes/osd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ const lilka::Button buttonIndices[10] = {

void osd_getinput(void) {
lilka::State state = lilka::controller.getState();
lilka::_StateButtons& buttons = *reinterpret_cast<lilka::_StateButtons*>(&state);
const lilka::_StateButtons& buttons = *reinterpret_cast<lilka::_StateButtons*>(&state);

for (int i = 0; i < sizeof(eventIndices) / sizeof(eventIndices[0]); i++) {
int eventIndex = eventIndices[i];
Expand Down Expand Up @@ -109,7 +109,7 @@ void osd_fullname(char* fullname, const char* shortname) {
}

/* This gives filenames for storage of saves */
extern char* osd_newextension(char* string, char* ext) {
extern char* osd_newextension(char* string, const char* ext) {
// dirty: assume both extensions is 3 characters
size_t l = strlen(string);
string[l - 3] = ext[1];
Expand Down
2 changes: 1 addition & 1 deletion firmware/keira/src/service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ void Service::start() {
}

void Service::_run(void* arg) {
Service* service = (Service*)arg;
Service* service = static_cast<Service*>(arg);
service->run();
Serial.println("Service " + String(service->name) + " died");
}
2 changes: 1 addition & 1 deletion sdk/lib/lilka/src/lilka/controller.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Controller::Controller() : state{} {
}

void Controller::inputTask(void* arg) {
Controller* self = (Controller*)arg;
Controller* self = static_cast<Controller*>(arg);
while (1) {
xSemaphoreTake(self->semaphore, portMAX_DELAY);
for (int i = 0; i < Button::COUNT; i++) {
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/lilka/src/lilka/filesystem.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ int Filesystem::readdir(String filenames[]) {
_root.close();
// Sort filenames
qsort(filenames, count, sizeof(String), [](const void* a, const void* b) -> int {
const String* ea = (const String*)a;
const String* eb = (const String*)b;
const String* ea = static_cast<const String*>(a);
const String* eb = static_cast<const String*>(b);
return ea->compareTo(*eb);
});
return count;
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/lilka/src/lilka/resources.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ Image* Resources::loadImage(String filename, int32_t transparentColor) {
// Read row data
fread(row, 1, width * bytesPerPixel, file);
for (int x = 0; x < width; x++) {
uint8_t* pixel = &row[x * bytesPerPixel];
const uint8_t* pixel = &row[x * bytesPerPixel];
uint8_t b = pixel[0];
uint8_t g = pixel[1];
uint8_t r = pixel[2];
Expand Down
4 changes: 2 additions & 2 deletions sdk/lib/lilka/src/lilka/sdcard.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,8 @@ int SDCard::listDir(String path, Entry entries[]) {
root.close();
// Sort filenames, but keep directories first
qsort(entries, i, sizeof(Entry), [](const void* a, const void* b) -> int {
const Entry* ea = (const Entry*)a;
const Entry* eb = (const Entry*)b;
const Entry* ea = static_cast<const Entry*>(a);
const Entry* eb = static_cast<const Entry*>(b);
if (ea->type == ENT_DIRECTORY && eb->type != ENT_DIRECTORY) {
return -1;
} else if (ea->type != ENT_DIRECTORY && eb->type == ENT_DIRECTORY) {
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/lilka/src/lilka/ui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void Menu::draw(Arduino_GFX* canvas) {
// TODO: Had to do this because I switched to canvas (FreeRTOS experiment)
// uint16_t *icon2 = (uint16_t *)icon;
canvas->draw16bitRGBBitmapWithTranColor(
0, 80 + screenI * 24 - 20, (uint16_t*)icon, canvas->color565(0, 0, 0), 24, 24
0, 80 + screenI * 24 - 20, const_cast<uint16_t*>(*icon), canvas->color565(0, 0, 0), 24, 24
);
}
canvas->setCursor(32, 80 + screenI * 24);
Expand Down
2 changes: 1 addition & 1 deletion sdk/lib/lilka/src/lilka/ui.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class Menu {
/// Конструктор класу.
///
/// @param title Заголовок меню.
Menu(String title);
explicit Menu(String title);
/// Додати пункт до меню.
/// @param title Заголовок пункту.
/// @param icon Іконка пункту (масив з ``uint16_t`` розміром 576 елементів, який представляє 24x24px зображення). За замовчуванням ``0`` (відсутня іконка).
Expand Down

0 comments on commit bd09954

Please sign in to comment.