Fix a bunch of warning raised by the new build warning options

A lot of them are related to signedness or type range limitation.
A lot are not actual issues and work find in practice, but a few
lead to actual bad behavior.

This makes all the conversion explicit to mark intent.

Signed-off-by: Sylvain Munaut <tnt@246tNt.com>
Change-Id: I992b9bc51659e85966651b1146091501b8f149f5
This commit is contained in:
Sylvain Munaut 2022-01-09 11:40:12 +01:00
parent 35a9cf0b99
commit 73d7184088
6 changed files with 12 additions and 15 deletions

View File

@ -264,10 +264,7 @@ _e1d_ctl_ts_query(void *data, struct msgb *msgb, struct msgb *rmsgb, int *rfd)
if (!line) if (!line)
return 0; return 0;
n = (hdr->ts == E1DP_INVALID) ? 32 : ( n = (hdr->ts == E1DP_INVALID) ? 32 : ((hdr->ts < 31) ? 1 : 0);
((hdr->ts >= 0) && (hdr->ts < 31)) ? 1 : 0
);
if (!n) if (!n)
return 0; return 0;

View File

@ -55,7 +55,7 @@ static void notify_user(struct osmo_e1f_instance *e1i, enum osmo_e1f_notify_even
int osmo_e1f_instance_init(struct osmo_e1f_instance *e1i, const char *name, e1_notify_cb cb, int osmo_e1f_instance_init(struct osmo_e1f_instance *e1i, const char *name, e1_notify_cb cb,
bool crc4_enabled, void *priv) bool crc4_enabled, void *priv)
{ {
int i; unsigned int i;
e1i->crc4_enabled = crc4_enabled; e1i->crc4_enabled = crc4_enabled;
e1i->notify_cb = cb; e1i->notify_cb = cb;
@ -101,7 +101,7 @@ void osmo_e1f_ts_reset(struct osmo_e1f_instance_ts *e1t)
* \param[in] e1t E1 instance which we are to stop */ * \param[in] e1t E1 instance which we are to stop */
void osmo_e1f_instance_reset(struct osmo_e1f_instance *e1i) void osmo_e1f_instance_reset(struct osmo_e1f_instance *e1i)
{ {
int i; unsigned int i;
align_fsm_reset(e1i); align_fsm_reset(e1i);
@ -290,7 +290,7 @@ static void e1_tx_update_crc4(struct osmo_e1f_instance *e1i, const uint8_t *out_
* \returns 0 on success, negative on error */ * \returns 0 on success, negative on error */
int osmo_e1f_pull_tx_frame(struct osmo_e1f_instance *e1i, uint8_t *out_frame) int osmo_e1f_pull_tx_frame(struct osmo_e1f_instance *e1i, uint8_t *out_frame)
{ {
int i; unsigned int i;
if (e1i->tx.ais) { if (e1i->tx.ais) {
memset(out_frame, 0xff, 32); memset(out_frame, 0xff, 32);
@ -684,7 +684,7 @@ flush:
*/ */
int osmo_e1f_rx_frame(struct osmo_e1f_instance *e1i, const uint8_t *in_frame) int osmo_e1f_rx_frame(struct osmo_e1f_instance *e1i, const uint8_t *in_frame)
{ {
int i; unsigned int i;
e1_rx_update_crc4(e1i, in_frame); e1_rx_update_crc4(e1i, in_frame);

View File

@ -87,7 +87,7 @@ _e1_tx_hdlcfs(struct e1_ts *ts, uint8_t *buf, int len)
if (!ts->hdlc.tx_len) { if (!ts->hdlc.tx_len) {
rv = recv(ts->fd, ts->hdlc.tx_buf, sizeof(ts->hdlc.tx_buf), MSG_TRUNC); rv = recv(ts->fd, ts->hdlc.tx_buf, sizeof(ts->hdlc.tx_buf), MSG_TRUNC);
if (rv > 0) { if (rv > 0) {
if (rv > sizeof(ts->hdlc.tx_buf)) { if (rv > (int)sizeof(ts->hdlc.tx_buf)) {
LOGPTS(ts, DXFR, LOGL_ERROR, "Truncated message: Client tried to " LOGPTS(ts, DXFR, LOGL_ERROR, "Truncated message: Client tried to "
"send %d bytes but our buffer is limited to %lu\n", "send %d bytes but our buffer is limited to %lu\n",
rv, sizeof(ts->hdlc.tx_buf)); rv, sizeof(ts->hdlc.tx_buf));
@ -151,7 +151,7 @@ _e1_ts_read(struct e1_ts *ts, uint8_t *buf, size_t len)
LOGPTS(ts, DE1D, LOGL_ERROR, "dead socket during read: %s\n", LOGPTS(ts, DE1D, LOGL_ERROR, "dead socket during read: %s\n",
strerror(errno)); strerror(errno));
e1_ts_stop(ts); e1_ts_stop(ts);
} else if (l < len) { } else if (l < (int)len) {
LOGPTS(ts, DE1D, LOGL_NOTICE, "TS read underflow: We had %zu bytes to read, " LOGPTS(ts, DE1D, LOGL_NOTICE, "TS read underflow: We had %zu bytes to read, "
"but socket returned only %d\n", len, l); "but socket returned only %d\n", len, l);
} }
@ -297,7 +297,7 @@ _e1_ts_write(struct e1_ts *ts, const uint8_t *buf, size_t len)
LOGPTS(ts, DE1D, LOGL_ERROR, "dead socket during write: %s\n", LOGPTS(ts, DE1D, LOGL_ERROR, "dead socket during write: %s\n",
strerror(errno)); strerror(errno));
e1_ts_stop(ts); e1_ts_stop(ts);
} else if (rv < len) { } else if (rv < (int)len) {
LOGPTS(ts, DE1D, LOGL_NOTICE, "TS write overflow: We had %zu bytes to send, " LOGPTS(ts, DE1D, LOGL_NOTICE, "TS write overflow: We had %zu bytes to send, "
"but write returned only %d\n", len, rv); "but write returned only %d\n", len, rv);
} }

View File

@ -94,7 +94,7 @@ _e1dp_server_request(struct osmo_e1dp_server_conn *conn, struct msgb *msgb)
/* Check payload length */ /* Check payload length */
if ((h->payload_len >= 0) && if ((h->payload_len >= 0) &&
(h->payload_len != (msgb_length(msgb) - sizeof(struct osmo_e1dp_msg_hdr)))) (h->payload_len != (int)(msgb_length(msgb) - sizeof(struct osmo_e1dp_msg_hdr))))
{ {
LOGP(DE1D, LOGL_ERROR, "Invalid payload for message type: %d / (%d/%d/%d).\n", LOGP(DE1D, LOGL_ERROR, "Invalid payload for message type: %d / (%d/%d/%d).\n",
hdr->type, hdr->intf, hdr->line, hdr->ts); hdr->type, hdr->intf, hdr->line, hdr->ts);

View File

@ -189,7 +189,7 @@ _e1uf_xfr(struct libusb_transfer *xfr)
flow->cb(flow, flow->cb(flow,
libusb_get_iso_packet_buffer_simple(xfr, j), libusb_get_iso_packet_buffer_simple(xfr, j),
(xfr->iso_packet_desc[j].status == LIBUSB_TRANSFER_COMPLETED) ? (xfr->iso_packet_desc[j].status == LIBUSB_TRANSFER_COMPLETED) ?
xfr->iso_packet_desc[j].actual_length : -1 (int)xfr->iso_packet_desc[j].actual_length : -1
); );
len += (xfr->iso_packet_desc[j].length = flow->size); len += (xfr->iso_packet_desc[j].length = flow->size);
} }
@ -359,7 +359,7 @@ static void interrupt_ep_cb(struct libusb_transfer *xfer)
switch (irq->type) { switch (irq->type) {
case ICE1USB_IRQ_T_ERRCNT: case ICE1USB_IRQ_T_ERRCNT:
if (xfer->actual_length < sizeof(*irq)) { if (xfer->actual_length < (int)sizeof(*irq)) {
LOGPLI(line, DE1D, LOGL_ERROR, "Short ERRCNT interrupt: %u<%zu\n", LOGPLI(line, DE1D, LOGL_ERROR, "Short ERRCNT interrupt: %u<%zu\n",
xfer->actual_length, sizeof(*irq)); xfer->actual_length, sizeof(*irq));
break; break;

View File

@ -107,7 +107,7 @@ const struct value_string e1_line_mode_names[] = {
static void vty_dump_line(struct vty *vty, const struct e1_line *line) static void vty_dump_line(struct vty *vty, const struct e1_line *line)
{ {
int tn; unsigned int tn;
vty_out(vty, "Interface #%u, Line #%u, Mode %s%s%s:%s", line->intf->id, line->id, vty_out(vty, "Interface #%u, Line #%u, Mode %s%s%s:%s", line->intf->id, line->id,
get_value_string(e1_line_mode_names, line->mode), get_value_string(e1_line_mode_names, line->mode),