Name of user not set #1005536 has uploaded this change for review. ( https://review.coreboot.org/c/coreboot/+/83378?usp=email )
Change subject: libpayload/commonlib: warning fixes ......................................................................
libpayload/commonlib: warning fixes
Compiling coreinfo resulted in lots of errors due to -Werror flag.
This patch fixes: - warnings related to signed/unsigned integer comparison - unused parameters
qsort is patched to use offset arithmetic instead of pointer arithmetic.
Change-Id: I23462a9c920a57e9cdf6a98174f0bea1a8b1ed19 --- M payloads/libpayload/curses/tinycurses.c M payloads/libpayload/drivers/i8042/keyboard.c M payloads/libpayload/drivers/options.c M payloads/libpayload/drivers/pci_ops.c M payloads/libpayload/drivers/storage/ahci_common.c M payloads/libpayload/drivers/storage/ata.c M payloads/libpayload/drivers/storage/nvme.c M payloads/libpayload/drivers/usb/ehci.c M payloads/libpayload/drivers/usb/ohci.c M payloads/libpayload/drivers/usb/ohci_private.h M payloads/libpayload/drivers/usb/quirks.c M payloads/libpayload/drivers/usb/usb.c M payloads/libpayload/drivers/usb/usb_dev.c M payloads/libpayload/drivers/usb/usbhid.c M payloads/libpayload/drivers/usb/usbhub.c M payloads/libpayload/drivers/usb/usbmsc.c M payloads/libpayload/drivers/usb/xhci.c M payloads/libpayload/drivers/usb/xhci_devconf.c M payloads/libpayload/drivers/usb/xhci_events.c M payloads/libpayload/drivers/usb/xhci_private.h M payloads/libpayload/drivers/video/corebootfb.c M payloads/libpayload/drivers/video/graphics.c M payloads/libpayload/drivers/video/vga.c M payloads/libpayload/drivers/video/video.c M payloads/libpayload/include/libpayload.h M payloads/libpayload/include/sysinfo.h M payloads/libpayload/include/usb/usb.h M payloads/libpayload/libc/coreboot.c M payloads/libpayload/libc/hexdump.c M payloads/libpayload/libc/lib.c M payloads/libpayload/libc/malloc.c M payloads/libpayload/libc/printf.c M payloads/libpayload/libc/qsort.c M payloads/libpayload/libc/string.c M payloads/libpayload/libc/time.c M payloads/libpayload/libcbfs/cbfs.c M payloads/libpayload/liblz4/lz4_wrapper.c M payloads/libpayload/libpci/libpci.c M src/commonlib/bsd/cbfs_mcache.c M src/commonlib/bsd/cbfs_private.c 40 files changed, 197 insertions(+), 149 deletions(-)
git pull ssh://review.coreboot.org:29418/coreboot refs/changes/78/83378/1
diff --git a/payloads/libpayload/curses/tinycurses.c b/payloads/libpayload/curses/tinycurses.c index d3bf84e..3d37ef7 100644 --- a/payloads/libpayload/curses/tinycurses.c +++ b/payloads/libpayload/curses/tinycurses.c @@ -171,6 +171,7 @@ /* Compute a rendition of the given char correct for the current context. */ static inline NCURSES_CH_T render_char(WINDOW *win, NCURSES_CH_T ch) { + (void)win; /* TODO. */ return ch; } @@ -219,6 +220,7 @@ // void delscreen(SCREEN *) {} int delwin(WINDOW *win) { + (void)win; /* TODO: Don't try to delete stdscr. */ /* TODO: Don't delete parent windows before subwindows. */
@@ -232,6 +234,11 @@ } WINDOW *derwin(WINDOW *orig, int num_lines, int num_columns, int begy, int begx) { + (void)orig; + (void)num_lines; + (void)num_columns; + (void)begy; + (void)begx; #if 0 WINDOW *win = NULL; int i; @@ -341,7 +348,12 @@ // bool is_linetouched (WINDOW *,int) {} // bool is_wintouched (WINDOW *) {} // NCURSES_CONST char * keyname (int) {} -int keypad (WINDOW *win, bool flag) { /* TODO */ return 0; } +int keypad (WINDOW *win, bool flag) { + (void)win; + (void)flag; + /* TODO */ + return 0; +} // char killchar (void) {} /* D */ int leaveok(WINDOW *win, bool flag) { win->_leaveok = flag; return OK; } // char *longname (void) {} @@ -488,7 +500,7 @@ // chtype termattrs (void) {} // char *termname (void) {} // int typeahead (int) {} -int ungetch(int ch) { /* TODO */ return ERR; } +int ungetch(int ch) { (void)ch; /* TODO */ return ERR; } // void use_env (bool) {} // int vidattr (chtype) {} // int vidputs (chtype, int (*)(int)) {} @@ -569,6 +581,7 @@ } int wattr_on(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { + (void)opts; if (at & A_COLOR) win->_color = PAIR_NUMBER(at); // toggle_attr_on(WINDOW_ATTRS(win), at); @@ -576,13 +589,14 @@ } int wattr_off(WINDOW *win, attr_t at, void *opts GCC_UNUSED) { + (void)opts; if (at & A_COLOR) win->_color = 0; // toggle_attr_off(WINDOW_ATTRS(win), at); return 0; } // int wbkgd (WINDOW *, chtype) {} -void wbkgdset(WINDOW *win, chtype ch) { /* TODO */ } +void wbkgdset(WINDOW *win, chtype ch) { (void)win; (void)ch; /* TODO */ }
int wborder(WINDOW *win, chtype ls, chtype rs, chtype ts, chtype bs, chtype tl, chtype tr, chtype bl, chtype br) @@ -634,7 +648,7 @@ return OK; } // int wclrtobot (WINDOW *) {} -int wclrtoeol(WINDOW *win) { /* TODO */ return ERR; } +int wclrtoeol(WINDOW *win) { (void)win; /* TODO */ return ERR; } int wcolor_set(WINDOW *win, short color_pair_number, void *opts) { if (!opts && (color_pair_number >= 0) @@ -697,6 +711,7 @@ } /* D */ chtype winch(WINDOW *win) { + (void)win; //// TODO // return (CharOf(win->_line[win->_cury].text[win->_curx]) | // AttrOf(win->_line[win->_cury].text[win->_curx])); diff --git a/payloads/libpayload/drivers/i8042/keyboard.c b/payloads/libpayload/drivers/i8042/keyboard.c index 2453392..ee1f214 100644 --- a/payloads/libpayload/drivers/i8042/keyboard.c +++ b/payloads/libpayload/drivers/i8042/keyboard.c @@ -483,7 +483,7 @@ } }
-bool keyboard_havechar(void) +int keyboard_havechar(void) { keyboard_poll(); return i8042_data_ready_ps2() && @@ -599,7 +599,7 @@
int keyboard_set_layout(char *country) { - int i; + size_t i;
for (i=0; i<ARRAY_SIZE(keyboard_layouts); i++) { if (strncmp(keyboard_layouts[i].country, country, @@ -616,7 +616,7 @@ }
static struct console_input_driver cons = { - .havekey = (int (*)(void))keyboard_havechar, + .havekey = keyboard_havechar, .getchar = keyboard_getchar, .input_type = CONSOLE_INPUT_TYPE_EC, }; diff --git a/payloads/libpayload/drivers/options.c b/payloads/libpayload/drivers/options.c index b6d2342..e24a83a 100644 --- a/payloads/libpayload/drivers/options.c +++ b/payloads/libpayload/drivers/options.c @@ -211,7 +211,7 @@ } }
-struct cb_cmos_enums *next_cmos_enum_of_id(struct cb_cmos_enums *cmos_enum, int id) +struct cb_cmos_enums *next_cmos_enum_of_id(struct cb_cmos_enums *cmos_enum, u32 id) { while ((cmos_enum = next_cmos_enum(cmos_enum))) { if (cmos_enum->config_id == id) { @@ -221,7 +221,7 @@ return NULL; }
-struct cb_cmos_enums *first_cmos_enum_of_id(struct cb_cmos_option_table *option_table, int id) +struct cb_cmos_enums *first_cmos_enum_of_id(struct cb_cmos_option_table *option_table, u32 id) { struct cb_cmos_enums *cmos_enum = first_cmos_enum(option_table); if (!cmos_enum) { diff --git a/payloads/libpayload/drivers/pci_ops.c b/payloads/libpayload/drivers/pci_ops.c index 79c3bc0..0489780 100644 --- a/payloads/libpayload/drivers/pci_ops.c +++ b/payloads/libpayload/drivers/pci_ops.c @@ -30,7 +30,7 @@ #include <libpayload.h> #include <pci.h>
-static int find_on_bus(int bus, unsigned short vid, unsigned short did, +static int find_on_bus(unsigned int bus, unsigned short vid, unsigned short did, pcidev_t * dev) { int devfn; @@ -48,7 +48,7 @@ val == 0x0000ffff || val == 0xffff0000) continue;
- if (val == ((did << 16) | vid)) { + if (val == (((u32)did << 16) | vid)) { *dev = PCI_DEV(bus, slot, func); return 1; } diff --git a/payloads/libpayload/drivers/storage/ahci_common.c b/payloads/libpayload/drivers/storage/ahci_common.c index abc67c3..90f4fea 100644 --- a/payloads/libpayload/drivers/storage/ahci_common.c +++ b/payloads/libpayload/drivers/storage/ahci_common.c @@ -201,7 +201,7 @@ if (buf_len > 0) { size_t prdt_len; u8 *buf; - int i; + size_t i;
prdt_len = ((buf_len - 1) >> BYTES_PER_PRD_SHIFT) + 1; const size_t max_prdt_len = ARRAY_SIZE(dev->cmdtable->prdt); diff --git a/payloads/libpayload/drivers/storage/ata.c b/payloads/libpayload/drivers/storage/ata.c index 00f1d88..4eb272c 100644 --- a/payloads/libpayload/drivers/storage/ata.c +++ b/payloads/libpayload/drivers/storage/ata.c @@ -74,10 +74,11 @@
/* Read all sector aligned blocks. */ const size_t sec_count = (blk_count & ~mask) >> shift; - const int sec_read = dev->read_sectors( + const ssize_t sec_read_result = dev->read_sectors( dev, sec_start, sec_count, blk_buf); - if (sec_read < 0) + if (sec_read_result < 0) goto _free_ret; + size_t sec_read = sec_read_result; ret += sec_read << shift; if (sec_read != sec_count) goto _free_ret; @@ -138,6 +139,11 @@ const lba_t start, const size_t count, const unsigned char *const buf) { + (void)dev; + (void)start; + (void)count; + (void)buf; + printf("ata: No write support implemented.\n"); return -1; } @@ -182,14 +188,14 @@ */ char *ata_strncpy(char *const dest, const u16 *const src, const size_t n) { - int i; + size_t i;
for (i = 0; i < (n - 1); i += 2) { dest[i] = ((const char *)src)[i + 1]; dest[i + 1] = ((const char *)src)[i]; }
- for (i = n - 2; i >= 0; --i) + for (i = n - 1; i-- > 0;) if (dest[i] != ' ') break; dest[i + 1] = '\0'; diff --git a/payloads/libpayload/drivers/storage/nvme.c b/payloads/libpayload/drivers/storage/nvme.c index f6076d3..7d78945 100644 --- a/payloads/libpayload/drivers/storage/nvme.c +++ b/payloads/libpayload/drivers/storage/nvme.c @@ -60,6 +60,7 @@
static storage_poll_t nvme_poll(struct storage_dev *dev) { + (void)dev; return POLL_MEDIUM_PRESENT; }
diff --git a/payloads/libpayload/drivers/usb/ehci.c b/payloads/libpayload/drivers/usb/ehci.c index 822fdb1..a88fff9 100644 --- a/payloads/libpayload/drivers/usb/ehci.c +++ b/payloads/libpayload/drivers/usb/ehci.c @@ -150,6 +150,7 @@
static void ehci_reinit(hci_t *controller) { + (void)controller; }
static int ehci_set_periodic_schedule(ehci_t *ehcic, int enable) @@ -164,7 +165,7 @@ */ enable = enable ? HC_OP_PERIODIC_SCHED_STAT : 0; int timeout = 100000; /* time out after 100ms */ - while (((ehcic->operation->usbsts & HC_OP_PERIODIC_SCHED_STAT) != enable) + while (!((ehcic->operation->usbsts & HC_OP_PERIODIC_SCHED_STAT) != !enable) && timeout--) udelay(1); if (timeout < 0) { @@ -195,7 +196,7 @@ enum { EHCI_OUT = 0, EHCI_IN = 1, EHCI_SETUP = 2 };
/* returns handled bytes. assumes that the fields it writes are empty on entry */ -static int fill_td(qtd_t *td, void* data, int datalen) +static int fill_td(qtd_t *td, void* data, u32 datalen) { u32 total_len = 0; u32 page_no = 0; @@ -308,7 +309,7 @@ */ enable = enable ? HC_OP_ASYNC_SCHED_STAT : 0; int timeout = 100; /* time out after 100ms */ - while (((ehcic->operation->usbsts & HC_OP_ASYNC_SCHED_STAT) != enable) + while (!((ehcic->operation->usbsts & HC_OP_ASYNC_SCHED_STAT) != !enable) && timeout--) mdelay(1); if (timeout < 0) { @@ -343,6 +344,7 @@
static int ehci_bulk(endpoint_t *ep, int size, u8 *src, int finalize) { + (void)finalize; int result = 0; u8 *end = src + size; int remaining = size; diff --git a/payloads/libpayload/drivers/usb/ohci.c b/payloads/libpayload/drivers/usb/ohci.c index 79add33..e6e1532 100644 --- a/payloads/libpayload/drivers/usb/ohci.c +++ b/payloads/libpayload/drivers/usb/ohci.c @@ -134,6 +134,7 @@ static void ohci_reinit(hci_t *controller) { + (void)controller; }
#if 0 && defined(USB_DEBUG) @@ -297,6 +298,7 @@ static int wait_for_ed(usbdev_t *dev, ed_t *head, int pages) { + (void)pages; /* wait for results */ int timeout = USB_MAX_PROCESSING_TIME_US / OHCI_SLEEP_TIME_US; while (((head->head_pointer & ~3) != head->tail_pointer) && diff --git a/payloads/libpayload/drivers/usb/ohci_private.h b/payloads/libpayload/drivers/usb/ohci_private.h index fd5ef65..e67889d 100644 --- a/payloads/libpayload/drivers/usb/ohci_private.h +++ b/payloads/libpayload/drivers/usb/ohci_private.h @@ -249,7 +249,7 @@ #define TD_CC_SHIFT 28 #define TD_CC_MASK MASK(TD_CC_SHIFT, 4) #define TD_CC_NOERR 0 -#define TD_CC_NOACCESS (14 << TD_CC_SHIFT) /* the lower of the two values, so "no access" can be tested with >= */ +#define TD_CC_NOACCESS ((u32)14 << TD_CC_SHIFT) /* the lower of the two values, so "no access" can be tested with >= */
#define OHCI_INST(controller) ((ohci_t*)((controller)->instance))
diff --git a/payloads/libpayload/drivers/usb/quirks.c b/payloads/libpayload/drivers/usb/quirks.c index b0d1921..a4dbe9b 100644 --- a/payloads/libpayload/drivers/usb/quirks.c +++ b/payloads/libpayload/drivers/usb/quirks.c @@ -66,7 +66,7 @@
u32 pci_quirk_check(pcidev_t controller) { - int i; + size_t i; u16 vendor = pci_read_config16(controller, REG_VENDOR_ID); u16 device = pci_read_config16(controller, REG_DEVICE_ID);
@@ -84,7 +84,7 @@
u32 usb_quirk_check(u16 vendor, u16 device) { - int i; + size_t i; for (i = 0; i < ARRAY_SIZE(usb_quirks); i++) { if ((usb_quirks[i].vendor == vendor) && (usb_quirks[i].device == device)) { @@ -99,7 +99,7 @@
int usb_interface_check(u16 vendor, u16 device) { - int i; + size_t i; for (i = 0; i < ARRAY_SIZE(usb_quirks); i++) { if ((usb_quirks[i].vendor == vendor) && (usb_quirks[i].device == device)) { diff --git a/payloads/libpayload/drivers/usb/usb.c b/payloads/libpayload/drivers/usb/usb.c index e260cf6..8c3e4a5 100644 --- a/payloads/libpayload/drivers/usb/usb.c +++ b/payloads/libpayload/drivers/usb/usb.c @@ -178,7 +178,7 @@ ret = dev->controller->control(dev, IN, sizeof(dr), &dr, len, data);
- if (ret == len) + if (ret >= 0 && (size_t)ret == len) break; udelay(10); } @@ -229,7 +229,7 @@ { int i = controller->latest_address + 1; for (; i != controller->latest_address; i++) { - if (i >= ARRAY_SIZE(controller->devices) || i < 1) { + if (i >= (int)ARRAY_SIZE(controller->devices) || i < 1) { usb_debug("WARNING: Device addresses for controller %#" PRIxPTR " wrapped around!\n", controller->reg_base); i = 0; @@ -507,7 +507,7 @@ dev->num_endp = 1; for (; ptr + 2 <= end && ptr[0] && ptr + ptr[0] <= end; ptr += ptr[0]) { if (ptr[1] == DT_INTF || ptr[1] == DT_CFG || - dev->num_endp >= ARRAY_SIZE(dev->endpoints)) + dev->num_endp >= (int)ARRAY_SIZE(dev->endpoints)) break; if (ptr[1] != DT_ENDP) continue; @@ -668,7 +668,7 @@ usb_attach_device(hci_t *controller, int hubaddress, int port, usb_speed speed) { static const char *speeds[] = { "full", "low", "high", "super", "ultra" }; - usb_debug("%sspeed device\n", (speed < sizeof(speeds) / sizeof(char*)) + usb_debug("%sspeed device\n", (speed >= 0 && speed < (int)ARRAY_SIZE(speeds)) ? speeds[speed] : "invalid value - no"); int newdev = set_address(controller, speed, port, hubaddress); if (newdev == -1) diff --git a/payloads/libpayload/drivers/usb/usb_dev.c b/payloads/libpayload/drivers/usb/usb_dev.c index fe6ca8e..0d26a20 100644 --- a/payloads/libpayload/drivers/usb/usb_dev.c +++ b/payloads/libpayload/drivers/usb/usb_dev.c @@ -40,6 +40,7 @@ static void usb_nop_poll(usbdev_t *dev) { + (void)dev; return; }
diff --git a/payloads/libpayload/drivers/usb/usbhid.c b/payloads/libpayload/drivers/usb/usbhid.c index 12177ef..60aeb65 100644 --- a/payloads/libpayload/drivers/usb/usbhid.c +++ b/payloads/libpayload/drivers/usb/usbhid.c @@ -272,7 +272,7 @@ if (current->modifiers & 0x04) /* Left-Alt */ modifiers |= KB_MOD_ALT; if (current->modifiers & 0x08) /* Left-GUI */ - ; + {} if (current->modifiers & 0x10) /* Right-Ctrl */ modifiers |= KB_MOD_CTRL; if (current->modifiers & 0x20) /* Right-Shift */ @@ -280,7 +280,7 @@ if (current->modifiers & 0x40) /* Right-AltGr */ modifiers |= KB_MOD_ALT; if (current->modifiers & 0x80) /* Right-GUI */ - ; + {}
if ((current->modifiers & 0x05) && ((current->keys[0] == 0x4c) || (current->keys[0] == 0x63))) { @@ -404,7 +404,7 @@ static int usb_hid_set_layout(const char *country) { /* FIXME should be per keyboard */ - int i; + size_t i;
for (i = 0; i < ARRAY_SIZE(keyboard_layouts); i++) { if (strncmp(keyboard_layouts[i].country, country, diff --git a/payloads/libpayload/drivers/usb/usbhub.c b/payloads/libpayload/drivers/usb/usbhub.c index b14f979..2b8070e 100644 --- a/payloads/libpayload/drivers/usb/usbhub.c +++ b/payloads/libpayload/drivers/usb/usbhub.c @@ -246,7 +246,8 @@ static void usb_hub_poll(usbdev_t *const dev) { - unsigned int port, i; + unsigned int i; + int port; u8 buf[32] = { 0 }; const u8 *ibuf;
@@ -323,7 +324,7 @@ return; }
- int port; + unsigned int port; for (port = 1; port <= num_ports; ++port) usb_hub_port_initialize(dev, port);
diff --git a/payloads/libpayload/drivers/usb/usbmsc.c b/payloads/libpayload/drivers/usb/usbmsc.c index 3f249d8..d3add38 100644 --- a/payloads/libpayload/drivers/usb/usbmsc.c +++ b/payloads/libpayload/drivers/usb/usbmsc.c @@ -201,7 +201,7 @@
static void wrap_cbw(cbw_t *cbw, int datalen, cbw_direction dir, const u8 *cmd, - int cmdlen, u8 lun) + size_t cmdlen, u8 lun) { memset(cbw, 0, sizeof(cbw_t));
@@ -247,7 +247,7 @@
static int execute_command(usbdev_t *dev, cbw_direction dir, const u8 *cb, int cblen, - u8 *buf, int buflen, int residue_ok) + u8 *buf, size_t buflen, int residue_ok) { cbw_t cbw; csw_t csw; diff --git a/payloads/libpayload/drivers/usb/xhci.c b/payloads/libpayload/drivers/usb/xhci.c index e9a7ead..a9632d7 100644 --- a/payloads/libpayload/drivers/usb/xhci.c +++ b/payloads/libpayload/drivers/usb/xhci.c @@ -153,7 +153,7 @@ hci_t * xhci_init(unsigned long physical_bar) { - int i; + size_t i;
if (!physical_bar) goto _exit_xhci; @@ -432,7 +432,7 @@ static void xhci_shutdown(hci_t *const controller) { - int i; + size_t i;
if (controller == 0) return; @@ -511,8 +511,9 @@ /* Clear TT buffer for bulk and control endpoints behind a TT */ const int hub = dev->hub; if (hub && dev->speed < HIGH_SPEED && - dev->controller->devices[hub]->speed == HIGH_SPEED) - /* TODO */; + dev->controller->devices[hub]->speed == HIGH_SPEED) { + /* TODO */ + }
/* Reset transfer ring if the endpoint is in the right state */ const unsigned ep_state = EC_GET(STATE, epctx); @@ -641,6 +642,7 @@ const int drlen, void *const devreq, const int dalen, unsigned char *const src) { + (void)drlen; unsigned char *data = src; xhci_t *const xhci = XHCI_INST(dev->controller); epctx_t *const epctx = xhci->dev[dev->address].ctx.ep0; @@ -737,9 +739,9 @@ xhci_bulk(endpoint_t *const ep, const int size, u8 *const src, const int finalize) { + (void)finalize; /* finalize: Hopefully the xHCI controller always does this. We have no control over the packets. */ - u8 *data = src; xhci_t *const xhci = XHCI_INST(ep->dev->controller); const int slot_id = ep->dev->address; @@ -816,6 +818,7 @@ const int reqsize, const int reqcount, const int reqtiming) { + (void)reqtiming; /* reqtiming: We ignore it and use the interval from the endpoint descriptor configured earlier. */
@@ -850,7 +853,7 @@ int pcs = tr->pcs; trb_t *cur = tr->cur; for (i = 0; i < reqcount; ++i) { - if (TRB_GET(C, cur) == pcs) { + if ((int)TRB_GET(C, cur) == pcs) { xhci_debug("Not enough empty TRBs\n"); goto _free_return; } @@ -917,7 +920,7 @@ xhci_handle_events(xhci);
/* Free all pending transfers and the interrupt queue structure */ - int i; + size_t i; for (i = 0; i < intrq->count; ++i) { free(phys_to_virt(intrq->next->ptr_low)); intrq->next = xhci_next_trb(intrq->next, NULL); diff --git a/payloads/libpayload/drivers/usb/xhci_devconf.c b/payloads/libpayload/drivers/usb/xhci_devconf.c index 2f481f5..4e215f8 100644 --- a/payloads/libpayload/drivers/usb/xhci_devconf.c +++ b/payloads/libpayload/drivers/usb/xhci_devconf.c @@ -314,7 +314,7 @@ xhci_finish_ep_config(const endpoint_t *const ep, inputctx_t *const ic) { xhci_t *const xhci = XHCI_INST(ep->dev->controller); - const int ep_id = xhci_ep_id(ep); + const unsigned int ep_id = xhci_ep_id(ep); xhci_debug("ep_id: %d\n", ep_id); if (ep_id <= 1 || 32 <= ep_id) return DRIVER_ERROR; diff --git a/payloads/libpayload/drivers/usb/xhci_events.c b/payloads/libpayload/drivers/usb/xhci_events.c index 139ea59..1b40389 100644 --- a/payloads/libpayload/drivers/usb/xhci_events.c +++ b/payloads/libpayload/drivers/usb/xhci_events.c @@ -218,7 +218,7 @@ unsigned long *const timeout_us) { while (xhci_wait_for_event(&xhci->er, timeout_us)) { - if (TRB_GET(TT, xhci->er.cur) == trb_type) + if ((int)TRB_GET(TT, xhci->er.cur) == trb_type) break;
xhci_handle_event(xhci); @@ -328,8 +328,8 @@ unsigned long timeout_us = USB_MAX_PROCESSING_TIME_US; int ret = TIMEOUT; while (xhci_wait_for_event_type(xhci, TRB_EV_TRANSFER, &timeout_us)) { - if (TRB_GET(ID, xhci->er.cur) == slot_id && - TRB_GET(EP, xhci->er.cur) == ep_id) { + if ((int)TRB_GET(ID, xhci->er.cur) == slot_id && + (int)TRB_GET(EP, xhci->er.cur) == ep_id) { ret = -TRB_GET(CC, xhci->er.cur); if (ret == -CC_SUCCESS || ret == -CC_SHORT_PACKET) ret = TRB_GET(EVTL, xhci->er.cur); diff --git a/payloads/libpayload/drivers/usb/xhci_private.h b/payloads/libpayload/drivers/usb/xhci_private.h index 45c3013..bf69225 100644 --- a/payloads/libpayload/drivers/usb/xhci_private.h +++ b/payloads/libpayload/drivers/usb/xhci_private.h @@ -511,7 +511,7 @@ int xhci_cmd_stop_endpoint(xhci_t *, int slot_id, int ep); int xhci_cmd_set_tr_dq(xhci_t *, int slot_id, int ep, trb_t *, int dcs);
-static inline int xhci_ep_id(const endpoint_t *const ep) { +static inline unsigned int xhci_ep_id(const endpoint_t *const ep) { return ((ep->endpoint & 0x7f) * 2) + (ep->direction != OUT); }
diff --git a/payloads/libpayload/drivers/video/corebootfb.c b/payloads/libpayload/drivers/video/corebootfb.c index 51922d9..a986714 100644 --- a/payloads/libpayload/drivers/video/corebootfb.c +++ b/payloads/libpayload/drivers/video/corebootfb.c @@ -70,7 +70,7 @@ { unsigned char *dst = FB; unsigned char *src = FB + (fbinfo.bytes_per_line * font_height); - int y; + u32 y;
/* Scroll all lines up */ for (y = 0; y < fbinfo.y_resolution - font_height; y++) { @@ -93,7 +93,7 @@ src = (unsigned char *)(chars + coreboot_video_console.columns); memcpy(dst, src, coreboot_video_console.columns * (coreboot_video_console.rows - 1) * 2); - int column; + unsigned int column; for (column = 0; column < coreboot_video_console.columns; column++) chars[(coreboot_video_console.rows - 1) * coreboot_video_console.columns + column] = (VGA_COLOR_DEFAULT << 8);
@@ -102,7 +102,7 @@
static void corebootfb_clear(void) { - int row, column; + unsigned int row, column; unsigned char *ptr = FB;
/* Clear the screen */ diff --git a/payloads/libpayload/drivers/video/graphics.c b/payloads/libpayload/drivers/video/graphics.c index 632a283..01b01ce 100644 --- a/payloads/libpayload/drivers/video/graphics.c +++ b/payloads/libpayload/drivers/video/graphics.c @@ -619,7 +619,8 @@ if (cbgfx_init()) return CBGFX_ERROR_INIT;
- int x, y, i; + u32 x, y; + int i; uint32_t color = calculate_color(rgb, 0); const int bpp = fbinfo->bits_per_pixel; const int bpl = fbinfo->bytes_per_line; @@ -1060,8 +1061,10 @@ palette_offset);
size_t pixel_size = header->size; - if (pixel_size != dim_org->height * - ROUNDUP(dim_org->width * header->bits_per_pixel / 8, 4)) { + size_t height = dim_org->height; + size_t stride = dim_org->width * header->bits_per_pixel / 8; + if (pixel_size != height * + ROUNDUP(stride, 4)) { LOG("Bitmap pixel array size does not match expected size\n"); return CBGFX_ERROR_BITMAP_DATA; } diff --git a/payloads/libpayload/drivers/video/vga.c b/payloads/libpayload/drivers/video/vga.c index c01936d..bb51728 100644 --- a/payloads/libpayload/drivers/video/vga.c +++ b/payloads/libpayload/drivers/video/vga.c @@ -87,7 +87,7 @@
static void vga_clear_line(u8 row, u8 ch, u8 attr) { - int col; + unsigned int col; u16 *ptr = VIDEO(row, 0);
for(col = 0; col < vga_video_console.columns; col++) @@ -98,7 +98,7 @@ { u16 *src = VIDEO(1,0); u16 *dst = VIDEO(0,0); - int i; + unsigned int i;
for(i = 0; i < (vga_video_console.rows - 1) * vga_video_console.columns; i++) *dst++ = *src++; diff --git a/payloads/libpayload/drivers/video/video.c b/payloads/libpayload/drivers/video/video.c index 87d7d74..7a7f3f4 100644 --- a/payloads/libpayload/drivers/video/video.c +++ b/payloads/libpayload/drivers/video/video.c @@ -57,8 +57,8 @@
static struct video_console *console;
-static int cursorx; -static int cursory; +static unsigned int cursorx; +static unsigned int cursory;
void video_get_rows_cols(unsigned int *rows, unsigned int *cols) { @@ -75,12 +75,6 @@ if (!console) return;
- if (cursorx < 0) - cursorx = 0; - - if (cursory < 0) - cursory = 0; - if (cursorx >= console->columns) { cursorx = 0; cursory++; @@ -152,11 +146,13 @@ break;
case '\b': - cursorx--; - if (cursorx < 0) { - cursory--; + if (cursorx == 0) { + if (cursory > 0) + cursory--; cursorx = console->columns; } + else + cursorx--; break;
case '\t': @@ -174,7 +170,7 @@ void video_printf(int foreground, int background, enum video_printf_align align, const char *fmt, ...) { - int i = 0, len; + size_t i = 0, len; char str[200];
va_list ap; @@ -242,7 +238,7 @@
int video_init(void) { - int i; + size_t i; unsigned int dummy_cursor_enabled;
for (i = 0; i < ARRAY_SIZE(console_list); i++) { @@ -252,8 +248,8 @@ console = console_list[i];
if (console->get_cursor) - console->get_cursor((unsigned int*)&cursorx, - (unsigned int*)&cursory, + console->get_cursor(&cursorx, + &cursory, &dummy_cursor_enabled);
if (cursorx) { diff --git a/payloads/libpayload/include/libpayload.h b/payloads/libpayload/include/libpayload.h index 09bd4be..2cef1d5 100644 --- a/payloads/libpayload/include/libpayload.h +++ b/payloads/libpayload/include/libpayload.h @@ -158,7 +158,7 @@ */ void keyboard_init(void); void keyboard_disconnect(void); -bool keyboard_havechar(void); +int keyboard_havechar(void); unsigned char keyboard_get_scancode(void); int keyboard_getchar(void); int keyboard_set_layout(char *country); @@ -321,8 +321,8 @@
struct cb_cmos_enums *first_cmos_enum(struct cb_cmos_option_table *option_table); struct cb_cmos_enums *next_cmos_enum(struct cb_cmos_enums *cmos_enum); -struct cb_cmos_enums *first_cmos_enum_of_id(struct cb_cmos_option_table *option_table, int id); -struct cb_cmos_enums *next_cmos_enum_of_id(struct cb_cmos_enums *cmos_enum, int id); +struct cb_cmos_enums *first_cmos_enum_of_id(struct cb_cmos_option_table *option_table, u32 id); +struct cb_cmos_enums *next_cmos_enum_of_id(struct cb_cmos_enums *cmos_enum, u32 id);
int get_option_with(const struct nvram_accessor *nvram, struct cb_cmos_option_table *option_table, void *dest, const char *name); int get_option_from(struct cb_cmos_option_table *option_table, void *dest, const char *name); @@ -456,11 +456,11 @@ * @{ */ void buffer_from_fifo32(void *buffer, size_t size, void *fifo, - int fifo_stride, int fifo_width); -void buffer_to_fifo32_prefix(const void *buffer, u32 prefix, int prefsz, size_t size, - void *fifo, int fifo_stride, int fifo_width); + size_t fifo_stride, size_t fifo_width); +void buffer_to_fifo32_prefix(const void *buffer, u32 prefix, size_t prefsz, size_t size, + void *fifo, size_t fifo_stride, size_t fifo_width); static inline void buffer_to_fifo32(const void *buffer, size_t size, void *fifo, - int fifo_stride, int fifo_width) + size_t fifo_stride, size_t fifo_width) { buffer_to_fifo32_prefix(buffer, 0, 0, size, fifo, fifo_stride, fifo_width); diff --git a/payloads/libpayload/include/sysinfo.h b/payloads/libpayload/include/sysinfo.h index cbfc7bf..783ef2f 100644 --- a/payloads/libpayload/include/sysinfo.h +++ b/payloads/libpayload/include/sysinfo.h @@ -178,6 +178,6 @@ * structure with information from the table. Return 0 on success and -1 on * failure. */ -int cb_parse_header(void *addr, int len, struct sysinfo_t *info); +int cb_parse_header(void *addr, size_t len, struct sysinfo_t *info);
#endif diff --git a/payloads/libpayload/include/usb/usb.h b/payloads/libpayload/include/usb/usb.h index 43c7b42..67f64a1 100644 --- a/payloads/libpayload/include/usb/usb.h +++ b/payloads/libpayload/include/usb/usb.h @@ -336,6 +336,7 @@
static inline void __attribute__((format(printf, 1, 2))) usb_debug(const char *fmt, ...) { + (void)fmt; #ifdef USB_DEBUG va_list ap; va_start(ap, fmt); diff --git a/payloads/libpayload/libc/coreboot.c b/payloads/libpayload/libc/coreboot.c index 7873426..bfc00ce 100644 --- a/payloads/libpayload/libc/coreboot.c +++ b/payloads/libpayload/libc/coreboot.c @@ -286,12 +286,12 @@ info->acpi_rsdp = cb_acpi_rsdp->rsdp_pointer; }
-int cb_parse_header(void *addr, int len, struct sysinfo_t *info) +int cb_parse_header(void *addr, size_t len, struct sysinfo_t *info) { struct cb_header *header; unsigned char *ptr = addr; void *forward; - int i; + size_t i;
for (i = 0; i < len; i += 16, ptr += 16) { header = (struct cb_header *)ptr; diff --git a/payloads/libpayload/libc/hexdump.c b/payloads/libpayload/libc/hexdump.c index aad67e4..aa22181 100644 --- a/payloads/libpayload/libc/hexdump.c +++ b/payloads/libpayload/libc/hexdump.c @@ -30,14 +30,14 @@
void hexdump(const void *memory, size_t length) { - int i; + size_t i; uint8_t *m; int all_zero = 0;
m = (uint8_t *) memory;
for (i = 0; i < length; i += 16) { - int j; + size_t j;
all_zero++; for (j = 0; j < 16; j++) { diff --git a/payloads/libpayload/libc/lib.c b/payloads/libpayload/libc/lib.c index f1d8574..8f2b066 100644 --- a/payloads/libpayload/libc/lib.c +++ b/payloads/libpayload/libc/lib.c @@ -128,6 +128,7 @@
char *getenv(const char *name) { + (void)name; return NULL; }
@@ -138,12 +139,12 @@ * the amount of bytes read per register (can be 1 through 4). */ void buffer_from_fifo32(void *buffer, size_t size, void *fifo, - int fifo_stride, int fifo_width) + size_t fifo_stride, size_t fifo_width) { u8 *p = buffer; - int i, j; + size_t i, j;
- assert(fifo_width > 0 && fifo_width <= sizeof(u32) && + assert(fifo_width >= 1 && fifo_width <= sizeof(u32) && fifo_stride % sizeof(u32) == 0);
for (i = 0; i < size; i += fifo_width, fifo += fifo_stride) { @@ -160,11 +161,11 @@ * bytes of the 'prefix' u32 parameter and any high-order bytes exceeding prefsz * must be 0. Note that 'size' counts total bytes written, including 'prefsz'. */ -void buffer_to_fifo32_prefix(const void *buffer, u32 prefix, int prefsz, size_t size, - void *fifo, int fifo_stride, int fifo_width) +void buffer_to_fifo32_prefix(const void *buffer, u32 prefix, size_t prefsz, size_t size, + void *fifo, size_t fifo_stride, size_t fifo_width) { const u8 *p = buffer; - int i, j = prefsz; + size_t i, j = prefsz;
assert(fifo_width > 0 && fifo_width <= sizeof(u32) && fifo_stride % sizeof(u32) == 0 && prefsz <= fifo_width); diff --git a/payloads/libpayload/libc/malloc.c b/payloads/libpayload/libc/malloc.c index f8a9ddf..5554c58 100644 --- a/payloads/libpayload/libc/malloc.c +++ b/payloads/libpayload/libc/malloc.c @@ -65,6 +65,7 @@ static struct memory_type *dma = &default_type;
typedef u64 hdrtype_t; +_Static_assert(sizeof(size_t) <= sizeof(hdrtype_t), "unexpected sizes"); #define HDRSIZE (sizeof(hdrtype_t))
#define SIZE_BITS ((HDRSIZE << 3) - 7) @@ -135,8 +136,12 @@ } }
+static inline int is_valid_len(hdrtype_t len) { + return len && len < MAX_SIZE; +} + /* Find free block of size >= len */ -static hdrtype_t volatile *find_free_block(int len, struct memory_type *type) +static hdrtype_t volatile *find_free_block(size_t len, struct memory_type *type) { hdrtype_t header; hdrtype_t volatile *ptr = (hdrtype_t volatile *)type->start; @@ -144,7 +149,7 @@ /* Align the size. */ len = ALIGN_UP(len, HDRSIZE);
- if (!len || len > MAX_SIZE) + if (!is_valid_len(len)) return (void *)NULL;
/* Make sure the region is setup correctly. */ @@ -160,7 +165,7 @@ /* Find some free space. */ do { header = *ptr; - int size = SIZE(header); + size_t size = SIZE(header);
if (!HAS_MAGIC(header) || size == 0) { printf("memory allocator panic. (%s%s)\n", @@ -207,7 +212,7 @@ } }
-static void *alloc(int len, struct memory_type *type) +static void *alloc(size_t len, struct memory_type *type) { hdrtype_t volatile *ptr = find_free_block(len, type);
@@ -359,10 +364,10 @@ { /* If alignment is 0 then the region represents a large region which * has no metadata for tracking subelements. */ - int alignment; + size_t alignment; /* start in memory, and size in bytes */ void* start; - int size; + size_t size; /* layout within a region: - num_elements bytes, 0: free, 1: used, 2: used, combines with next - padding to alignment @@ -373,7 +378,7 @@ */ void* start_data; /* number of free blocks sized "alignment" */ - int free; + size_t free; struct align_region_t *next; };
@@ -541,7 +546,7 @@ return (void *)NULL; }
- int i, count = 0, target = (size+align-1)/align; + size_t i, count = 0, target = (size+align-1)/align; for (i = 0; i < (reg->size/align); i++) { if (((u8*)reg->start)[i] == 0) diff --git a/payloads/libpayload/libc/printf.c b/payloads/libpayload/libc/printf.c index 3edf166..6f47423 100644 --- a/payloads/libpayload/libc/printf.c +++ b/payloads/libpayload/libc/printf.c @@ -813,6 +813,7 @@
static int vprintf_write(const char *str, size_t count, void *unused) { + (void)unused; console_write(str, count); return count; } diff --git a/payloads/libpayload/libc/qsort.c b/payloads/libpayload/libc/qsort.c index aad2aa3..fb78826 100644 --- a/payloads/libpayload/libc/qsort.c +++ b/payloads/libpayload/libc/qsort.c @@ -31,8 +31,8 @@ #include <sys/types.h> #include <stdlib.h>
-static __inline char *med3(char *, char *, char *, int (*)(const void *, const void *)); -static __inline void swapfunc(char *, char *, size_t, int); +static __inline size_t med3(char *, size_t, size_t, size_t, int (*)(const void *, const void *)); +static __inline void swapfunc(char *, char *, size_t, int);
#define min(a, b) (a) < (b) ? a : b
@@ -72,18 +72,22 @@
#define vecswap(a, b, n) if ((n) > 0) swapfunc(a, b, n, swaptype)
-static __inline char * -med3(char *a, char *b, char *c, int (*cmp)(const void *, const void *)) +static __inline size_t +med3(char *base, size_t a, size_t b, size_t c, int (*cmp)(const void *, const void *)) { - return cmp(a, b) < 0 ? - (cmp(b, c) < 0 ? b : (cmp(a, c) < 0 ? c : a )) - :(cmp(b, c) > 0 ? b : (cmp(a, c) < 0 ? a : c )); + const void *pa = base + a; + const void *pb = base + b; + const void *pc = base + c; + return cmp(pa, pb) < 0 ? + (cmp(pb, pc) < 0 ? b : (cmp(pa, pc) < 0 ? c : a )) + :(cmp(pb, pc) > 0 ? b : (cmp(pa, pc) < 0 ? a : c )); }
void qsort(void *aa, size_t n, size_t es, int (*cmp)(const void *, const void *)) { - char *pa, *pb, *pc, *pd, *pl, *pm, *pn; + size_t oa, ob, oc, od, ol, om, on; + //char *pa, *pb, *pc, *pd, *pl, *pm, *pn; int cmp_result, swaptype, swap_cnt; size_t d, r; char *a = aa; @@ -91,70 +95,70 @@ loop: SWAPINIT(a, es); swap_cnt = 0; if (n < 7) { - for (pm = (char *)a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); + for (om = es; om < n * es; om += es) + for (ol = om; ol > 0 && cmp(a + ol - es, a + ol) > 0; + ol -= es) + swap(a + ol, a + ol - es); return; } - pm = (char *)a + (n / 2) * es; + om = (n / 2) * es; if (n > 7) { - pl = (char *)a; - pn = (char *)a + (n - 1) * es; + ol = 0; + on = (n - 1) * es; if (n > 40) { d = (n / 8) * es; - pl = med3(pl, pl + d, pl + 2 * d, cmp); - pm = med3(pm - d, pm, pm + d, cmp); - pn = med3(pn - 2 * d, pn - d, pn, cmp); + ol = med3(a, ol, ol + d, ol + 2 * d, cmp); + om = med3(a, om - d, om, om + d, cmp); + on = med3(a, on - 2 * d, on - d, on, cmp); } - pm = med3(pl, pm, pn, cmp); + om = med3(a, ol, om, on, cmp); } - swap(a, pm); - pa = pb = (char *)a + es; + swap(a, a + om); + oa = ob = es;
- pc = pd = (char *)a + (n - 1) * es; + oc = od = (n - 1) * es; for (;;) { - while (pb <= pc && (cmp_result = cmp(pb, a)) <= 0) { + while (ob <= oc && (cmp_result = cmp(a + ob, a)) <= 0) { if (cmp_result == 0) { swap_cnt = 1; - swap(pa, pb); - pa += es; + swap(a + oa, a + ob); + oa += es; } - pb += es; + ob += es; } - while (pb <= pc && (cmp_result = cmp(pc, a)) >= 0) { + while (ob <= oc && (cmp_result = cmp(a + oc, a)) >= 0) { if (cmp_result == 0) { swap_cnt = 1; - swap(pc, pd); - pd -= es; + swap(a + oc, a + od); + od -= es; } - pc -= es; + oc -= es; } - if (pb > pc) + if (ob > oc) break; - swap(pb, pc); + swap(a + ob, a + oc); swap_cnt = 1; - pb += es; - pc -= es; + ob += es; + oc -= es; } if (swap_cnt == 0) { /* Switch to insertion sort */ - for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) - for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; - pl -= es) - swap(pl, pl - es); + for (om = es; om < n * es; om += es) + for (ol = om; ol > 0 && cmp(a + ol - es, a + ol) > 0; + ol -= es) + swap(a + ol, a + ol - es); return; }
- pn = (char *)a + n * es; - r = min(pa - (char *)a, pb - pa); - vecswap(a, pb - r, r); - r = min(pd - pc, pn - pd - es); - vecswap(pb, pn - r, r); - if ((r = pb - pa) > es) + on = n * es; + r = min(oa, ob - oa); + vecswap(a, a + ob - r, r); + r = min(od - oc, on - od - es); + vecswap(a + ob, a + on - r, r); + if ((r = ob - oa) > es) qsort(a, r / es, es, cmp); - if ((r = pd - pc) > es) { + if ((r = od - oc) > es) { /* Iterate rather than recurse to save stack space */ - a = pn - r; + a = a + on - r; n = r / es; goto loop; } diff --git a/payloads/libpayload/libc/string.c b/payloads/libpayload/libc/string.c index b3e1c8df..d5eb87a 100644 --- a/payloads/libpayload/libc/string.c +++ b/payloads/libpayload/libc/string.c @@ -420,7 +420,7 @@
/* Return the "value" of the character in the given base */
-static int _offset(char ch, int base) +static int _offset(char ch) { if (ch >= '0' && ch <= '9') return ch - '0'; @@ -524,7 +524,7 @@ }
for ( ; *ptr && _valid(*ptr, base); ptr++) - ret = (ret * base) + _offset(*ptr, base); + ret = (ret * base) + _offset(*ptr);
if (endptr != NULL) *endptr = (char *) ptr; diff --git a/payloads/libpayload/libc/time.c b/payloads/libpayload/libc/time.c index 64de800..d22d156 100644 --- a/payloads/libpayload/libc/time.c +++ b/payloads/libpayload/libc/time.c @@ -155,6 +155,7 @@ */ int gettimeofday(struct timeval *tv, void *tz) { + (void)tz; tv->tv_sec = time(NULL); tv->tv_usec = clock.usecs;
diff --git a/payloads/libpayload/libcbfs/cbfs.c b/payloads/libpayload/libcbfs/cbfs.c index 0cee914..7084c29 100644 --- a/payloads/libpayload/libcbfs/cbfs.c +++ b/payloads/libpayload/libcbfs/cbfs.c @@ -107,6 +107,7 @@ { void *load = buffer; size_t out_size = 0; + ssize_t read_result;
DEBUG("Decompressing %zu bytes from '%s' to %p with algo %d\n", in_size, mdata->h.filename, buffer, compression); @@ -119,7 +120,8 @@ } }
- if (boot_device_read(load, offset, in_size) != in_size) { + read_result = boot_device_read(load, offset, in_size); + if (read_result < 0 || (size_t)read_result != in_size) { ERROR("'%s' failed to read contents of file\n", mdata->h.filename); goto out; } diff --git a/payloads/libpayload/liblz4/lz4_wrapper.c b/payloads/libpayload/liblz4/lz4_wrapper.c index 3d17fe6..5c3b1c9 100644 --- a/payloads/libpayload/liblz4/lz4_wrapper.c +++ b/payloads/libpayload/liblz4/lz4_wrapper.c @@ -156,7 +156,7 @@ }
if (b.not_compressed) { - size_t size = MIN((uint32_t)b.size, dst + dstn - out); + size_t size = MIN((uint32_t)b.size, (size_t)(dst + dstn - out)); memcpy(out, in, size); if (size < b.size) break; /* output overrun */ diff --git a/payloads/libpayload/libpci/libpci.c b/payloads/libpayload/libpci/libpci.c index 200ae18..504bee6 100644 --- a/payloads/libpayload/libpci/libpci.c +++ b/payloads/libpayload/libpci/libpci.c @@ -86,6 +86,7 @@
void pci_filter_init(struct pci_access* pacc, struct pci_filter* pf) { + (void)pacc; pf->domain = -1; pf->bus = -1; pf->dev = -1; @@ -212,6 +213,7 @@ struct pci_dev *pci_get_dev(struct pci_access* pacc, u16 domain, u8 bus, u8 dev, u8 func) { struct pci_dev *cur = malloc(sizeof(*cur)); + (void)pacc; cur->domain = domain; cur->bus = bus; cur->dev = dev; diff --git a/src/commonlib/bsd/cbfs_mcache.c b/src/commonlib/bsd/cbfs_mcache.c index 8714cc0..e10744a 100644 --- a/src/commonlib/bsd/cbfs_mcache.c +++ b/src/commonlib/bsd/cbfs_mcache.c @@ -47,8 +47,9 @@ struct cbfs_mcache_build_args *args = arg; union mcache_entry *entry = args->mcache; const uint32_t data_offset = be32toh(mdata->h.offset); + size_t remain = args->end - args->mcache;
- if (args->end - args->mcache < data_offset) + if (remain < data_offset) return CB_CBFS_CACHE_FULL;
if (cbfs_copy_fill_metadata(args->mcache, mdata, already_read, dev, offset)) diff --git a/src/commonlib/bsd/cbfs_private.c b/src/commonlib/bsd/cbfs_private.c index 7ad2986..8ddf625 100644 --- a/src/commonlib/bsd/cbfs_private.c +++ b/src/commonlib/bsd/cbfs_private.c @@ -72,7 +72,7 @@ }
/* Read the rest of the metadata (filename, and possibly attributes). */ - assert(todo > 0 && todo <= sizeof(mdata) - sizeof(mdata.h)); + assert(todo > 0 && (size_t)todo <= sizeof(mdata) - sizeof(mdata.h)); if (cbfs_dev_read(dev, mdata.raw + sizeof(mdata.h), offset + sizeof(mdata.h), todo) != todo) return CB_CBFS_IO; @@ -120,8 +120,8 @@ /* Then read in whatever metadata may be left (will only happen in non-hashing case). */ const size_t todo = be32toh(src->h.offset) - already_read; assert(todo <= sizeof(*dst) - already_read); - if (todo && cbfs_dev_read(dev, dst->raw + already_read, offset + already_read, - todo) != todo) + ssize_t read_result = cbfs_dev_read(dev, dst->raw + already_read, offset + already_read, todo); + if (todo && (read_result < 0 || (size_t)read_result != todo)) return CB_CBFS_IO; return CB_SUCCESS; }