[warnings] fix a few warnings introduced with newer version of gcc

Most of the warnings are new, such as needing to mark fallthroughs on
cases explicitly. A few are based on signed vs unsigned comparisons.

Disable one warning that was annoying about comparing null to arguments
marked nonnull.
This commit is contained in:
Travis Geiselbrecht
2018-03-15 14:10:12 -07:00
parent 1d63a772a9
commit 5dea3e1933
15 changed files with 23 additions and 18 deletions

View File

@@ -112,6 +112,7 @@ static int lkb_send(lkb_t *lkb, u8 opcode, const void *data, size_t len) {
break;
}
len = 0;
// fallthrough
default:
lkb->state = STATE_ERROR;
opcode = MSG_FAIL;

View File

@@ -251,6 +251,7 @@ void handle(u32 magic, u32 cmd, u32 arg) {
return;
case 'A':
boot_app();
/* fallthrough */
case 'R':
/* reboot "normally" */
reply[1] = 0;

View File

@@ -69,7 +69,7 @@ static const union double_int float_test_vec[] = {
};
#define countof(a) (sizeof(a) / sizeof((a)[0]))
static const unsigned int float_test_vec_size = countof(float_test_vec);
__attribute__((unused)) static const unsigned int float_test_vec_size = countof(float_test_vec);
#define PRINT_FLOAT \
printf("0x%016llx %f %F %a %A\n", \

View File

@@ -576,8 +576,8 @@ int arch_mmu_map(arch_aspace_t *aspace, addr_t vaddr, paddr_t paddr, uint count,
tt_entry |= MMU_MEMORY_L1_PAGETABLE_NON_SECURE;
aspace->tt_virt[l1_index] = tt_entry;
/* fallthrough */
}
/* fallthrough */
case MMU_MEMORY_L1_DESCRIPTOR_PAGE_TABLE: {
uint32_t *l2_table = paddr_to_kvaddr(MMU_MEMORY_L1_PAGE_TABLE_ADDR(tt_entry));
LTRACEF("l2_table at %p\n", l2_table);

View File

@@ -56,7 +56,7 @@ CONFIGHEADER := $(BUILDDIR)/config.h
GLOBAL_INCLUDES := $(BUILDDIR) $(addsuffix /include,$(LKINC))
GLOBAL_OPTFLAGS ?= $(ARCH_OPTFLAGS)
GLOBAL_COMPILEFLAGS := -g -finline -include $(CONFIGHEADER)
GLOBAL_COMPILEFLAGS += -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Werror=return-type
GLOBAL_COMPILEFLAGS += -W -Wall -Wno-multichar -Wno-unused-parameter -Wno-unused-function -Wno-unused-label -Werror=return-type -Wno-nonnull-compare
GLOBAL_COMPILEFLAGS += -fno-common
GLOBAL_CFLAGS := --std=gnu11 -Werror-implicit-function-declaration -Wstrict-prototypes -Wwrite-strings
#GLOBAL_CFLAGS += -Werror

View File

@@ -85,7 +85,7 @@ __ieee754_asin(double x)
if(ix<0x3e400000) { /* if |x| < 2**-27 */
if(huge+x>one) return x;/* return x with inexact if x!=0*/
} else
t = x*x;
t = x*x;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
w = p/q;

View File

@@ -54,7 +54,7 @@ __ieee754_asinf(float x)
if(ix<0x32000000) { /* if |x| < 2**-27 */
if(huge+x>one) return x;/* return x with inexact if x!=0*/
} else
t = x*x;
t = x*x;
p = t*(pS0+t*(pS1+t*(pS2+t*(pS3+t*(pS4+t*pS5)))));
q = one+t*(qS1+t*(qS2+t*(qS3+t*qS4)));
w = p/q;

View File

@@ -185,7 +185,7 @@ usage:
if (argc < 4) goto notenoughargs;
int request = argv[3].u;
int arg = (argc == 5) ? argv[4].u : 0;
unsigned long arg = (argc == 5) ? argv[4].u : 0;
bdev_t *dev = bio_open(argv[2].str);
if (!dev) {
@@ -238,7 +238,7 @@ usage:
} else if (!strcmp(argv[1].str, "crc32")) {
if (argc < 5) goto notenoughargs;
off_t offset = argv[3].u; // XXX use long
unsigned long offset = argv[3].u;
size_t len = argv[4].u;
bdev_t *dev = bio_open(argv[2].str);
@@ -256,12 +256,12 @@ usage:
do {
ulong crc = 0;
off_t pos = offset;
unsigned long pos = offset;
while (pos < offset + len) {
ssize_t err = bio_read(dev, buf, pos, MIN(len - (pos - offset), dev->block_size));
if (err <= 0) {
printf("error reading at offset 0x%llx\n", offset + pos);
printf("error reading at offset 0x%lx\n", offset + pos);
break;
}

View File

@@ -125,7 +125,7 @@ int ext2_read_link(ext2_t *ext2, struct ext2_inode *inode, char *str, size_t len
off_t linklen = ext2_file_len(ext2, inode);
if ((linklen < 0) || (linklen + 1 > len))
if ((linklen < 0) || (linklen + 1 > (off_t)len))
return ERR_NO_MEMORY;
if (linklen > 60) {

View File

@@ -194,7 +194,7 @@ ssize_t ext2_read_inode(ext2_t *ext2, struct ext2_inode *inode, void *_buf, off_
/* trim the read */
if (offset > file_size)
return 0;
if (offset + len >= file_size)
if ((off_t)(offset + len) >= file_size)
len = file_size - offset;
if (len == 0)
return 0;

View File

@@ -239,7 +239,7 @@ static ssize_t memfs_read(filecookie *fcookie, void *buf, off_t off, size_t len)
mutex_acquire(&file->fs->lock);
if (off >= file->len) {
if (off >= (off_t)file->len) {
len = 0;
} else if (off + len > file->len) {
len = file->len - off;

View File

@@ -695,10 +695,10 @@ static int spifs_test(int argc, const cmd_args *argv)
break;
}
}
printf("\nPassed %u of %u tests.\n", passed, attempted);
printf("\nPassed %zu of %zu tests.\n", passed, attempted);
if (attempted != countof(tests)) {
printf("(Skipped %u)\n", countof(tests) - attempted);
printf("(Skipped %zu)\n", countof(tests) - attempted);
}
return countof(tests) - passed;
@@ -841,4 +841,4 @@ STATIC_COMMAND_START
STATIC_COMMAND("spifs", "commands related to the spifs implementation.", &cmd_spifs)
STATIC_COMMAND_END(spifs);
#endif // LK_DEBUGLEVEL > 1
#endif // LK_DEBUGLEVEL > 1

View File

@@ -114,8 +114,10 @@ minip_usage:
switch (argc) {
case 5:
count = argv[4].u;
/* fallthrough */
case 4:
port = argv[3].u;
/* fallthrough */
case 3:
host = str_ip_to_int(argv[2].str, strlen(argv[2].str));
break;

View File

@@ -323,6 +323,7 @@ void platform_init_keyboard(cbuf_t *buffer)
i8042_flush();
ctr = 0;
if (i8042_command(&ctr, I8042_CMD_CTL_RCTR)) {
dprintf(SPEW, "Failed to read CTR while initializing i8042\n");
return;

View File

@@ -504,19 +504,19 @@ static int pci_bios_detect(void)
pci_bios_info *pci = find_pci_bios_info();
if (pci != NULL) {
printf("Found PCI structure at %08x\n", (uint32_t) pci);
printf("Found PCI structure at %p\n", pci);
printf("\nPCI header info:\n");
printf("%c%c%c%c\n", pci->magic[0], pci->magic[1], pci->magic[2],
pci->magic[3]);
printf("%08x\n", (uint32_t) pci->entry);
printf("%p\n", pci->entry);
printf("%d\n", pci->length * 16);
printf("%d\n", pci->checksum);
uint32_t adr, temp, len;
uint8_t err;
bios32_entry.offset = (uint32_t)pci->entry + KERNEL_BASE;
bios32_entry.offset = (uint32_t)(uintptr_t)pci->entry + KERNEL_BASE;
bios32_entry.selector = CODE_SELECTOR;
__asm__(