Skip to content

Commit

Permalink
fix static analysis
Browse files Browse the repository at this point in the history
  • Loading branch information
finger563 committed Dec 27, 2023
1 parent b5590c2 commit 8740531
Show file tree
Hide file tree
Showing 11 changed files with 63 additions and 222 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/static_analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@ jobs:
use_cmake: false

# (Optional) cppcheck args
cppcheck_args: -i$GITHUB_WORKSPACE/lib -i$GITHUB_WORKSPACE/components/gbc/gnuboy -i$GITHUB_WORKSPACE/components/nes/nofrendo -i$GITHUB_WORKSPACE/components/jpegdec -i$GITHUB_WORKSPACE/components/codec -i$GITHUB_WORKSPACE/components/espp --force --enable=all --inline-suppr --inconclusive --platform=mips32 --suppressions-list=$GITHUB_WORKSPACE/suppressions.txt
cppcheck_args: -i$GITHUB_WORKSPACE/lib -i$GITHUB_WORKSPACE/components/gbc/gnuboy -i$GITHUB_WORKSPACE/components/nes/nofrendo -i$GITHUB_WORKSPACE/components/gui/generated -i$GITHUB_WORKSPACE/components/menu/generated -i$GITHUB_WORKSPACE/components/jpegdec -i$GITHUB_WORKSPACE/components/codec -i$GITHUB_WORKSPACE/components/espp --force --enable=all --inline-suppr --inconclusive --platform=mips32 --suppressions-list=$GITHUB_WORKSPACE/suppressions.txt
6 changes: 3 additions & 3 deletions components/gui/include/gui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ class Gui {
espp::Logger::Verbosity log_level{espp::Logger::Verbosity::WARN};
};

Gui(const Config& config)
explicit Gui(const Config& config)
: play_haptic_(config.play_haptic),
set_waveform_(config.set_waveform),
display_(config.display),
Expand Down Expand Up @@ -64,7 +64,7 @@ class Gui {
ready_to_play_ = new_state;
}

