fix more issues reported by coverity

This commit is contained in:
David Hrdlička
2020-01-15 18:48:22 +01:00
parent 94ba8ec38c
commit a575bd7e8b
9 changed files with 23 additions and 13 deletions

View File

@@ -1380,7 +1380,7 @@ mem_write_scatw(uint32_t addr, uint16_t val, void *priv)
}
if (chkaddr >= 0xc0000 && chkaddr < 0x100000) {
if (dev->regs[SCAT_RAM_WRITE_PROTECT] & (1 << ((chkaddr - 0xc0000) >> 15)))
if (dev != NULL && (dev->regs[SCAT_RAM_WRITE_PROTECT] & (1 << ((chkaddr - 0xc0000) >> 15))))
return;
}
@@ -1409,7 +1409,7 @@ mem_write_scatl(uint32_t addr, uint32_t val, void *priv)
}
if (chkaddr >= 0xc0000 && chkaddr < 0x100000) {
if (dev->regs[SCAT_RAM_WRITE_PROTECT] & (1 << ((chkaddr - 0xc0000) >> 15)))
if (dev != NULL && (dev->regs[SCAT_RAM_WRITE_PROTECT] & (1 << ((chkaddr - 0xc0000) >> 15))))
return;
}

View File

@@ -309,7 +309,7 @@ config_read(wchar_t *fn)
/* Create a new section and insert it. */
ns = malloc(sizeof(section_t));
memset(ns, 0x00, sizeof(section_t));
strncpy(ns->name, sname, sizeof(ns->name));
strncpy(ns->name, sname, sizeof(ns->name) - 1);
list_add(&ns->list, &config_head);
/* New section is now the current one. */

View File

@@ -125,9 +125,11 @@ image_is_hdx(const wchar_t *s, int check_signature)
f = plat_fopen((wchar_t *)s, L"rb");
if (!f)
return 0;
fseeko64(f, 0, SEEK_END);
if (fseeko64(f, 0, SEEK_END))
fatal("image_is_hdx(): Error while seeking");
filelen = ftello64(f);
fseeko64(f, 0, SEEK_SET);
if (fseeko64(f, 0, SEEK_SET))
fatal("image_is_hdx(): Error while seeking");
if (filelen < 44) {
if (f != NULL)
fclose(f);

View File

@@ -530,7 +530,7 @@ zip_load(zip_t *dev, wchar_t *fn)
if (fseek(dev->drv->f, dev->drv->base, SEEK_SET) == -1)
fatal("zip_load(): Error seeking to the beginning of the file\n");
memcpy(dev->drv->image_path, fn, sizeof(dev->drv->image_path));
wcsncpy(dev->drv->image_path, fn, sizeof_w(dev->drv->image_path));
return 1;
}

View File

@@ -571,8 +571,11 @@ uint8_t t3100e_ems_in(uint16_t addr, void *p)
{
struct t3100e_ems_regs *regs = (struct t3100e_ems_regs *)p;
return regs->page[port_to_page(addr)];
int page = port_to_page(addr);
if(page >= 0)
return regs->page[page];
else
fatal("t3100e_ems_in(): invalid address");
}
/* Write EMS page register */

View File

@@ -323,7 +323,7 @@ pc_init(int argc, wchar_t *argv[])
uint32_t *uid, *shwnd;
/* Grab the executable's full path. */
plat_get_exe_name(exe_path, sizeof(exe_path)-1);
plat_get_exe_name(exe_path, sizeof_w(exe_path)-1);
p = plat_get_filename(exe_path);
*p = L'\0';

View File

@@ -10,12 +10,12 @@
*
* Version: @(#)prt_escp.c 1.0.7 2019/09/23
*
* Authors: Michael Dr<44>ing, <michael@drueing.de>
* Authors: Michael Dr<44>ing, <michael@drueing.de>
* Fred N. van Kempen, <decwiz@yahoo.com>
*
* Based on code by Frederic Weymann (originally for DosBox.)
*
* Copyright 2018,2019 Michael Dr<44>ing.
* Copyright 2018,2019 Michael Dr<44>ing.
* Copyright 2019,2019 Fred N. van Kempen.
*
* Redistribution and use in source and binary forms, with
@@ -2058,6 +2058,11 @@ escp_init(void *lpt)
dev->lpt = lpt;
/* Create a full pathname for the font files. */
if(wcslen(exe_path) >= sizeof_w(dev->fontpath)) {
free(dev);
return(NULL);
}
wcscpy(dev->fontpath, exe_path);
plat_path_slash(dev->fontpath);
wcscat(dev->fontpath, L"roms/printer/fonts/");

View File

@@ -139,7 +139,7 @@ file_dlg_w(HWND hwnd, WCHAR *f, WCHAR *fn, int save)
* not use the contents of szFile to initialize itself.
*/
memcpy(ofn.lpstrFile, fn, (wcslen(fn) << 1) + 2);
ofn.nMaxFile = 259;
ofn.nMaxFile = sizeof_w(wopenfilestring);
ofn.lpstrFilter = f;
ofn.nFilterIndex = 1;
ofn.lpstrFileTitle = NULL;

View File

@@ -2846,6 +2846,7 @@ win_settings_hard_disks_add_proc(HWND hdlg, UINT message, WPARAM wParam, LPARAM
f = _wfopen(wopenfilestring, (existing & 1) ? L"rb" : L"wb");
if (f == NULL) {
hdd_add_file_open_error:
fclose(f);
settings_msgbox(MBX_ERROR, (existing & 1) ? (wchar_t *)IDS_4107 : (wchar_t *)IDS_4108);
return TRUE;
}
@@ -2876,7 +2877,6 @@ hdd_add_file_open_error:
} else {
fseeko64(f, 0, SEEK_END);
size = ftello64(f);
fclose(f);
if (((size % 17) == 0) && (size <= 142606336)) {
spt = 17;
if (size <= 26738688)