fixed problems found by cppcheck tool (patch by Maxim Derbasov) - second round
This commit is contained in:
parent
2ca192eef7
commit
055da948a0
@ -372,7 +372,7 @@ void delay_ms(int n)
|
||||
int i, j;
|
||||
for(i = 0; i < n; i++) {
|
||||
#ifdef BX_QEMU
|
||||
volatile int k;
|
||||
volatile int k = 0;
|
||||
/* approximative ! */
|
||||
for(j = 0; j < 1000000; j++) {
|
||||
k++;
|
||||
|
@ -323,6 +323,7 @@ reparse:
|
||||
{
|
||||
if ((*tmp_buf_prev != '\n') && (*tmp_buf_prev != 0)) {
|
||||
strncpy(tmp_buf, tmp_buf_prev, sizeof(tmp_buf_prev));
|
||||
tmp_buf[sizeof(tmp_buf) - 1] = '\0';
|
||||
goto reparse;
|
||||
}
|
||||
}
|
||||
@ -379,6 +380,7 @@ void bx_get_command(void)
|
||||
charptr_ret = SIM->debug_get_next_command();
|
||||
if (charptr_ret) {
|
||||
strncpy(tmp_buf, charptr_ret, sizeof(tmp_buf));
|
||||
tmp_buf[sizeof(tmp_buf) - 2] = '\0';
|
||||
strcat(tmp_buf, "\n");
|
||||
// The returned string was allocated in wxmain.cc by "new char[]".
|
||||
// Free it with delete[].
|
||||
@ -395,7 +397,8 @@ void bx_get_command(void)
|
||||
// beware, returns NULL on end of file
|
||||
if (charptr_ret && strlen(charptr_ret) > 0) {
|
||||
add_history(charptr_ret);
|
||||
strcpy(tmp_buf, charptr_ret);
|
||||
strncpy(tmp_buf, charptr_ret, sizeof(tmp_buf));
|
||||
tmp_buf[sizeof(tmp_buf) - 2] = '\0';
|
||||
strcat(tmp_buf, "\n");
|
||||
free(charptr_ret);
|
||||
charptr_ret = &tmp_buf[0];
|
||||
@ -468,6 +471,7 @@ int bx_nest_infile(char *path)
|
||||
}
|
||||
|
||||
if ((bx_infile_stack_index+1) >= BX_INFILE_DEPTH) {
|
||||
fclose(tmp_fp);
|
||||
dbg_printf("%s: source files nested too deeply\n", argv0);
|
||||
return(0);
|
||||
}
|
||||
|
@ -509,6 +509,7 @@ void bx_gui_c::snapshot_handler(void)
|
||||
BX_INFO(("GFX snapshot: %u x %u x %u bpp (%u bytes)", BX_GUI_THIS guest_xres,
|
||||
BX_GUI_THIS guest_yres, BX_GUI_THIS guest_bpp, ilen));
|
||||
} else {
|
||||
close(fd);
|
||||
BX_ERROR(("snapshot button failed: cannot allocate memory"));
|
||||
return;
|
||||
}
|
||||
|
@ -631,6 +631,7 @@ int bx_write_rc(char *rc)
|
||||
strcpy(oldrc, "none");
|
||||
} else {
|
||||
strncpy(oldrc, rc, CI_PATH_LENGTH);
|
||||
oldrc[sizeof(oldrc) - 1] = '\0';
|
||||
}
|
||||
while (1) {
|
||||
if (ask_string("Save configuration to what file? To cancel, type 'none'.\n[%s] ", oldrc, newrc) < 0) return -1;
|
||||
|
@ -511,6 +511,7 @@ void PluginControlDialog::OnEvent(wxCommandEvent& event)
|
||||
{
|
||||
wxString tmpname(plugname->GetValue());
|
||||
strncpy(buf, tmpname.mb_str(wxConvUTF8), sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
if (SIM->opt_plugin_ctrl(buf, 1)) {
|
||||
tmpname.Printf(wxT("Plugin '%s' loaded"), buf);
|
||||
wxMessageBox(tmpname, wxT("Plugin Control"), wxOK | wxICON_INFORMATION, this);
|
||||
@ -523,6 +524,7 @@ void PluginControlDialog::OnEvent(wxCommandEvent& event)
|
||||
int i = pluglist->GetSelection();
|
||||
wxString tmpname = pluglist->GetString(i);
|
||||
strncpy(buf, tmpname.mb_str(wxConvUTF8), sizeof(buf));
|
||||
buf[sizeof(buf) - 1] = '\0';
|
||||
if (SIM->opt_plugin_ctrl(buf, 0)) {
|
||||
tmpname.Printf(wxT("Plugin '%s' unloaded"), buf);
|
||||
wxMessageBox(tmpname, wxT("Plugin Control"), wxOK | wxICON_INFORMATION, this);
|
||||
@ -1377,6 +1379,7 @@ void FloppyConfigDialog::OnEvent(wxCommandEvent& event)
|
||||
int cap = pstrMedia->u.choice->GetSelection();
|
||||
char name[1024];
|
||||
strncpy(name, pstrPath->u.text->GetValue().mb_str(wxConvUTF8), sizeof(name));
|
||||
name[sizeof(name) - 1] = '\0';
|
||||
if ((floppy_type_n_sectors[cap] > 0) && (strlen(name) > 0) && (strcmp(name, "none"))) {
|
||||
if (CreateImage(0, floppy_type_n_sectors[cap], name)) {
|
||||
wxString msg(wxT("Created a "));
|
||||
@ -1528,6 +1531,7 @@ int GetTextCtrlInt(wxTextCtrl *ctrl,
|
||||
wxString tmp(ctrl->GetValue());
|
||||
char buf[1024];
|
||||
strncpy(buf, tmp.mb_str(wxConvUTF8), sizeof(buf));
|
||||
buf[sizeof(buf)-1] = '\0';
|
||||
int n = strtol(buf, NULL, 0);
|
||||
if (n != LONG_MIN && n != LONG_MAX) {
|
||||
if (valid) *valid = true;
|
||||
|
@ -554,6 +554,7 @@ void MyFrame::OnConfigRead(wxCommandEvent& WXUNUSED(event))
|
||||
wxFileDialog *fdialog = new wxFileDialog(this, wxT("Read configuration"), wxT(""), wxT(""), wxT("*.*"), style);
|
||||
if (fdialog->ShowModal() == wxID_OK) {
|
||||
strncpy(bochsrc, fdialog->GetPath().mb_str(wxConvUTF8), sizeof(bochsrc));
|
||||
bochsrc[sizeof(bochsrc) - 1] = '\0';
|
||||
SIM->reset_all_param();
|
||||
SIM->read_rc(bochsrc);
|
||||
}
|
||||
@ -567,6 +568,7 @@ void MyFrame::OnConfigSave(wxCommandEvent& WXUNUSED(event))
|
||||
wxFileDialog *fdialog = new wxFileDialog(this, wxT("Save configuration"), wxT(""), wxT(""), wxT("*.*"), style);
|
||||
if (fdialog->ShowModal() == wxID_OK) {
|
||||
strncpy(bochsrc, fdialog->GetPath().mb_str(wxConvUTF8), sizeof(bochsrc));
|
||||
bochsrc[sizeof(bochsrc) - 1] = '\0';
|
||||
SIM->write_rc(bochsrc, 1);
|
||||
}
|
||||
delete fdialog;
|
||||
@ -583,6 +585,7 @@ void MyFrame::OnStateRestore(wxCommandEvent& WXUNUSED(event))
|
||||
|
||||
if (ddialog.ShowModal() == wxID_OK) {
|
||||
strncpy(sr_path, ddialog.GetPath().mb_str(wxConvUTF8), sizeof(sr_path));
|
||||
sr_path[sizeof(sr_path) - 1] = '\0';
|
||||
SIM->get_param_bool(BXPN_RESTORE_FLAG)->set(1);
|
||||
SIM->get_param_string(BXPN_RESTORE_PATH)->set(sr_path);
|
||||
}
|
||||
@ -1029,6 +1032,7 @@ int MyFrame::HandleAskParamString(bx_param_string_c *param)
|
||||
|
||||
if (ddialog->ShowModal() == wxID_OK)
|
||||
strncpy(newval, ddialog->GetPath().mb_str(wxConvUTF8), sizeof(newval));
|
||||
newval[sizeof(newval) - 1] = '\0';
|
||||
dialog = ddialog; // so I can delete it
|
||||
} else if (n_opt & param->IS_FILENAME) {
|
||||
// use file open dialog
|
||||
@ -1037,6 +1041,7 @@ int MyFrame::HandleAskParamString(bx_param_string_c *param)
|
||||
wxFileDialog *fdialog = new wxFileDialog(this, wxString(msg, wxConvUTF8), wxT(""), wxString(param->getptr(), wxConvUTF8), wxT("*.*"), style);
|
||||
if (fdialog->ShowModal() == wxID_OK)
|
||||
strncpy(newval, fdialog->GetPath().mb_str(wxConvUTF8), sizeof(newval));
|
||||
newval[sizeof(newval) - 1] = '\0';
|
||||
dialog = fdialog; // so I can delete it
|
||||
} else {
|
||||
// use simple string dialog
|
||||
@ -1044,6 +1049,7 @@ int MyFrame::HandleAskParamString(bx_param_string_c *param)
|
||||
wxTextEntryDialog *tdialog = new wxTextEntryDialog(this, wxString(msg, wxConvUTF8), wxT("Enter new value"), wxString(param->getptr(), wxConvUTF8), style);
|
||||
if (tdialog->ShowModal() == wxID_OK)
|
||||
strncpy(newval, tdialog->GetValue().mb_str(wxConvUTF8), sizeof(newval));
|
||||
newval[sizeof(newval) - 1] = '\0';
|
||||
dialog = tdialog; // so I can delete it
|
||||
}
|
||||
if (strlen(newval) > 0) {
|
||||
|
@ -1185,6 +1185,7 @@ void bx_pci_device_stub_c::load_pci_rom(const char *path)
|
||||
}
|
||||
ret = fstat(fd, &stat_buf);
|
||||
if (ret) {
|
||||
close(fd);
|
||||
BX_PANIC(("couldn't stat PCI ROM image file '%s'.", path));
|
||||
return;
|
||||
}
|
||||
|
@ -1115,7 +1115,7 @@ void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
|
||||
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
|
||||
ret = (int)BX_FD_THIS s.media[drive].vvfat->read(buffer, bytes);
|
||||
#if BX_WITH_MACOS
|
||||
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
|
||||
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive)) {
|
||||
ret = fd_read((char *) buffer, offset, bytes);
|
||||
#endif
|
||||
} else {
|
||||
@ -1136,7 +1136,7 @@ void bx_floppy_ctrl_c::floppy_xfer(Bit8u drive, Bit32u offset, Bit8u *buffer,
|
||||
if (BX_FD_THIS s.media[drive].vvfat_floppy) {
|
||||
ret = (int)BX_FD_THIS s.media[drive].vvfat->write(buffer, bytes);
|
||||
#if BX_WITH_MACOS
|
||||
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive))
|
||||
} else if (!strcmp(SIM->get_param_string(pname)->getptr(), SuperDrive)) {
|
||||
ret = fd_write((char *) buffer, offset, bytes);
|
||||
#endif
|
||||
} else {
|
||||
|
@ -260,7 +260,7 @@ void bx_speaker_c::beep_off()
|
||||
DWORD threadID;
|
||||
beep_info.msec = (DWORD)((bx_pc_system.time_usec() - usec_start) / 1000);
|
||||
beep_info.frequency = (DWORD)beep_frequency;
|
||||
CreateThread(NULL, 0, BeepThread, NULL, 0, &threadID);
|
||||
CloseHandle(CreateThread(NULL, 0, BeepThread, NULL, 0, &threadID));
|
||||
#endif
|
||||
}
|
||||
} else if (output_mode == BX_SPK_MODE_GUI) {
|
||||
|
@ -399,9 +399,11 @@ void BX_MEM_C::load_ROM(const char *path, bx_phy_address romaddress, Bit8u type)
|
||||
ret = fstat(fd, &stat_buf);
|
||||
if (ret) {
|
||||
if (type < 2) {
|
||||
close(fd);
|
||||
BX_PANIC(("ROM: couldn't stat ROM image file '%s'.", path));
|
||||
}
|
||||
else {
|
||||
close(fd);
|
||||
BX_ERROR(("ROM: couldn't stat ROM image file '%s'.", path));
|
||||
}
|
||||
return;
|
||||
@ -522,6 +524,7 @@ void BX_MEM_C::load_RAM(const char *path, bx_phy_address ramaddress, Bit8u type)
|
||||
}
|
||||
ret = fstat(fd, &stat_buf);
|
||||
if (ret) {
|
||||
close(fd);
|
||||
BX_PANIC(("RAM: couldn't stat RAM image file '%s'.", path));
|
||||
return;
|
||||
}
|
||||
|
@ -43,7 +43,7 @@ unsigned char cmos[] = {
|
||||
0x00, 0x48, 0x2b, 0x03, 0x03, 0x03, 0x04, 0xce,
|
||||
0x00, 0x3c, 0x19, 0xff, 0xff, 0xf0, 0x00, 0xf0,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, 0x7b
|
||||
};
|
||||
};
|
||||
|
||||
#else
|
||||
unsigned char cmos[] = {
|
||||
@ -64,7 +64,7 @@ unsigned char cmos[] = {
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, // 70
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
};
|
||||
#endif
|
||||
|
||||
int
|
||||
@ -75,23 +75,26 @@ main(int argc, char *argv[])
|
||||
if (argc != 2) {
|
||||
fprintf(stderr, "usage: %s pathname\n", argv[0]);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
fd = open(argv[1], O_WRONLY | O_CREAT
|
||||
#ifdef O_BINARY
|
||||
| O_BINARY
|
||||
| O_BINARY
|
||||
#endif
|
||||
, S_IRUSR | S_IWUSR
|
||||
);
|
||||
, S_IRUSR | S_IWUSR);
|
||||
if (fd < 0) {
|
||||
perror("trying to open cmos image file to write.\n");
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
ret = write(fd, cmos, sizeof(cmos));
|
||||
if (ret != sizeof(cmos)) {
|
||||
perror("write() did not write all CMOS data.\n");
|
||||
close(fd);
|
||||
exit(1);
|
||||
}
|
||||
}
|
||||
|
||||
close(fd);
|
||||
printf("CMOS data successfuly written to file '%s'.\n", argv[1]);
|
||||
return 0;
|
||||
}
|
||||
|
@ -192,7 +192,7 @@ int main (int argc, char **argv)
|
||||
Bit64s ll;
|
||||
while (1) {
|
||||
printf ("Enter a long int: ");
|
||||
gets (buf);
|
||||
fgets (buf, sizeof(buf), stdin);
|
||||
l = strtoul (buf, &endbuf, 10);
|
||||
printf ("As a long, %ld\n", l);
|
||||
printf ("Endbuf is at buf[%d]\n", endbuf-buf);
|
||||
|
Loading…
Reference in New Issue
Block a user