From 82fa95f8cd0ef0f386c14e529a55b6af95ec7753 Mon Sep 17 00:00:00 2001 From: Jonas 'Sortie' Termansen Date: Wed, 21 Aug 2024 17:17:11 +0200 Subject: [PATCH] Fix warnings on gcc 14.2.0. --- Makefile | 4 +- build-aux/verify-headers-in-configuration.sh | 4 +- checksum/checksum.c | 4 +- disked/disked.c | 2 +- editor/input.c | 5 +++ games/aquatinspitz.c | 16 ++++---- games/asteroids.cpp | 3 +- kernel/disk/ahci/ahci.cpp | 7 +--- kernel/disk/ata/ata.cpp | 6 +-- kernel/gpu/bga/bga.cpp | 15 +++---- kernel/include/sortix/kernel/cpu.h | 4 +- kernel/include/sortix/kernel/textbuffer.h | 2 +- kernel/lfbtextbuffer.cpp | 1 - kernel/net/arp.cpp | 8 ++-- kernel/net/em/em.cpp | 2 +- kernel/pci.cpp | 7 +++- kernel/process.cpp | 10 ++--- kernel/vga.cpp | 2 +- kernel/x64/memorymanagement.h | 14 +++---- kernel/x86-family/vbox.cpp | 5 +-- kernel/x86/memorymanagement.h | 10 ++--- libc/pthread/pthread_create.c | 43 ++++++++++---------- libc/stdio/vcbscanf.c | 3 ++ libc/string/memcpy.c | 2 +- libm/Makefile | 2 +- regress/regress.c | 10 ++--- rw/Makefile | 2 +- sh/editline.c | 2 +- terminal/terminal.c | 8 ++-- trianglix/vector.h | 5 ++- utils/column.c | 2 +- utils/find.c | 12 +++--- utils/tee.c | 5 ++- 33 files changed, 115 insertions(+), 112 deletions(-) diff --git a/Makefile b/Makefile index 2272ec3a..2954bb94 100644 --- a/Makefile +++ b/Makefile @@ -714,7 +714,7 @@ verify-manual: verify-build-tools: $(MAKE) clean-build-tools - $(MAKE) OPTLEVEL='-O2 -g -Werror -Werror=strict-prototypes' build-tools + CFLAGS='-O2 -g -Werror -Werror=strict-prototypes' CXXFLAGS='-O2 -g -Werror' $(MAKE) build-tools verify-sysroot-source: $(MAKE) clean-sysroot @@ -726,7 +726,7 @@ verify-sysroot-source: verify-build: $(MAKE) mostlyclean - $(MAKE) OPTLEVEL='-O2 -g -Werror -Werror=strict-prototypes' PACKAGES='' + CFLAGS='-O2 -g -Werror -Werror=strict-prototypes' CXXFLAGS='-O2 -g -Werror' $(MAKE) PACKAGES='' verify-headers: # TODO: The gcc port doesn't ship with cross-compilers out of the box. diff --git a/build-aux/verify-headers-in-configuration.sh b/build-aux/verify-headers-in-configuration.sh index c9b255fe..b3ed5e3a 100755 --- a/build-aux/verify-headers-in-configuration.sh +++ b/build-aux/verify-headers-in-configuration.sh @@ -106,10 +106,10 @@ feature="$3" printf '%s:\n' "$header" case $std in *++*) - printf '\t@%s\n' "$target-g++ $std $feature -c $header -o /dev/null -O3 -Wall -Wextra -Wsystem-headers -Werror -I libc/include -I libm/include -I $libm_machine -I kernel/include" + printf '\t@%s\n' "$target-g++ $std $feature -c $header -o /dev/zero -O3 -Wall -Wextra -Wsystem-headers -Werror -I libc/include -I libm/include -I $libm_machine -I kernel/include" ;; *) - printf '\t@%s\n' "$target-gcc $std $feature -c $header -o /dev/null -O3 -Wall -Wextra -Wsystem-headers -Werror -I libc/include -I libm/include -I $libm_machine -I kernel/include" + printf '\t@%s\n' "$target-gcc $std $feature -c $header -o /dev/zero -O3 -Wall -Wextra -Wsystem-headers -Werror -I libc/include -I libm/include -I $libm_machine -I kernel/include" ;; esac done) | make -f - --no-print-directory diff --git a/checksum/checksum.c b/checksum/checksum.c index 701f8d99..6bbdf854 100644 --- a/checksum/checksum.c +++ b/checksum/checksum.c @@ -205,8 +205,8 @@ static int checklist_fp(FILE* fp, struct checklist** checklist_sorted = NULL; if ( files ) { - checklist = calloc(sizeof(struct checklist), files_count); - checklist_sorted = calloc(sizeof(struct checklist*), files_count); + checklist = calloc(files_count, sizeof(struct checklist)); + checklist_sorted = calloc(files_count, sizeof(struct checklist*)); if ( !checklist || !checklist_sorted ) err(1, "malloc"); for ( size_t i = 0; i < files_count; i++ ) diff --git a/disked/disked.c b/disked/disked.c index f7cdea8c..4380cc84 100644 --- a/disked/disked.c +++ b/disked/disked.c @@ -453,7 +453,7 @@ static void remove_partition_devices(const char* path) char* dir_path = strdup(path); if ( !dir_path ) { - warn("%s", dir_path); + warn("malloc"); return; // TODO: Error. } dirname(dir_path); diff --git a/editor/input.c b/editor/input.c index ca41bb7b..4eff6a8a 100644 --- a/editor/input.c +++ b/editor/input.c @@ -267,6 +267,11 @@ void editor_input_process_byte(struct editor_input* editor_input, if ( amount_read != sizeof(uc) ) return; + // TODO: Work around https://gcc.gnu.org/bugzilla/show_bug.cgi?id=110091 + // false positive warning on gcc 14.2.0 -O2. + #if defined(__GNUC__) && 12 <= __GNUC__ + #pragma GCC diagnostic ignored "-Wdangling-pointer" + #endif if ( editor_input->termseq_used < MAX_TERMSEQ_SIZE ) editor_input->termseq[editor_input->termseq_used++] = (char) uc; diff --git a/games/aquatinspitz.c b/games/aquatinspitz.c index 67ed82a4..a68bb321 100644 --- a/games/aquatinspitz.c +++ b/games/aquatinspitz.c @@ -38,7 +38,7 @@ #include // Utility global variables every game will need. -uint32_t window_id = 0; +uint32_t my_window_id = 0; static size_t framesize; static uint32_t* fb; static bool game_running = true; @@ -273,9 +273,9 @@ void render(struct display_connection* connection) } } - display_render_window(connection, window_id, 0, 0, + display_render_window(connection, my_window_id, 0, 0, game_width, game_height, fb); - display_show_window(connection, window_id); + display_show_window(connection, my_window_id); } // ... to here. No need to edit stuff below. @@ -331,7 +331,7 @@ void on_quit(void* ctx, uint32_t window_id) void on_resize(void* ctx, uint32_t window_id, uint32_t width, uint32_t height) { (void) ctx; - if ( window_id != window_id ) + if ( window_id != my_window_id ) return; game_width = width; game_height = height; @@ -341,7 +341,7 @@ void on_resize(void* ctx, uint32_t window_id, uint32_t width, uint32_t height) void on_keyboard(void* ctx, uint32_t window_id, uint32_t codepoint) { (void) ctx; - if ( window_id != window_id ) + if ( window_id != my_window_id ) return; int kbkey = KBKEY_DECODE(codepoint); if ( !kbkey ) @@ -399,9 +399,9 @@ int main(int argc, char* argv[]) if ( !connection ) error(1, errno, "Could not connect to display server"); - display_create_window(connection, window_id); - display_resize_window(connection, window_id, game_width, game_height); - display_title_window(connection, window_id, "Aquatinspitz"); + display_create_window(connection, my_window_id); + display_resize_window(connection, my_window_id, game_width, game_height); + display_title_window(connection, my_window_id, "Aquatinspitz"); mainloop(connection); diff --git a/games/asteroids.cpp b/games/asteroids.cpp index d84eec10..1b1f4647 100644 --- a/games/asteroids.cpp +++ b/games/asteroids.cpp @@ -162,7 +162,8 @@ public: float y; public: - Vector(float x = 0.0f, float y = 0.0f) : x(x), y(y) { } + constexpr Vector(float x = 0.0f, float y = 0.0f) : x(x), y(y) { } + constexpr Vector(const Vector& v) : x(v.x), y(v.y) { } Vector& operator=(const Vector& rhs) { diff --git a/kernel/disk/ahci/ahci.cpp b/kernel/disk/ahci/ahci.cpp index 218fa162..26bbf48f 100644 --- a/kernel/disk/ahci/ahci.cpp +++ b/kernel/disk/ahci/ahci.cpp @@ -105,12 +105,7 @@ static void InitializeDevice(Ref dev, const char* devpath, void Init(const char* devpath, Ref dev) { uint32_t devaddr; - pcifind_t filter; - - memset(&filter, 255, sizeof(filter)); - filter.classid = 0x01; - filter.subclassid = 0x06; - + pcifind_t filter(NULL, 0xFFFF, 0xFFFF, 0x01, 0x06); devaddr = 0; while ( (devaddr = PCI::SearchForDevices(filter, devaddr)) ) InitializeDevice(dev, devpath, devaddr); diff --git a/kernel/disk/ata/ata.cpp b/kernel/disk/ata/ata.cpp index 0868bd46..5a57287f 100644 --- a/kernel/disk/ata/ata.cpp +++ b/kernel/disk/ata/ata.cpp @@ -50,11 +50,7 @@ static void InitializeDevice(Ref dev, const char* devpath, void Init(const char* devpath, Ref dev) { uint32_t devaddr; - pcifind_t filter; - - memset(&filter, 255, sizeof(filter)); - filter.classid = 0x01; - filter.subclassid = 0x01; + pcifind_t filter(NULL, 0xFFFF, 0xFFFF, 0x01, 0x01); devaddr = 0; while ( (devaddr = PCI::SearchForDevices(filter, devaddr)) ) InitializeDevice(dev, devpath, devaddr); diff --git a/kernel/gpu/bga/bga.cpp b/kernel/gpu/bga/bga.cpp index 4af51af4..ad25a1fa 100644 --- a/kernel/gpu/bga/bga.cpp +++ b/kernel/gpu/bga/bga.cpp @@ -619,15 +619,12 @@ static bool OnDevice(uint32_t devaddr, const pciid_t*, const pcitype_t*, void*, void Init() { - pcifind_t patterns[2]; - memset(&patterns[0], 255, sizeof(patterns[0])); - patterns[0].vendorid = 0x1234; - patterns[0].deviceid = 0x1111; - memset(&patterns[1], 255, sizeof(patterns[1])); - patterns[1].vendorid = 0x80EE; - patterns[1].deviceid = 0xBEEF; - - PCI::Search(OnDevice, NULL, patterns, 2); + pcifind_t patterns[2] = + { + { NULL, 0x1234, 0x1111 }, + { NULL, 0x80EE, 0xBEEF }, + }; + PCI::Search(OnDevice, NULL, patterns, sizeof(patterns)/sizeof(patterns[0])); } } // namespace BGA diff --git a/kernel/include/sortix/kernel/cpu.h b/kernel/include/sortix/kernel/cpu.h index f6b9c4cc..08d5a271 100644 --- a/kernel/include/sortix/kernel/cpu.h +++ b/kernel/include/sortix/kernel/cpu.h @@ -30,8 +30,8 @@ namespace Sortix { // Functions for 32-bit and 64-bit x86. #if defined(__i386__) || defined(__x86_64__) namespace CPU { -void Reboot(); -void ShutDown(); +__attribute__((noreturn)) void Reboot(); +__attribute__((noreturn)) void ShutDown(); } // namespace CPU #endif diff --git a/kernel/include/sortix/kernel/textbuffer.h b/kernel/include/sortix/kernel/textbuffer.h index dc36de94..04cc2b35 100644 --- a/kernel/include/sortix/kernel/textbuffer.h +++ b/kernel/include/sortix/kernel/textbuffer.h @@ -53,7 +53,7 @@ struct TextCharPOD struct TextChar { - TextChar() { } + TextChar() : c(0), vgacolor(0), attr(0), fg(0), bg(0) { } TextChar(const TextCharPOD& o) : c(o.c), vgacolor(o.vgacolor), attr(o.attr), fg(o.fg), bg(o.bg) { } TextChar(wchar_t c, uint8_t vgacolor, uint16_t attr, uint32_t fg, uint32_t bg) : diff --git a/kernel/lfbtextbuffer.cpp b/kernel/lfbtextbuffer.cpp index 4c3b9ebf..8a23ed16 100644 --- a/kernel/lfbtextbuffer.cpp +++ b/kernel/lfbtextbuffer.cpp @@ -106,7 +106,6 @@ LFBTextBuffer* CreateLFBTextBuffer(uint8_t* lfb, uint32_t lfbformat, ret->columns = columns; ret->rows = rows; ret->font = font; - memset(chars, 0, sizeof(chars[0]) * columns * rows); ret->chars = chars; ret->cursorenabled = true; ret->cursorpos = TextPos(0, 0); diff --git a/kernel/net/arp.cpp b/kernel/net/arp.cpp index 0556286e..396dc99d 100644 --- a/kernel/net/arp.cpp +++ b/kernel/net/arp.cpp @@ -218,10 +218,10 @@ static struct arp_table* GetTable(NetworkInterface* netif) { if ( netif->arp_table ) return netif->arp_table; - struct arp_table* table = new struct arp_table; + struct arp_table* table = + (struct arp_table*) calloc(1, sizeof(struct arp_table)); if ( !table ) return NULL; - memset(table, 0, sizeof(*table)); netif->arp_table = table; table->netif = netif; // Enter every entry into the table's unused linked list. @@ -301,7 +301,9 @@ static void EvictEntry(struct arp_table* table, struct arp_entry* entry) } // Clear the entry. - memset(entry, 0, sizeof(*entry)); + assert(!entry->pending_first); + assert(!entry->pending_last); + memset((char*) entry, 0, sizeof(*entry)); entry->table = table; // Insert the entry into the table's unused linked list. diff --git a/kernel/net/em/em.cpp b/kernel/net/em/em.cpp index 55aca4d9..cda4aeb6 100644 --- a/kernel/net/em/em.cpp +++ b/kernel/net/em/em.cpp @@ -495,7 +495,7 @@ bool EM::AddReceiveDescriptor(Ref pkt) // ordered via interrupt worker if ( next_desc == rx_prochead ) return false; struct rx_desc* desc = &rdesc[rx_tail]; - memset(desc, 0, sizeof(*desc)); + *desc = rx_desc{0, 0, 0, 0, 0, 0}; desc->status = 0; desc->address = pkt->pmap.phys; rpackets[rx_tail] = pkt; diff --git a/kernel/pci.cpp b/kernel/pci.cpp index 25687b4e..3c611743 100644 --- a/kernel/pci.cpp +++ b/kernel/pci.cpp @@ -142,7 +142,12 @@ static void MakeCoarsePattern(pcifind_t* coarse, { if ( pattern_count < 1 ) { - memset(coarse, 255, sizeof(*coarse)); + coarse->vendorid = 0xffff; + coarse->deviceid = 0xffff; + coarse->classid = 0xff; + coarse->subclassid = 0xff; + coarse->progif = 0xff; + coarse->revid = 0xff; return; } const pcifind_t* first = patterns; diff --git a/kernel/process.cpp b/kernel/process.cpp index 99e641c9..2e4e12b6 100644 --- a/kernel/process.cpp +++ b/kernel/process.cpp @@ -1391,10 +1391,9 @@ int sys_execve(const char* user_filename, } } - argv = new char*[argc+1]; + argv = (char**) calloc(argc+1, sizeof(char*)); if ( !argv ) goto cleanup_filename; - memset(argv, 0, sizeof(char*) * (argc+1)); for ( int i = 0; i < argc; i++ ) { @@ -1420,10 +1419,9 @@ int sys_execve(const char* user_filename, } } - envp = new char*[envc+1]; + envp = (char**) calloc(envc+1, sizeof(char*)); if ( !envp ) goto cleanup_argv; - memset(envp, 0, sizeof(char*) * (envc+1)); for ( int i = 0; i < envc; i++ ) { @@ -1439,11 +1437,11 @@ int sys_execve(const char* user_filename, cleanup_envp: for ( int i = 0; i < envc; i++) delete[] envp[i]; - delete[] envp; + free(envp); cleanup_argv: for ( int i = 0; i < argc; i++) delete[] argv[i]; - delete[] argv; + free(argv); cleanup_filename: delete[] filename; cleanup_done: diff --git a/kernel/vga.cpp b/kernel/vga.cpp index 8984aa2b..1137586b 100644 --- a/kernel/vga.cpp +++ b/kernel/vga.cpp @@ -39,7 +39,7 @@ namespace Sortix { namespace VGA { -uint8_t* const VGA = (uint8_t* const) 0xB8000; +uint8_t* const VGA = (uint8_t*) 0xB8000; const unsigned WIDTH = 80; const unsigned HEIGHT = 25; const size_t VGA_SIZE = sizeof(uint16_t) * WIDTH * HEIGHT; diff --git a/kernel/x64/memorymanagement.h b/kernel/x64/memorymanagement.h index a9df00c4..31a624af 100644 --- a/kernel/x64/memorymanagement.h +++ b/kernel/x64/memorymanagement.h @@ -29,14 +29,14 @@ const size_t TRANSBITS = 9; PML* const PMLS[TOPPMLLEVEL + 1] = { - (PML* const) 0x0, - (PML* const) 0xFFFFFF8000000000UL, - (PML* const) 0xFFFFFF7FC0000000UL, - (PML* const) 0XFFFFFF7FBFE00000UL, - (PML* const) 0xFFFFFF7FBFDFF000UL, + (PML*) 0x0, + (PML*) 0xFFFFFF8000000000UL, + (PML*) 0xFFFFFF7FC0000000UL, + (PML*) 0XFFFFFF7FBFE00000UL, + (PML*) 0xFFFFFF7FBFDFF000UL, }; -PML* const FORKPML = (PML* const) 0xFFFFFF0000000000UL; +PML* const FORKPML = (PML*) 0xFFFFFF0000000000UL; } // namespace Memory } // namespace Sortix @@ -44,7 +44,7 @@ PML* const FORKPML = (PML* const) 0xFFFFFF0000000000UL; namespace Sortix { namespace Page { -addr_t* const STACK = (addr_t* const) 0xFFFFFE8000000000UL; +addr_t* const STACK = (addr_t*) 0xFFFFFE8000000000UL; const size_t MAXSTACKSIZE = (512UL*1024UL*1024UL*1024UL); const size_t MAXSTACKLENGTH = MAXSTACKSIZE / sizeof(addr_t); diff --git a/kernel/x86-family/vbox.cpp b/kernel/x86-family/vbox.cpp index 15794ed2..5406e5cc 100644 --- a/kernel/x86-family/vbox.cpp +++ b/kernel/x86-family/vbox.cpp @@ -542,10 +542,7 @@ GuestAdditions* GetGuestAdditions() void Init() { - pcifind_t pcifind; - memset(&pcifind, 255, sizeof(pcifind)); - pcifind.vendorid = 0x80EE; - pcifind.deviceid = 0xCAFE; + pcifind_t pcifind(NULL, 0x80EE, 0xCAFE); uint32_t devaddr = PCI::SearchForDevices(pcifind, 0); if ( !devaddr ) diff --git a/kernel/x86/memorymanagement.h b/kernel/x86/memorymanagement.h index 091bdc0c..c201c4f5 100644 --- a/kernel/x86/memorymanagement.h +++ b/kernel/x86/memorymanagement.h @@ -29,12 +29,12 @@ const size_t TRANSBITS = 10; PML* const PMLS[TOPPMLLEVEL + 1] = { - (PML* const) 0x0, - (PML* const) 0xFFC00000UL, - (PML* const) 0xFFBFF000UL, + (PML*) 0x0, + (PML*) 0xFFC00000UL, + (PML*) 0xFFBFF000UL, }; -PML* const FORKPML = (PML* const) 0xFF800000UL; +PML* const FORKPML = (PML*) 0xFF800000UL; } // namespace Memory } // namespace Sortix @@ -42,7 +42,7 @@ PML* const FORKPML = (PML* const) 0xFF800000UL; namespace Sortix { namespace Page { -addr_t* const STACK = (addr_t* const) 0xFF400000UL; +addr_t* const STACK = (addr_t*) 0xFF400000UL; const size_t MAXSTACKSIZE = (4UL*1024UL*1024UL); const size_t MAXSTACKLENGTH = MAXSTACKSIZE / sizeof(addr_t); diff --git a/libc/pthread/pthread_create.c b/libc/pthread/pthread_create.c index 9a54f90a..84d6c0d6 100644 --- a/libc/pthread/pthread_create.c +++ b/libc/pthread/pthread_create.c @@ -43,27 +43,28 @@ static void pthread_entrance(struct pthread* thread) } #if defined(__i386__) || defined(__x86_64__) -static const unsigned long FLAGS_CARRY = 1 << 0; // 0x000001 -static const unsigned long FLAGS_RESERVED1 = 1 << 1; // 0x000002, read as one -static const unsigned long FLAGS_PARITY = 1 << 2; // 0x000004 -static const unsigned long FLAGS_RESERVED2 = 1 << 3; // 0x000008 -static const unsigned long FLAGS_AUX = 1 << 4; // 0x000010 -static const unsigned long FLAGS_RESERVED3 = 1 << 5; // 0x000020 -static const unsigned long FLAGS_ZERO = 1 << 6; // 0x000040 -static const unsigned long FLAGS_SIGN = 1 << 7; // 0x000080 -static const unsigned long FLAGS_TRAP = 1 << 8; // 0x000100 -static const unsigned long FLAGS_INTERRUPT = 1 << 9; // 0x000200 -static const unsigned long FLAGS_DIRECTION = 1 << 10; // 0x000400 -static const unsigned long FLAGS_OVERFLOW = 1 << 11; // 0x000800 -static const unsigned long FLAGS_IOPRIVLEVEL = 1 << 12 | 1 << 13; -static const unsigned long FLAGS_NESTEDTASK = 1 << 14; // 0x004000 -static const unsigned long FLAGS_RESERVED4 = 1 << 15; // 0x008000 -static const unsigned long FLAGS_RESUME = 1 << 16; // 0x010000 -static const unsigned long FLAGS_VIRTUAL8086 = 1 << 17; // 0x020000 -static const unsigned long FLAGS_ALIGNCHECK = 1 << 18; // 0x040000 -static const unsigned long FLAGS_VIRTINTR = 1 << 19; // 0x080000 -static const unsigned long FLAGS_VIRTINTRPEND = 1 << 20; // 0x100000 -static const unsigned long FLAGS_ID = 1 << 21; // 0x200000 +#define unused __attribute__((unused)) +unused static const unsigned long FLAGS_CARRY = 1 << 0; // 0x000001 +unused static const unsigned long FLAGS_RESERVED1 = 1 << 1; // 0x000002, read as one +unused static const unsigned long FLAGS_PARITY = 1 << 2; // 0x000004 +unused static const unsigned long FLAGS_RESERVED2 = 1 << 3; // 0x000008 +unused static const unsigned long FLAGS_AUX = 1 << 4; // 0x000010 +unused static const unsigned long FLAGS_RESERVED3 = 1 << 5; // 0x000020 +unused static const unsigned long FLAGS_ZERO = 1 << 6; // 0x000040 +unused static const unsigned long FLAGS_SIGN = 1 << 7; // 0x000080 +unused static const unsigned long FLAGS_TRAP = 1 << 8; // 0x000100 +unused static const unsigned long FLAGS_INTERRUPT = 1 << 9; // 0x000200 +unused static const unsigned long FLAGS_DIRECTION = 1 << 10; // 0x000400 +unused static const unsigned long FLAGS_OVERFLOW = 1 << 11; // 0x000800 +unused static const unsigned long FLAGS_IOPRIVLEVEL = 1 << 12 | 1 << 13; +unused static const unsigned long FLAGS_NESTEDTASK = 1 << 14; // 0x004000 +unused static const unsigned long FLAGS_RESERVED4 = 1 << 15; // 0x008000 +unused static const unsigned long FLAGS_RESUME = 1 << 16; // 0x010000 +unused static const unsigned long FLAGS_VIRTUAL8086 = 1 << 17; // 0x020000 +unused static const unsigned long FLAGS_ALIGNCHECK = 1 << 18; // 0x040000 +unused static const unsigned long FLAGS_VIRTINTR = 1 << 19; // 0x080000 +unused static const unsigned long FLAGS_VIRTINTRPEND = 1 << 20; // 0x100000 +unused static const unsigned long FLAGS_ID = 1 << 21; // 0x200000 #endif #if defined(__i386__) diff --git a/libc/stdio/vcbscanf.c b/libc/stdio/vcbscanf.c index 354366ad..4a0b3157 100644 --- a/libc/stdio/vcbscanf.c +++ b/libc/stdio/vcbscanf.c @@ -180,6 +180,7 @@ int vcbscanf(void* fp, if ( scan_type != TYPE_INT ) return errno = EINVAL, matched_items ? matched_items : EOF; scan_type = TYPE_PTR; + // fallthrough case 'X': case 'x': base = 16; is_unsigned = true; break; default: __builtin_unreachable(); @@ -321,12 +322,14 @@ int vcbscanf(void* fp, if ( scan_type != TYPE_INT ) return errno = EINVAL, matched_items ? matched_items : EOF; scan_type = TYPE_LONG; + // fallthrough case 's': string = true; use_scanset = false; break; case '[': string = true; use_scanset = true; break; case 'C': if ( scan_type != TYPE_INT ) return errno = EINVAL, matched_items ? matched_items : EOF; scan_type = TYPE_LONG; + // fallthrough case 'c': string = false; use_scanset = false; break; default: __builtin_unreachable(); } diff --git a/libc/string/memcpy.c b/libc/string/memcpy.c index 6ee6fda3..bb5e8360 100644 --- a/libc/string/memcpy.c +++ b/libc/string/memcpy.c @@ -46,7 +46,7 @@ void* memcpy(void* restrict dst_ptr, return dst_ptr; void* dst_end = (char*) dst_ptr + size; - const void* src_end = (const const char*) src_ptr + size; + const void* src_end = (const char*) src_ptr + size; if ( (dst_ptr < src_ptr && src_ptr < dst_end) || (src_ptr < dst_ptr && dst_ptr < src_end) ) { diff --git a/libm/Makefile b/libm/Makefile index f9436220..27f2b2f9 100644 --- a/libm/Makefile +++ b/libm/Makefile @@ -348,7 +348,7 @@ ctanf.c \ ctanh.c \ ctanhf.c \ -CFLAGS:=$(CFLAGS) -std=gnu99 -Wall -Wextra +CFLAGS:=$(CFLAGS) -std=gnu99 -Wall -Wextra -Wno-misleading-indentation -Wno-shift-negative-value -Wno-maybe-uninitialized CPPFLAGS:=$(CPPFLAGS) -I include -I src -I $(ARCH_SUBDIR) # TODO: Figure out whether these are the defines that we want to pass. diff --git a/regress/regress.c b/regress/regress.c index 5f63e6aa..ded823be 100644 --- a/regress/regress.c +++ b/regress/regress.c @@ -30,11 +30,11 @@ #include #include -static const int VERBOSITY_SILENT = 0; -static const int VERBOSITY_NO_OUTPUT = 1; -static const int VERBOSITY_QUIET = 2; -static const int VERBOSITY_NORMAL = 3; -static const int VERBOSITY_VERBOSE = 4; +__attribute__((unused)) static const int VERBOSITY_SILENT = 0; +__attribute__((unused)) static const int VERBOSITY_NO_OUTPUT = 1; +__attribute__((unused)) static const int VERBOSITY_QUIET = 2; +__attribute__((unused)) static const int VERBOSITY_NORMAL = 3; +__attribute__((unused)) static const int VERBOSITY_VERBOSE = 4; bool is_usable_terminal(int fd) { diff --git a/rw/Makefile b/rw/Makefile index 2e19fe8c..66d44f18 100644 --- a/rw/Makefile +++ b/rw/Makefile @@ -6,7 +6,7 @@ include ../build-aux/dirs.mak OPTLEVEL?=$(DEFAULT_OPTLEVEL) CFLAGS?=$(OPTLEVEL) -CFLAGS += -Wall -Wextra +CFLAGS += -Wall -Wextra -Wno-format-truncation BINARIES = rw MANPAGES1 = rw.1 diff --git a/sh/editline.c b/sh/editline.c index 28d951b7..bfe60be7 100644 --- a/sh/editline.c +++ b/sh/editline.c @@ -582,7 +582,7 @@ bool edit_line_history_save(struct edit_line* edit_state, const char* path) } // Merge with any updated history. bool success = true; - char** history = calloc(sizeof(char*), histsize); + char** history = calloc(histsize, sizeof(char*)); if ( !history ) warn("malloc"), success = false; size_t first = 0; diff --git a/terminal/terminal.c b/terminal/terminal.c index c0b01c56..50d11ffc 100644 --- a/terminal/terminal.c +++ b/terminal/terminal.c @@ -153,7 +153,7 @@ static void scrollback_resize(size_t new_rows, size_t new_columns) // TODO: Recover gracefully if the scrollback fails. // TODO: Overflow. struct entry* new_scrollback = - calloc(sizeof(struct entry), new_rows * new_columns); + calloc(new_rows * new_columns, sizeof(struct entry)); if ( !new_scrollback ) err(1, "malloc"); size_t src_y_after_cursor = rows ? row + 1 : 0; @@ -1057,8 +1057,8 @@ void on_keyboard(void* ctx, uint32_t window_id, uint32_t codepoint) void draw(struct display_connection* connection) { - uint32_t* framebuffer = (uint32_t*) - calloc(sizeof(uint32_t), WINDOW_WIDTH * WINDOW_HEIGHT); + uint32_t* framebuffer = + calloc(WINDOW_WIDTH * WINDOW_HEIGHT, sizeof(uint32_t)); assert(framebuffer); struct framebuffer fb; @@ -1155,7 +1155,7 @@ int main(int argc, char* argv[]) columns = 80; // TODO: Overflow. - scrollback = calloc(sizeof(struct entry), rows * columns); + scrollback = calloc(rows * columns, sizeof(struct entry)); if ( !scrollback ) err(1, "malloc"); diff --git a/trianglix/vector.h b/trianglix/vector.h index 08dc6644..57fa4490 100644 --- a/trianglix/vector.h +++ b/trianglix/vector.h @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013 Jonas 'Sortie' Termansen. + * Copyright (c) 2013, 2024 Jonas 'Sortie' Termansen. * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -28,7 +28,8 @@ public: float z; public: - Vector(float x = 0.f, float y = 0.f, float z = 0.f) : x(x), y(y), z(z) { } + constexpr Vector(float x = 0.f, float y = 0.f, float z = 0.f) : x(x), y(y), z(z) { } + constexpr Vector(const Vector& v) : x(v.x), y(v.y), z(v.z) { } Vector& operator=(const Vector& rhs) { diff --git a/utils/column.c b/utils/column.c index ca4fd68a..5ebb2226 100644 --- a/utils/column.c +++ b/utils/column.c @@ -298,7 +298,7 @@ int main(int argc, char* argv[]) if ( columns == 1 ) rows = lines_used; - size_t* column_widths = (size_t*) calloc(sizeof(size_t), columns); + size_t* column_widths = (size_t*) calloc(columns, sizeof(size_t)); if ( !column_widths ) error(1, errno, "calloc column widths"); diff --git a/utils/find.c b/utils/find.c index 246b822c..ff9a4e6e 100644 --- a/utils/find.c +++ b/utils/find.c @@ -915,7 +915,7 @@ static bool find(const struct expr* expr, char* new_path = join_paths(state->path, entry->d_name); if ( !new_path ) err(1, "malloc"); - struct state* new_state = calloc(sizeof(struct state), 1); + struct state* new_state = calloc(1, sizeof(struct state)); if ( !new_state ) err(1, "malloc"); new_state->parent = state; @@ -1061,7 +1061,7 @@ int main(int argc, char* argv[]) for ( int i = predicates_offset; i < argc; i++ ) { const char* arg = argv[i]; - struct expr* subexpr = calloc(sizeof(struct expr), 1); + struct expr* subexpr = calloc(1, sizeof(struct expr)); if ( !subexpr ) err(1, "malloc"); struct expr** next_insert_at = NULL; @@ -1070,7 +1070,7 @@ int main(int argc, char* argv[]) subexpr->kind = EXPR_PAREN; subexpr->expr_not.expr = NULL; struct parse_state* new_parse_state = - calloc(sizeof(struct parse_state), 1); + calloc(1, sizeof(struct parse_state)); if ( !new_parse_state ) err(1, "malloc"); new_parse_state->outer = parse_state; @@ -1440,7 +1440,7 @@ int main(int argc, char* argv[]) } else { - struct expr* and_expr = calloc(sizeof(struct expr), 1); + struct expr* and_expr = calloc(1, sizeof(struct expr)); if ( !and_expr ) err(1, "malloc"); and_expr->kind = EXPR_AND; @@ -1465,7 +1465,7 @@ int main(int argc, char* argv[]) if ( !found_action ) { - struct expr* print_expr = calloc(sizeof(struct expr), 1); + struct expr* print_expr = calloc(1, sizeof(struct expr)); if ( !print_expr ) err(1, "malloc"); print_expr->kind = EXPR_PRINT; @@ -1474,7 +1474,7 @@ int main(int argc, char* argv[]) root = print_expr; else { - struct expr* and_expr = calloc(sizeof(struct expr), 1); + struct expr* and_expr = calloc(1, sizeof(struct expr)); if ( !and_expr ) err(1, "malloc"); and_expr->kind = EXPR_AND; diff --git a/utils/tee.c b/utils/tee.c index 67399491..345858be 100644 --- a/utils/tee.c +++ b/utils/tee.c @@ -85,7 +85,10 @@ int main(int argc, char* argv[]) bool ok = true; bool stdout_ok = true; - int* fds = malloc(files_count * sizeof(*fds)); + #if defined(__GNUC__) && 7 <= __GNUC__ + #pragma GCC diagnostic ignored "-Walloc-size-larger-than=" + #endif + int* fds = calloc(files_count, sizeof(*fds)); if ( !fds ) err(1, "malloc");