fixed problems found by cppcheck tool (patch by Maxim Derbasov)

This commit is contained in:
Stanislav Shwartsman 2015-01-03 13:53:52 +00:00
parent c7c92bb62b
commit 1f4d3e7194
9 changed files with 20 additions and 10 deletions

View File

@ -316,6 +316,7 @@ int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset)
dbg_printf("%s:%d: missing symbol name\n", file.name, line_num); dbg_printf("%s:%d: missing symbol name\n", file.name, line_num);
else else
dbg_printf("%s:%d: syntax error near '%s'\n", file.name, line_num, sym_name); dbg_printf("%s:%d: syntax error near '%s'\n", file.name, line_num, sym_name);
fclose(fp);
return -1; return -1;
} }
++sym_name; ++sym_name;
@ -333,6 +334,7 @@ int bx_dbg_symbol_command(const char* filename, bx_bool global, Bit32u offset)
} }
++line_num; ++line_num;
} }
fclose(fp);
return 0; return 0;
} }

View File

@ -1096,8 +1096,8 @@ bx_bool vvfat_image_t::read_sector_from_file(const char *path, Bit8u *buffer, Bi
return 0; return 0;
int offset = sector * 0x200; int offset = sector * 0x200;
if (::lseek(fd, offset, SEEK_SET) != offset) { if (::lseek(fd, offset, SEEK_SET) != offset) {
return 0;
::close(fd); ::close(fd);
return 0;
} }
int result = ::read(fd, buffer, 0x200); int result = ::read(fd, buffer, 0x200);
::close(fd); ::close(fd);
@ -1448,7 +1448,7 @@ bx_bool vvfat_image_t::write_file(const char *path, direntry_t *entry, bx_bool c
int fd; int fd;
Bit32u csize, fsize, fstart, cur, next, rsvd_clusters, bad_cluster; Bit32u csize, fsize, fstart, cur, next, rsvd_clusters, bad_cluster;
Bit64u offset; Bit64u offset;
Bit8u *buffer; Bit8u *buffer = NULL;
#ifndef WIN32 #ifndef WIN32
struct tm tv; struct tm tv;
struct utimbuf ut; struct utimbuf ut;
@ -1553,7 +1553,8 @@ bx_bool vvfat_image_t::write_file(const char *path, direntry_t *entry, bx_bool c
CloseHandle(hFile); CloseHandle(hFile);
} }
#endif #endif
if(buffer)
free(buffer);
return 1; return 1;
} }

View File

@ -798,6 +798,7 @@ int tftp_send_data(Bit8u *buffer, unsigned block_nr, tftp_session_t *s)
} }
if (fseek(fp, (block_nr - 1) * s->blksize_val, SEEK_SET) < 0) { if (fseek(fp, (block_nr - 1) * s->blksize_val, SEEK_SET) < 0) {
fclose(fp);
return tftp_send_error(buffer, 3, "Block not seekable", s); return tftp_send_error(buffer, 3, "Block not seekable", s);
} }
@ -991,6 +992,7 @@ int process_tftp(bx_devmodel_c *netdev, const Bit8u *data, unsigned data_len, Bi
return tftp_send_error(reply, 2, "Access violation", s); return tftp_send_error(reply, 2, "Access violation", s);
} }
if (fseek(fp, (block_nr - 1) * TFTP_BUFFER_SIZE, SEEK_SET) < 0) { if (fseek(fp, (block_nr - 1) * TFTP_BUFFER_SIZE, SEEK_SET) < 0) {
fclose(fp);
return tftp_send_error(reply, 3, "Block not seekable", s); return tftp_send_error(reply, 3, "Block not seekable", s);
} }
fwrite(reply, 1, tftp_len, fp); fwrite(reply, 1, tftp_len, fp);

View File

@ -3721,9 +3721,13 @@ bx_bool bx_sb16_buffer::puts(const char *data, ...)
while (string[index] != 0) while (string[index] != 0)
{ {
if (put((Bit8u) string[index]) == 0) if (put((Bit8u) string[index]) == 0)
return 0; // buffer full {
free(string);
return 0; // buffer full
}
index++; index++;
} }
free(string);
return 1; return 1;
} }

View File

@ -65,6 +65,7 @@ void bx_load32bitOSimagehack(void)
} }
if (feof(fp)) break; if (feof(fp)) break;
} }
fclose(fp);
} //if iolog file to load } //if iolog file to load
// Invoke proper hack depending on which OS image we're loading // Invoke proper hack depending on which OS image we're loading

View File

@ -84,7 +84,7 @@ void iofunctions::remove_logfn(logfunc_t *fn)
{ {
assert(n_logfn > 0); assert(n_logfn > 0);
int i = 0; int i = 0;
while ((fn != logfn_list[i]) && (i < n_logfn)) { while ((i < n_logfn) && (fn != logfn_list[i])) {
i++; i++;
}; };
if (i < n_logfn) { if (i < n_logfn) {
@ -434,6 +434,7 @@ void logfunctions::panic(const char *fmt, ...)
if (onoff[LOGLEV_PANIC] == ACT_FATAL) { if (onoff[LOGLEV_PANIC] == ACT_FATAL) {
va_start(ap, fmt); va_start(ap, fmt);
fatal(prefix, fmt, ap, 1); fatal(prefix, fmt, ap, 1);
va_end(ap);
} }
} }

View File

@ -360,7 +360,7 @@ memmove (dest, src, size)
dest[i] = src[i]; dest[i] = src[i];
} }
else if (dest > src) else if (dest > src)
for (i = size -1; i >= 0; --i) for (i = size -1; i < size; --i)
{ {
dest[i] = src[i]; dest[i] = src[i];
} }

View File

@ -514,8 +514,7 @@ void create_sparse_image(const char *filename, Bit64u size)
Bit8u *padding = new Bit8u[padtopagesize]; Bit8u *padding = new Bit8u[padtopagesize];
memset(padding, 0, padtopagesize); memset(padding, 0, padtopagesize);
if (padding == NULL)
fatal("ERROR: The disk image is not complete - could not create padding!");
if (bx_write_image(fd, sizesofar, padding, padtopagesize) != padtopagesize) { if (bx_write_image(fd, sizesofar, padding, padtopagesize) != padtopagesize) {
close(fd); close(fd);
fatal("ERROR: The disk image is not complete - could not write padding!"); fatal("ERROR: The disk image is not complete - could not write padding!");

View File

@ -50,8 +50,8 @@
int infd, outfd; int infd, outfd;
unsigned int delay = 60; // default delay, in seconds int delay = 60; // default delay, in seconds
unsigned int count_down = 0; int count_down = 0;
char buffer[BUF_SIZE]; char buffer[BUF_SIZE];
ssize_t readcnt, writecnt; ssize_t readcnt, writecnt;