Skip to content
Snippets Groups Projects
Commit 62c8638b authored by Deucе's avatar Deucе :ok_hand_tone4:
Browse files

Some low-hanging fruit Coverity issues

These are either correct and trivial to fix, or false positives,
but fixing is easy enough that it's not a problem.
parent f5a22fd0
No related branches found
No related tags found
1 merge request!488Overhaul LZH code
Pipeline #7529 passed
......@@ -408,7 +408,7 @@ int comGetModemStatus(COM_HANDLE handle)
static bool comSetFlags(COM_HANDLE handle, int flags, bool set)
{
int cmd = set ? TIOCMBIS : TIOCMBIC;
unsigned long cmd = set ? TIOCMBIS : TIOCMBIC;
return (ioctl(handle, cmd, &flags) == 0);
}
......
......@@ -2287,9 +2287,9 @@ all_done:
p++;
}
plen = get_hexstrlen(p, end);
p += plen * 2;
if (plen == -1)
return;
p += plen * 2;
mlen += ul * plen;
if (p <= end) {
if (*p == ';')
......@@ -2321,6 +2321,8 @@ all_done:
p++;
}
plen = get_hexstrlen(p, end);
if (plen == -1)
return;
for (i = 0; i < ul; i++) {
get_hexstr(p, end, out);
out += plen;
......@@ -2331,6 +2333,8 @@ all_done:
}
else {
plen = get_hexstrlen(p, end);
if (plen == -1)
return;
get_hexstr(p, end, out);
out += plen;
p += plen * 2;
......
......@@ -1242,8 +1242,12 @@ void curs_textmode(int mode)
getmaxyx(stdscr, maxy, maxx);
if (maxy > 255)
maxy = 255;
if (maxy < 0)
maxy = 24;
if (maxx > 255)
maxx = 255;
if (maxx < 0)
maxx = 80;
cio_textinfo.screenheight = maxy;
cio_textinfo.screenwidth = maxx;
if(has_colors())
......
......@@ -914,8 +914,14 @@ int zmodem_recv_data16(zmodem_t* zm, register unsigned char* p, unsigned maxlen,
crc = ucrc16(subpkt_type,crc);
rxd_crc = zmodem_rx(zm) << 8;
rxd_crc |= zmodem_rx(zm);
c = zmodem_rx(zm);
if (c < 0)
return c;
rxd_crc = c << 8;
c = zmodem_rx(zm);
if (c < 0)
return c;
rxd_crc |= c;
if(rxd_crc != crc) {
lprintf(zm, LOG_DEBUG, "%lu %s CRC ERROR (%04hX, expected: %04hX) Bytes=%u, subpacket type=%s"
......@@ -1049,20 +1055,24 @@ int zmodem_recv_nibble(zmodem_t* zm)
int zmodem_recv_hex(zmodem_t* zm)
{
int n1;
unsigned un1;
int n0;
unsigned un0;
int ret;
n1 = zmodem_recv_nibble(zm);
if(n1 < 0)
return n1;
un1 = n1;
n0 = zmodem_recv_nibble(zm);
if(n0 < 0)
return n0;
un0 = n0;
ret = (n1 << 4) | n0;
ret = (un1 << 4) | un0;
// lprintf(zm,LOG_DEBUG, __FUNCTION__ " returning: 0x%02X", ret);
......@@ -1539,9 +1549,13 @@ static unsigned new_window_size(zmodem_t* zm, time_t start, unsigned pos)
time_t elapsed = time(NULL) - start;
if(elapsed < 1)
elapsed = 1;
unsigned cps = (unsigned)(pos / elapsed);
uint64_t cps = (uint64_t)(pos / elapsed);
if (cps < 1)
cps = 1;
if (cps > UINT_MAX)
cps = UINT_MAX;
if (cps * zm->target_window_size > UINT_MAX)
cps = UINT_MAX / zm->target_window_size;
return cps * zm->target_window_size;
}
......
......@@ -87,9 +87,9 @@ modem_output_thread(void *args)
sent = 0;
while (com != COM_HANDLE_INVALID && sent < wr) {
ret = comWriteBuf(com, conn_api.wr_buf + sent, wr - sent);
sent += ret;
if (ret == COM_ERROR)
if (ret < 0)
break;
sent += ret;
}
}
else {
......
......@@ -65,7 +65,7 @@ rlogin_output_thread(void *args)
while (rlogin_sock != INVALID_SOCKET && sent < wr) {
if (socket_writable(rlogin_sock, 100)) {
ret = sendsocket(rlogin_sock, conn_api.wr_buf + sent, wr - sent);
if (ret == -1)
if (ret < 0)
break;
sent += ret;
}
......
......@@ -2072,9 +2072,12 @@ xmodem_download(struct bbslist *bbs, long mode, char *path)
break;
if ((cps = (unsigned)(file_bytes / t)) == 0)
cps = 1;
if (--total_files <= 0)
if (total_files == 0 || --total_files == 0)
extra_pass = true;
if (file_bytes < total_bytes)
total_bytes -= file_bytes;
else
total_bytes = 0;
if ((total_files > 1) && total_bytes) {
lprintf(LOG_INFO, "Remaining - Time: %lu:%02lu Files: %u KBytes: %" PRId64,
(total_bytes / cps) / 60,
......
......@@ -61,7 +61,7 @@ int safe_snprintf(char *dst, size_t size, const char *fmt, ...)
if(numchars==-1)
numchars=strlen(dst);
#endif
if(numchars>=(int)size && numchars>0)
if ((size_t)numchars >= size && numchars > 0)
numchars = size - 1;
return(numchars);
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment