More fixes for sonarcloud findings

This commit is contained in:
Jasmine Iwanek
2023-05-16 15:43:20 -04:00
parent ab733b7f6c
commit ce451a2bf4
25 changed files with 688 additions and 501 deletions

View File

@@ -117,7 +117,7 @@ uint8_t
log2i(uint32_t i)
{
uint8_t ret = 0;
while ((i >>= 1))
while (i >>= 1)
ret++;
return ret;
}

View File

@@ -282,8 +282,9 @@ flash_writel(uint32_t addr, uint32_t val, void *p)
static void
intel_flash_add_mappings(flash_t *dev)
{
int max = 2, i = 0;
uint32_t base, fbase;
int max = 2;
uint32_t base;
uint32_t fbase;
uint32_t sub = 0x20000;
if (biosmask == 0x7ffff) {
@@ -294,7 +295,7 @@ intel_flash_add_mappings(flash_t *dev)
max = 4;
}
for (i = 0; i < max; i++) {
for (int i = 0; i < max; i++) {
if (biosmask == 0x7ffff)
base = 0x80000 + (i << 16);
else if (biosmask == 0x3ffff)

View File

@@ -90,12 +90,11 @@ FILE *
rom_fopen(const char *fn, char *mode)
{
char temp[1024];
rom_path_t *rom_path;
FILE *fp = NULL;
if (strstr(fn, "roms/") == fn) {
/* Relative path */
for (rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
path_append_filename(temp, rom_path->path, fn + 5);
if ((fp = plat_fopen(temp, mode)) != NULL) {
@@ -114,11 +113,10 @@ int
rom_getfile(char *fn, char *s, int size)
{
char temp[1024];
rom_path_t *rom_path;
if (strstr(fn, "roms/") == fn) {
/* Relative path */
for (rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
for (rom_path_t *rom_path = &rom_paths; rom_path != NULL; rom_path = rom_path->next) {
path_append_filename(temp, rom_path->path, fn + 5);
if (rom_present(temp)) {
@@ -147,10 +145,10 @@ rom_present(char *fn)
f = rom_fopen(fn, "rb");
if (f != NULL) {
(void) fclose(f);
return (1);
return 1;
}
return (0);
return 0;
}
uint8_t
@@ -212,7 +210,7 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t
if (f == NULL) {
rom_log("ROM: image '%s' not found\n", fn);
return (0);
return 0;
}
/* Make sure we only look at the base-256K offset. */
@@ -236,7 +234,7 @@ rom_load_linear_oddeven(const char *fn, uint32_t addr, int sz, int off, uint8_t
(void) fclose(f);
return (1);
return 1;
}
/* Load a ROM BIOS from its chips, interleaved mode. */
@@ -247,7 +245,7 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
if (f == NULL) {
rom_log("ROM: image '%s' not found\n", fn);
return (0);
return 0;
}
/* Make sure we only look at the base-256K offset. */
@@ -265,7 +263,7 @@ rom_load_linear(const char *fn, uint32_t addr, int sz, int off, uint8_t *ptr)
(void) fclose(f);
return (1);
return 1;
}
/* Load a ROM BIOS from its chips, linear mode with high bit flipped. */
@@ -276,7 +274,7 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t
if (f == NULL) {
rom_log("ROM: image '%s' not found\n", fn);
return (0);
return 0;
}
/* Make sure we only look at the base-256K offset. */
@@ -289,7 +287,7 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t
(void) fseek(f, 0, SEEK_END);
if (ftell(f) < sz) {
(void) fclose(f);
return (0);
return 0;
}
if (ptr != NULL) {
@@ -303,7 +301,7 @@ rom_load_linear_inverted(const char *fn, uint32_t addr, int sz, int off, uint8_t
(void) fclose(f);
return (1);
return 1;
}
/* Load a ROM BIOS from its chips, interleaved mode. */
@@ -312,7 +310,6 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
{
FILE *fl = rom_fopen(fnl, "rb");
FILE *fh = rom_fopen(fnh, "rb");
int c;
if (fl == NULL || fh == NULL) {
if (fl == NULL)
@@ -324,7 +321,7 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
else
(void) fclose(fh);
return (0);
return 0;
}
/* Make sure we only look at the base-256K offset. */
@@ -337,7 +334,7 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
if (ptr != NULL) {
(void) fseek(fl, off, SEEK_SET);
(void) fseek(fh, off, SEEK_SET);
for (c = 0; c < sz; c += 2) {
for (int c = 0; c < sz; c += 2) {
ptr[addr + c] = fgetc(fl) & 0xff;
ptr[addr + c + 1] = fgetc(fh) & 0xff;
}
@@ -346,7 +343,7 @@ rom_load_interleaved(const char *fnl, const char *fnh, uint32_t addr, int sz, in
(void) fclose(fh);
(void) fclose(fl);
return (1);
return 1;
}
static int
@@ -428,8 +425,10 @@ bios_readl(uint32_t addr, void *priv)
static void
bios_add(void)
{
int temp_cpu_type, temp_cpu_16bitbus = 1;
int temp_is286 = 0, temp_is6117 = 0;
int temp_cpu_type;
int temp_cpu_16bitbus = 1;
int temp_is286 = 0;
int temp_is6117 = 0;
if (/*AT && */ cpu_s) {
temp_cpu_type = cpu_s->cpu_type;
@@ -482,7 +481,7 @@ bios_load(const char *fn1, const char *fn2, uint32_t addr, int sz, int off, int
{
uint8_t ret = 0;
uint8_t *ptr = NULL;
int i, old_sz = sz;
int old_sz = sz;
/*
f0000, 65536 = prepare 64k rom starting at f0000, load 64k bios at 0000
@@ -512,7 +511,7 @@ bios_load(const char *fn1, const char *fn2, uint32_t addr, int sz, int off, int
if (!bios_only && (flags & FLAG_REP) && (old_sz >= 65536) && (sz < old_sz)) {
old_sz /= sz;
for (i = 0; i < (old_sz - 1); i++) {
for (int i = 0; i < (old_sz - 1); i++) {
rom_log("Copying ptr[%08X] to ptr[%08X]\n", addr - biosaddr, i * sz);
memcpy(&(ptr[i * sz]), &(ptr[addr - biosaddr]), sz);
}
@@ -591,7 +590,7 @@ rom_init(rom_t *rom, const char *fn, uint32_t addr, int sz, int mask, int off, u
NULL, NULL, NULL,
rom->rom, flags | MEM_MAPPING_ROM_WS, rom);
return (0);
return 0;
}
int
@@ -620,7 +619,7 @@ rom_init_oddeven(rom_t *rom, const char *fn, uint32_t addr, int sz, int mask, in
NULL, NULL, NULL,
rom->rom, flags | MEM_MAPPING_ROM_WS, rom);
return (0);
return 0;
}
int
@@ -647,5 +646,5 @@ rom_init_interleaved(rom_t *rom, const char *fnl, const char *fnh, uint32_t addr
NULL, NULL, NULL,
rom->rom, flags | MEM_MAPPING_ROM_WS, rom);
return (0);
return 0;
}

View File

@@ -29,7 +29,8 @@
#include <86box/mem.h>
#include <86box/smram.h>
static smram_t *base_smram, *last_smram;
static smram_t *base_smram;
static smram_t *last_smram;
static uint8_t use_separate_smram = 0;
static uint8_t smram[0x40000];
@@ -135,7 +136,8 @@ smram_writel(uint32_t addr, uint32_t val, void *priv)
void
smram_backup_all(void)
{
smram_t *temp_smram = base_smram, *next;
smram_t *temp_smram = base_smram;
smram_t *next;
while (temp_smram != NULL) {
temp_smram->old_host_base = temp_smram->host_base;
@@ -150,7 +152,8 @@ smram_backup_all(void)
void
smram_recalc_all(int ret)
{
smram_t *temp_smram = base_smram, *next;
smram_t *temp_smram = base_smram;
smram_t *next;
if (base_smram == NULL)
return;
@@ -316,7 +319,8 @@ smram_disable(smram_t *smr)
void
smram_disable_all(void)
{
smram_t *temp_smram = base_smram, *next;
smram_t *temp_smram = base_smram;
smram_t *next;
while (temp_smram != NULL) {
smram_disable(temp_smram);
@@ -339,7 +343,7 @@ smram_enable_ex(smram_t *smr, uint32_t host_base, uint32_t ram_base, uint32_t si
if ((size != 0x00000000) && (flags_normal || flags_smm)) {
smr->host_base = host_base;
smr->ram_base = ram_base,
smr->ram_base = ram_base;
smr->size = size;
mem_mapping_set_addr(&(smr->mapping), smr->host_base, smr->size);

View File

@@ -92,7 +92,9 @@ comp_ui16_rev(const void *elem1, const void *elem2)
void
spd_populate(uint16_t *rows, uint8_t slot_count, uint16_t total_size, uint16_t min_module_size, uint16_t max_module_size, uint8_t enable_asym)
{
uint8_t row, next_empty_row, split, i;
uint8_t row;
uint8_t next_empty_row;
uint8_t split;
uint16_t asym;
/* Populate rows with modules in power-of-2 capacities. */
@@ -138,7 +140,7 @@ spd_populate(uint16_t *rows, uint8_t slot_count, uint16_t total_size, uint16_t m
/* Find next empty row. */
next_empty_row = 0;
for (i = row + 1; i < slot_count && !next_empty_row; i++) {
for (uint8_t i = row + 1; i < slot_count && !next_empty_row; i++) {
if (!rows[i])
next_empty_row = i;
}
@@ -176,8 +178,13 @@ spd_write_part_no(char *part_no, char *type, uint16_t size)
void
spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
{
uint8_t slot, slot_count, row, i;
uint16_t min_module_size, rows[SPD_MAX_SLOTS], asym;
uint8_t slot;
uint8_t slot_count;
uint8_t row;
uint8_t i;
uint16_t min_module_size;
uint16_t rows[SPD_MAX_SLOTS];
uint16_t asym;
spd_edo_t *edo_data;
spd_sdram_t *sdram_data;
@@ -336,8 +343,11 @@ spd_register(uint8_t ram_type, uint8_t slot_mask, uint16_t max_module_size)
void
spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit)
{
uint8_t row, dimm, drb, apollo = 0;
uint16_t size, rows[SPD_MAX_SLOTS];
uint8_t dimm;
uint8_t drb;
uint8_t apollo = 0;
uint16_t size;
uint16_t rows[SPD_MAX_SLOTS];
/* Special case for VIA Apollo Pro family, which jumps from 5F to 56. */
if (reg_max < reg_min) {
@@ -353,7 +363,7 @@ spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit
/* Write DRBs for each row. */
spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit);
for (row = 0; row <= (reg_max - reg_min); row++) {
for (uint8_t row = 0; row <= (reg_max - reg_min); row++) {
dimm = (row >> 1);
size = 0;
@@ -392,8 +402,11 @@ spd_write_drbs(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit
void
spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit)
{
uint8_t row, dimm, drb;
uint16_t size, row_val = 0, rows[SPD_MAX_SLOTS];
uint8_t dimm;
uint8_t drb;
uint16_t size;
uint16_t row_val = 0;
uint16_t rows[SPD_MAX_SLOTS];
int shift;
/* No SPD: split SIMMs into pairs as if they were "DIMM"s. */
@@ -404,7 +417,7 @@ spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t
/* Write DRBs for each row. */
spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit);
for (row = 0; row <= (reg_max - reg_min); row++) {
for (uint8_t row = 0; row <= (reg_max - reg_min); row++) {
dimm = (row >> 1);
size = 0;
@@ -441,9 +454,10 @@ spd_write_drbs_with_ext(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t
void
spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint8_t drb_unit)
{
uint8_t row, dimm;
uint8_t dimm;
uint8_t drb;
uint16_t size, size_acc = 0;
uint16_t size;
uint16_t size_acc = 0;
uint16_t rows[SPD_MAX_SLOTS];
/* No SPD: split SIMMs into pairs as if they were "DIMM"s. */
@@ -454,7 +468,7 @@ spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint
/* Write DRBs for each row. */
spd_log("SPD: Writing DRBs... regs=[%02X:%02X] unit=%d\n", reg_min, reg_max, drb_unit);
for (row = 0; row <= (reg_max - reg_min); row += 2) {
for (uint8_t row = 0; row <= (reg_max - reg_min); row += 2) {
dimm = (row >> 2);
size = 0;
@@ -493,7 +507,8 @@ spd_write_drbs_interleaved(uint8_t *regs, uint8_t reg_min, uint8_t reg_max, uint
void
spd_write_drbs_ali1621(uint8_t *regs, uint8_t reg_min, uint8_t reg_max)
{
uint8_t dimm, drb;
uint8_t dimm;
uint8_t drb;
uint16_t size;
uint16_t rows[SPD_MAX_SLOTS];

View File

@@ -89,7 +89,7 @@ static char flash_path[1024];
#define SST39LF080 0xd800
#define SST39LF016 0xd900
/*
#if 0
// 16 wide
#define SST39WF400 0x272f
#define SST39WF400B 0x272e
@@ -103,7 +103,7 @@ static char flash_path[1024];
#define SST39LF400 0x2780
#define SST39LF800 0x2781
#define SST39LF160 0x2782
*/
#endif
#define SST49LF002 0x5700
#define SST49LF020 0x6100
@@ -150,7 +150,8 @@ sst_sector_erase(sst_t *dev, uint32_t addr)
static void
sst_new_command(sst_t *dev, uint32_t addr, uint8_t val)
{
uint32_t base = 0x00000, size = dev->size;
uint32_t base = 0x00000;
uint32_t size = dev->size;
if (dev->command_state == 5)
switch (val) {
@@ -230,11 +231,10 @@ static void
sst_page_write(void *priv)
{
sst_t *dev = (sst_t *) priv;
int i;
if (dev->last_addr != 0xffffffff) {
dev->page_base = dev->last_addr & dev->page_mask;
for (i = 0; i < 128; i++) {
for (uint8_t i = 0; i < 128; i++) {
if (dev->page_dirty[i]) {
if (((dev->page_base + i) < 0x2000) && (dev->bbp_first_8k & 0x01))
continue;
@@ -419,14 +419,15 @@ sst_readl(uint32_t addr, void *p)
static void
sst_add_mappings(sst_t *dev)
{
int i = 0, count;
uint32_t base, fbase;
int count;
uint32_t base;
uint32_t fbase;
uint32_t root_base;
count = dev->size >> 16;
root_base = 0x100000 - dev->size;
for (i = 0; i < count; i++) {
for (int i = 0; i < count; i++) {
base = root_base + (i << 16);
fbase = base & biosmask;