bool ready_to_play() {
bool ready_to_play() const {
return ready_to_play_;
}

Expand All @@ -84,7 +84,7 @@ class Gui {

void add_rom(const RomInfo& rom);

std::optional<const RomInfo*> get_selected_rom() {
std::optional<const RomInfo*> get_selected_rom() const {
if (focused_rom_ < 0 || focused_rom_ >= rom_infos_.size()) {
return std::nullopt;
}
Expand Down
3 changes: 2 additions & 1 deletion components/jpeg/include/jpeg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ class Jpeg {
return;
}
// get size from current location (end)
// cppcheck-suppress unreadVariable
*size = (size_t)imgfile_.tellg();
// reset file pointer to beginning
imgfile_.seekg(0, std::ios::beg);
Expand Down Expand Up @@ -110,7 +111,7 @@ class Jpeg {
auto ys = pDraw->y;
auto ye = pDraw->y + height - 1;
uint16_t *dst_buffer = (uint16_t*)decoded_data_;
uint16_t *src_buffer = (uint16_t*)pDraw->pPixels;
const uint16_t *src_buffer = (const uint16_t*)pDraw->pPixels;
// two bytes per pixel for RGB565
auto num_bytes_per_row = width * 2;
for (int y=ys; y<=ye; y++) {
Expand Down
4 changes: 2 additions & 2 deletions components/menu/include/menu.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Menu {
espp::Logger::Verbosity log_level{espp::Logger::Verbosity::WARN};
};

Menu(const Config& config)
explicit Menu(const Config& config)
: display_(config.display),
paused_image_path_(config.paused_image_path),
action_callback_(config.action_callback),
Expand Down Expand Up @@ -97,7 +97,7 @@ class Menu {

void set_video_setting(VideoSetting setting);

bool is_paused() { return paused_; }
bool is_paused() const { return paused_; }
void pause() {
paused_ = true;
lv_group_focus_freeze(group_, true);
Expand Down
4 changes: 2 additions & 2 deletions components/nes/src/nes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,8 @@ std::vector<uint8_t> get_nes_video_buffer() {
std::vector<uint8_t> frame(NES_SCREEN_WIDTH * NES_VISIBLE_HEIGHT * 2);
// the frame data for the NES is stored in frame_buffer0 as a 8 bit index into the palette
// we need to convert this to a 16 bit RGB565 value
uint8_t *frame_buffer0 = get_frame_buffer0();
uint16_t *palette = get_nes_palette();
const uint8_t *frame_buffer0 = get_frame_buffer0();
const uint16_t *palette = get_nes_palette();
for (int i = 0; i < NES_SCREEN_WIDTH * NES_VISIBLE_HEIGHT; i++) {
uint8_t index = frame_buffer0[i];
uint16_t color = palette[index];
Expand Down
7 changes: 4 additions & 3 deletions components/nes/src/video_audio.c
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,6 @@ void osd_set_video_scale(bool new_video_scale) {
}

void ili9341_write_frame_nes(const uint8_t* buffer, uint16_t* myPalette) {
short x, y;
static const int x_offset = (320-256)/2;
static const int y_offset = (240-224)/2;
if (buffer == NULL) {
Expand All @@ -163,11 +162,12 @@ void ili9341_write_frame_nes(const uint8_t* buffer, uint16_t* myPalette) {
lcd_write_frame(0,0,320,240,NULL);
}
if (scale_video) {
uint8_t* framePtr = buffer;
const uint8_t* framePtr = buffer;
static int buffer_index = 0;
static const int LINE_COUNT = NUM_ROWS_IN_FRAME_BUFFER;
float x_scale = 1.25f;
float y_scale = 1.0f;
short x, y;
for (y = 0; y < 240; y+= LINE_COUNT) {
uint16_t* line_buffer = buffer_index ? (uint16_t*)get_vram1() : (uint16_t*)get_vram0();
buffer_index = buffer_index ? 0 : 1;
Expand All @@ -186,9 +186,10 @@ void ili9341_write_frame_nes(const uint8_t* buffer, uint16_t* myPalette) {
lcd_write_frame(0, y_offset+y, 320, num_lines_written, (uint8_t*)&line_buffer[0]);
}
} else {
uint8_t* framePtr = buffer;
const uint8_t* framePtr = buffer;
static int buffer_index = 0;
static const int LINE_COUNT = NUM_ROWS_IN_FRAME_BUFFER;
short x, y;
for (y = 0; y < NES_GAME_HEIGHT; y+= LINE_COUNT) {
uint16_t* line_buffer = buffer_index ? (uint16_t*)get_vram1() : (uint16_t*)get_vram0();
buffer_index = buffer_index ? 0 : 1;
Expand Down
194 changes: 0 additions & 194 deletions main/button_handlers.hpp

This file was deleted.

23 changes: 10 additions & 13 deletions main/cart.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,10 @@ class Cart {
std::filesystem::remove(paused_image_path, ec);
}
// copy the screenshot to the paused image
std::fstream screenshot(screenshot_path, std::ios::binary | std::ios::in);
std::fstream screenshot_file(screenshot_path, std::ios::binary | std::ios::in);
std::fstream paused_image(paused_image_path, std::ios::binary | std::ios::out);
paused_image << screenshot.rdbuf();
screenshot.close();
paused_image << screenshot_file.rdbuf();
screenshot_file.close();
paused_image.close();
}

Expand All @@ -101,10 +101,10 @@ class Cart {
}
// copy the paused image to the screenshot
std::fstream paused_image(paused_image_path, std::ios::binary | std::ios::in);
std::fstream screenshot(screenshot_path, std::ios::binary | std::ios::out);
screenshot << paused_image.rdbuf();
std::fstream screenshot_file(screenshot_path, std::ios::binary | std::ios::out);
screenshot_file << paused_image.rdbuf();
paused_image.close();
screenshot.close();
screenshot_file.close();
} else {
logger_.warn("paused image does not exist");
}
Expand Down Expand Up @@ -229,7 +229,7 @@ class Cart {
return ".sav";
}

virtual std::string get_screenshot_extension() const {
std::string get_screenshot_extension() const {
return ".bin";
}

Expand Down Expand Up @@ -278,31 +278,28 @@ class Cart {
}
}

std::string get_save_path(bool bypass_exist_check=false) {
std::string get_save_path(bool bypass_exist_check=false) const {
namespace fs = std::filesystem;
auto save_path =
savedir_ + "/" +
fs::path(get_rom_filename()).stem().string() +
fmt::format("_{}", menu_->get_selected_slot()) +
get_save_extension();
if (bypass_exist_check || fs::exists(save_path)) {
logger_.info("found: {}", save_path);
return save_path;
} else {
logger_.warn("Could not find {}", save_path);
}
return "";
}

std::string get_paused_image_path() {
std::string get_paused_image_path() const {
namespace fs = std::filesystem;
auto save_path =
savedir_ + "/paused" +
get_screenshot_extension();
return save_path;
}

std::string get_screenshot_path(bool bypass_exist_check=false) {
std::string get_screenshot_path(bool bypass_exist_check=false) const {
auto save_path = get_save_path(bypass_exist_check);
if (!save_path.empty()) {
return save_path + get_screenshot_extension();
Expand Down
Loading

0 comments on commit 8740531

Please sign in to comment.