From eb1b65ef4bccde2e4b775a451139278b612f6a97 Mon Sep 17 00:00:00 2001 From: chaoskagami Date: Thu, 18 Aug 2016 12:32:47 -0400 Subject: [PATCH] Fix as many warnings as I possibly can at the moment and -Werror on most --- common.mk | 9 ++--- include/arm11.h | 2 +- include/common.h | 2 ++ include/menu-backend.h | 31 ++++++++++++++++ include/menu.h | 7 ++++ include/option.h | 31 ---------------- include/std/draw.h | 14 ++++---- include/std/memory.h | 2 +- source/chainloader.c | 5 ++- source/firm/decryptor.c | 2 +- source/firm/firm.c | 12 ++++--- source/menu-backend.c | 2 +- source/menu.c | 2 +- source/patch/emunand.c | 2 +- source/patch/module.c | 4 +-- source/patch/reboot.c | 2 +- source/std/abort.c | 4 +-- source/std/draw.c | 78 ++++++++++++++++++++++------------------- source/std/fs.c | 14 ++++---- source/std/memory.c | 8 ++--- 20 files changed, 123 insertions(+), 110 deletions(-) create mode 100644 include/menu.h diff --git a/common.mk b/common.mk index 216f4a9..326bcab 100644 --- a/common.mk +++ b/common.mk @@ -6,17 +6,18 @@ SIZE_OPTIMIZATION = -Wl,--gc-sections -ffunction-sections REVISION := $(shell git rev-parse HEAD | head -c10)+$(shell git rev-list --count HEAD) -AM_CFLAGS= -std=gnu11 -Os -g -fomit-frame-pointer -ffast-math \ +AM_CFLAGS= -std=gnu11 -Os -g -ffast-math \ -Wpedantic -Wall -Wextra -Wcast-align -Wcast-qual \ -Wdisabled-optimization -Wformat=2 -Winit-self -Wlogical-op \ -Wmissing-include-dirs -Wredundant-decls \ -Wshadow -Wsign-conversion -Wstrict-overflow=5 -Wswitch-default \ - -Wundef -Wno-unused $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \ + -Wundef -Wno-unused -Werror -Wno-error=cast-align -Wno-error=strict-overflow -Wno-error=pedantic \ + $(THUMBFLAGS) $(SIZE_OPTIMIZATION) $(INCPATHS) $(C9FLAGS) \ -fno-builtin -std=gnu11 -DREVISION=\"$(REVISION)\" \ -DFW_NAME=\"corbenik\" $(PATHARGS) -AM_LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -Wl,-z,defs -lgcc \ - -L$(top_srcdir)/external/libctr9/src +AM_LDFLAGS=-Wl,--use-blx,--pic-veneer,-q -nostdlib -nodefaultlibs -Wl,-z,defs -lgcc \ + -lc -L$(top_srcdir)/external/libctr9/src OCFLAGS=--set-section-flags .bss=alloc,load,contents diff --git a/include/arm11.h b/include/arm11.h index 822eeb4..e4c3ba3 100644 --- a/include/arm11.h +++ b/include/arm11.h @@ -32,7 +32,7 @@ #define PDC1_FRAMEBUFFER_SETUP_FBB_ADDR_1 PDC1_FRAMEBUFFER_SETUP_REG(0x94) #define PDC1_FRAMEBUFFER_SETUP_FBB_ADDR_2 PDC1_FRAMEBUFFER_SETUP_REG(0x98) -#define MAKE_FRAMEBUFFER_PIXFMT(col, plx, screen) ((col & 0b111) | ((plx & 1) << 5) | ((screen & 1) << 6) | 0b10000000001100000000) +#define MAKE_FRAMEBUFFER_PIXFMT(col, plx, screen) ((col & 0x7) | ((plx & 1) << 5) | ((screen & 1) << 6) | 0x80300) #define RGBA8 0 #define BGR8 1 diff --git a/include/common.h b/include/common.h index 53c1788..e9d82f2 100644 --- a/include/common.h +++ b/include/common.h @@ -19,6 +19,8 @@ #include #include +#include +#include #include #include #include diff --git a/include/menu-backend.h b/include/menu-backend.h index 16aa720..3f46fb5 100644 --- a/include/menu-backend.h +++ b/include/menu-backend.h @@ -1,6 +1,37 @@ #ifndef __MENU_BACKEND_H__ #define __MENU_BACKEND_H__ +/* Menu entry type. Determines how the menu is displayed and which (if any) options + * can be changed. + */ +enum type +{ + boolean_val = 0, ///< Toggleable boolean + ranged_val = 1, ///< N1 - N2, left and right to pick. + mask_val = 2, ///< Bitmask allowed values. + not_option = 3, ///< Skip over this. + call_fun = 4, ///< Call a function. Treat (a) as (void)(*)(void). + boolean_val_n3ds = 5, ///< Toggle, but only show on n3DS + break_menu = 6 ///< Exit the menu (same as B) +}; + +typedef void (*func_call_t)(uint32_t data); + +struct range_str +{ + int a, b; +}; + +struct options_s +{ + int64_t index; ///< Option index. Used for displaying values. + char name[64]; ///< Name of patch to display in menus. + char desc[256]; ///< Description of option, shown when pressing select + enum type allowed; ///< Misnomer, FIXME. Type of menu entry. See enum type. + uint32_t a, b; ///< Should be union, FIXME. Data values used for menu entry. + uint8_t indent; ///< Indentation/ownership level of menu. +} __attribute__((packed)); + /* Set the accent foreground color for a screen. * * \param screen Which screen it should be set for diff --git a/include/menu.h b/include/menu.h new file mode 100644 index 0000000..7f39387 --- /dev/null +++ b/include/menu.h @@ -0,0 +1,7 @@ +#ifndef __MENU_H +#define __MENU_H + +void reset(); +void poweroff(); + +#endif diff --git a/include/option.h b/include/option.h index 667e780..e1a2f4f 100644 --- a/include/option.h +++ b/include/option.h @@ -36,37 +36,6 @@ extern struct config_file config; extern struct config_file *config; #endif -/* Menu entry type. Determines how the menu is displayed and which (if any) options - * can be changed. - */ -enum type -{ - boolean_val = 0, ///< Toggleable boolean - ranged_val = 1, ///< N1 - N2, left and right to pick. - mask_val = 2, ///< Bitmask allowed values. - not_option = 3, ///< Skip over this. - call_fun = 4, ///< Call a function. Treat (a) as (void)(*)(void). - boolean_val_n3ds = 5, ///< Toggle, but only show on n3DS - break_menu = 6 ///< Exit the menu (same as B) -}; - -typedef void (*func_call_t)(uint32_t data); - -struct range_str -{ - int a, b; -}; - -struct options_s -{ - int64_t index; ///< Option index. Used for displaying values. - char name[64]; ///< Name of patch to display in menus. - char desc[256]; ///< Description of option, shown when pressing select - enum type allowed; ///< Misnomer, FIXME. Type of menu entry. See enum type. - uint32_t a, b; ///< Should be union, FIXME. Data values used for menu entry. - uint8_t indent; ///< Indentation/ownership level of menu. -} __attribute__((packed)); - #define OPTION_LOADER 2 ///< Use builtin loader module replacer. #define OPTION_SVCS 3 ///< Inject svcBackdoor (FIXME, misnomer) diff --git a/include/std/draw.h b/include/std/draw.h index 9759b16..0f24e5e 100644 --- a/include/std/draw.h +++ b/include/std/draw.h @@ -54,7 +54,7 @@ void screenshot(); * \param y2 Y2 coordinate * \param color Color to fill with */ -void rect(void* channel, int x, int y, int x2, int y2, uint8_t color); +void rect(void* channel, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2, uint8_t color); /* Fill a line behind characters with a color. * @@ -62,7 +62,7 @@ void rect(void* channel, int x, int y, int x2, int y2, uint8_t color); * \param y Which line to fill * \param color Color to fill with */ -void fill_line(void* channel, int y, uint8_t color); +void fill_line(void* channel, unsigned int y, uint8_t color); /* Clears background image bitmaps. */ @@ -93,7 +93,7 @@ void clear_screens(); * \param color_fg RGB color to draw character as (as uint32_t) * \param color_bg RGB color to draw behind character (as uint32_t) */ -void draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg); +void draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, unsigned int ch_y, const uint32_t color_fg, const uint32_t color_bg); /* Sets the font. * @@ -112,14 +112,14 @@ void set_font(const char* filename); * \param buf Handle to output to. * \param c Character (as int) to output */ -void putc(void *buf, const int c); +void putc(void *buf, int c); /* Outputs a string to a handle * * \param buf Handle to output to. * \param string String to output */ -void puts(void *buf, const char *string); +void puts(void *buf, char *string); /* Flushes a handle * @@ -159,11 +159,11 @@ void clear_disp(uint8_t *screen); * \param Format string. * \param ... Format arguments */ -void fprintf(void *channel, const char *format, ...) __attribute__ ((format (printf, 2, 3))); +void fprintf(void *channel, char *format, ...) __attribute__ ((format (printf, 2, 3))); /* See fprintf. Takes a va_list instead of variable arguments. */ -void vfprintf(void *channel, const char *format, va_list ap); +void vfprintf(void *channel, char *format, va_list ap); #define BLACK 0 #define BLUE 1 diff --git a/include/std/memory.h b/include/std/memory.h index 369e91a..7546d74 100644 --- a/include/std/memory.h +++ b/include/std/memory.h @@ -4,7 +4,7 @@ #include #include -size_t strlen(const char *string); +size_t strlen(char *string); void memcpy(void *dest, const void *src, size_t size); void memmove(void *dest, const void *src, size_t size); void memset(void *dest, const int filler, size_t size); diff --git a/source/chainloader.c b/source/chainloader.c index 7cb1d77..775b8e5 100644 --- a/source/chainloader.c +++ b/source/chainloader.c @@ -4,11 +4,8 @@ #include uint32_t current_chain_index = 0; - struct options_s *chains = NULL; -int show_menu(struct options_s *options, uint8_t *toggles); - // TODO - The near same function is called in different places. It would // be better to have a recursive listing that calls a function for // each entry (it would cut code density) @@ -76,6 +73,8 @@ void chainload_file(char* chain_file_data) memcpy((void*)0x23FFFE00, framebuffers, sizeof(struct framebuffers)); ((void(*)(void*, uint32_t))0x24F00000)(chain_data, size + 256 + 8); // Size of payload + argv. + + while(1); } void chain_file_hdl(char* fpath) { diff --git a/source/firm/decryptor.c b/source/firm/decryptor.c index 32dbde3..4196555 100644 --- a/source/firm/decryptor.c +++ b/source/firm/decryptor.c @@ -21,7 +21,7 @@ ncch_getctr(const ncch_h *ncch, uint8_t *ctr, uint8_t type) ctr[i] = partitionID[7 - i]; // Convert to big endian & normal input ctr[8] = type; } else if (version == 1) { - int x = 0; + unsigned int x = 0; if (type == NCCHTYPE_EXHEADER) x = MEDIA_UNITS; else if (type == NCCHTYPE_EXEFS) diff --git a/source/firm/firm.c b/source/firm/firm.c index bc2be84..c8a5ac6 100644 --- a/source/firm/firm.c +++ b/source/firm/firm.c @@ -188,12 +188,12 @@ decrypt_cetk_key(void *key, const void *cetk) { static int got_cetk = 0; uint8_t iv[AES_BLOCK_SIZE] = { 0 }; - uint32_t sigtype = __builtin_bswap32(*(uint32_t *)cetk); + uint32_t sigtype = __builtin_bswap32(*(const uint32_t *)cetk); if (sigtype != SIG_TYPE_RSA2048_SHA256) return 1; - ticket_h *ticket = (ticket_h *)(cetk + sizeof(sigtype) + 0x13C); + const ticket_h *ticket = (const ticket_h *)((const uint8_t*)cetk + sizeof(sigtype) + 0x13C); if (ticket->ticketCommonKeyYIndex != 1) return 1; @@ -222,7 +222,7 @@ decrypt_firm_title(firm_h *dest, ncch_h *ncch, uint32_t *size, void *key) uint8_t exefs_key[16] = { 0 }; uint8_t exefs_iv[16] = { 0 }; - fprintf(stderr, " Decrypting FIRM container (size is %u blocks)\n", *size / AES_BLOCK_SIZE); + fprintf(stderr, " Decrypting FIRM container (size is %lu blocks)\n", *size / AES_BLOCK_SIZE); setup_aeskey(0x16, key); use_aeskey(0x16); @@ -240,7 +240,7 @@ decrypt_firm_title(firm_h *dest, ncch_h *ncch, uint32_t *size, void *key) exefs_h *exefs = (exefs_h *)((uint8_t *)ncch + ncch->exeFSOffset * MEDIA_UNITS); uint32_t exefs_size = ncch->exeFSSize * MEDIA_UNITS; - fprintf(stderr, " Decrypting ExeFs for FIRM (size is %u blocks)\n", exefs_size / AES_BLOCK_SIZE); + fprintf(stderr, " Decrypting ExeFs for FIRM (size is %lu blocks)\n", exefs_size / AES_BLOCK_SIZE); setup_aeskeyY(0x2C, exefs_key); use_aeskey(0x2C); @@ -283,7 +283,7 @@ decrypt_arm9bin(arm9bin_h *header, uint64_t firm_title, uint8_t version) int size = atoi(header->size); use_aeskey(slot); - ctr_decrypt(arm9bin, arm9bin, size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, header->ctr); + ctr_decrypt(arm9bin, arm9bin, (size_t)size / AES_BLOCK_SIZE, AES_CNT_CTRNAND_MODE, header->ctr); if (firm_title == NATIVE_FIRM_TITLEID) return *(uint32_t *)arm9bin != ARM9BIN_MAGIC; @@ -460,6 +460,8 @@ boot_firm() *a11_entry = (uint32_t)firm_loc->a11Entry; ((void (*)())firm_loc->a9Entry)(); + + while(1); } int diff --git a/source/menu-backend.c b/source/menu-backend.c index 92b13a5..fc58efa 100644 --- a/source/menu-backend.c +++ b/source/menu-backend.c @@ -99,7 +99,7 @@ show_menu(struct options_s *options, uint8_t *toggles) set_cursor(TOP_SCREEN, 0, (unsigned int)(i - window_top + 2) ); int indent = options[i].indent; - for(int i=0; i < indent; i++) + for(int j=0; j < indent; j++) fprintf(TOP_SCREEN, " "); if (options[i].allowed == boolean_val || (is_n3ds && options[i].allowed == boolean_val_n3ds)) { diff --git a/source/menu.c b/source/menu.c index 1e19a8a..4905a4e 100644 --- a/source/menu.c +++ b/source/menu.c @@ -81,7 +81,7 @@ void patch_func(char* fpath) { strncpy(patches[current_menu_index_patches].desc, fpath, 255); else strncpy(patches[current_menu_index_patches].desc, p.desc, 255); - patches[current_menu_index_patches].index = p.uuid; + patches[current_menu_index_patches].index = (int64_t)p.uuid; patches[current_menu_index_patches].allowed = boolean_val; patches[current_menu_index_patches].a = 0; patches[current_menu_index_patches].b = 0; diff --git a/source/patch/emunand.c b/source/patch/emunand.c index 6426513..a217ac3 100644 --- a/source/patch/emunand.c +++ b/source/patch/emunand.c @@ -63,7 +63,7 @@ getSDMMC(uint8_t *pos, uint32_t size) const uint8_t pattern[] = { 0x21, 0x20, 0x18, 0x20 }; const uint8_t *off = memfind(pos, size, pattern, 4); - uint32_t ret = *(uint32_t *)(off + 9) + *(uint32_t *)(off + 0xD); + uint32_t ret = *(const uint32_t *)(off + 9) + *(const uint32_t *)(off + 0xD); fprintf(stderr, "emunand: SDMMC code @ %lx\n", ret); diff --git a/source/patch/module.c b/source/patch/module.c index aebee27..ebe7857 100644 --- a/source/patch/module.c +++ b/source/patch/module.c @@ -45,7 +45,7 @@ patch_modules() uint32_t need_units = (module->contentSize - sysmodule->contentSize); memmove((uint8_t *)sysmodule + module->contentSize * 0x200, (uint8_t *)sysmodule + sysmodule->contentSize * 0x200, - ((uint8_t *)firm_loc + firm_size) - ((uint8_t *)sysmodule + (module->contentSize * 0x200))); + ((uint32_t)firm_loc + firm_size) - ((uint32_t)sysmodule + (module->contentSize * 0x200))); sysmodule_section->size += 0x200 * need_units; for (int i = section_index + 1; i < 4; i++) { @@ -62,7 +62,7 @@ patch_modules() else if (module->contentSize < sysmodule->contentSize) { // NOTE - This doesn't change the sysmodule section size; it isn't needed to do so. fprintf(stderr, "Module: Shrink %lu units\n", sysmodule->contentSize - module->contentSize); - int remaining_size = + uint32_t remaining_size = sysmodule_section->size - (((uint32_t)sysmodule + sysmodule->contentSize * 0x200) - ((uint32_t)firm_loc + sysmodule_section->offset)); // Sysmodule section size - (End location of this sysmodule - // Sysmodule section) => diff --git a/source/patch/reboot.c b/source/patch/reboot.c index 2c0ab05..96ebd68 100644 --- a/source/patch/reboot.c +++ b/source/patch/reboot.c @@ -35,7 +35,7 @@ patch_reboot() fprintf(stderr, "reboot: firmlaunch @ %lx\n", (uint32_t)off); // Firmlaunch function offset - offset in BLX opcode (A4-16 - ARM DDI 0100E) + 1 - uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - process9Offset + process9MemAddr); + uint32_t fOpenOffset = (uint32_t)(off + 9 - (-((*(uint32_t *)off & 0x00FFFFFF) << 2) & (0xFFFFFF << 2)) - (uint32_t)process9Offset + process9MemAddr); fprintf(stderr, "reboot: fopen @ %lx\n", fOpenOffset); diff --git a/source/std/abort.c b/source/std/abort.c index 4a71952..48db2f1 100644 --- a/source/std/abort.c +++ b/source/std/abort.c @@ -4,9 +4,7 @@ #include #include -void poweroff(); - -void abort(const char* x, ...) { +void abort(char* x, ...) { va_list ap; va_start(ap, x); diff --git a/source/std/draw.c b/source/std/draw.c index 557db37..65c38be 100644 --- a/source/std/draw.c +++ b/source/std/draw.c @@ -66,9 +66,9 @@ static uint32_t colors[16] = { 0xffffff // White }; // VGA color table. -void rect(void* channel, int x, int y, int x2, int y2, uint8_t color) { +void rect(void* channel, unsigned int x, unsigned int y, unsigned int x2, unsigned int y2, uint8_t color) { uint8_t* screen = NULL; - int height = 0; + unsigned int height = 0; if (channel == stdout) { screen = framebuffers->top_left; height = TOP_HEIGHT; @@ -79,11 +79,11 @@ void rect(void* channel, int x, int y, int x2, int y2, uint8_t color) { return; // Invalid on non-screen displays. } - for(int y_a = y; y_a < y2; y_a++) { - for(int x_a = x; x_a < x2; x_a++) { - int xDisplacement = (x_a * SCREEN_DEPTH * height); - int yDisplacement = ((height - y_a - 1) * SCREEN_DEPTH); - int pos = xDisplacement + yDisplacement; + for(unsigned int y_a = y; y_a < y2; y_a++) { + for(unsigned int x_a = x; x_a < x2; x_a++) { + unsigned int xDisplacement = (x_a * SCREEN_DEPTH * height); + unsigned int yDisplacement = ((height - y_a - 1) * SCREEN_DEPTH); + unsigned int pos = xDisplacement + yDisplacement; screen[pos + 1] = colors[color & 0xF]; screen[pos + 2] = colors[color & 0xF] >> 8; @@ -93,8 +93,8 @@ void rect(void* channel, int x, int y, int x2, int y2, uint8_t color) { } } -void fill_line(void* channel, int y, uint8_t color) { - int x2 = 0; +void fill_line(void* channel, unsigned int y, uint8_t color) { + unsigned int x2 = 0; if (channel == stdout) x2 = TOP_WIDTH; else if (channel == stderr) @@ -281,13 +281,13 @@ set_cursor(void *channel, unsigned int x, unsigned int y) } void -draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, const uint32_t color_fg, const uint32_t color_bg) +draw_character(uint8_t *screen, const unsigned int character, unsigned int ch_x, unsigned int ch_y, const uint32_t color_fg, const uint32_t color_bg) { if (!isprint(character)) return; // Don't output non-printables. - _UNUSED int width = 0; - int height = 0; + _UNUSED unsigned int width = 0; + unsigned int height = 0; uint8_t* buffer_bg; if (screen == framebuffers->top_left || screen == framebuffers->top_right) { width = TOP_WIDTH; @@ -301,8 +301,8 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co return; // Invalid buffer. } - int x = (font_w + font_kern) * ch_x; - int y = font_h * ch_y; + unsigned int x = (font_w + font_kern) * ch_x; + unsigned int y = font_h * ch_y; if (x >= width || y >= height) return; // OOB @@ -310,12 +310,12 @@ draw_character(uint8_t *screen, const uint32_t character, int ch_x, int ch_y, co unsigned int c_font_w = (font_w / 8) + (font_w % 8 ? 1 : 0); for (unsigned int yy = 0; yy < font_h; yy++) { - int xDisplacement = (x * SCREEN_DEPTH * height); - int yDisplacement = ((height - (y + yy) - 1) * SCREEN_DEPTH); + unsigned int xDisplacement = (x * SCREEN_DEPTH * height); + unsigned int yDisplacement = ((height - (y + yy) - 1) * SCREEN_DEPTH); unsigned int pos = xDisplacement + yDisplacement; - int xDisplacementBg = (x * 3 * height); - int yDisplacementBg = ((height - (y + yy) - 1) * 3); + unsigned int xDisplacementBg = (x * 3 * height); + unsigned int yDisplacementBg = ((height - (y + yy) - 1) * 3); unsigned int pos_b = xDisplacementBg + yDisplacementBg; unsigned char char_dat = font_data[(character - ' ') * (c_font_w * font_h) + yy]; @@ -446,17 +446,24 @@ ansi_statemach(void* buf, const int c) case 4: // Background color *color &= 0xf0; // Remove bg color. *color |= ((*val % 40) & 0xf); + break; + default: // ??? break; } *state = ANSI_END; } } return 1; + default: + *state = TEXT; + return 1; } + + return 0; // Should not be reached. } void -putc(void *buf, const int c) +putc(void *buf, int c) { if(ansi_statemach(buf, c) == 1) // Inside ANSI escape? return; @@ -513,7 +520,7 @@ putc(void *buf, const int c) cursor_x[0] = 0; // Reset to beginning of line. break; default: - draw_character(screen, c, cursor_x[0], cursor_y[0], colors[(color[0] >> 4) & 0xF], colors[color[0] & 0xF]); + draw_character(screen, (unsigned int)c, cursor_x[0], cursor_y[0], colors[(color[0] >> 4) & 0xF], colors[color[0] & 0xF]); cursor_x[0]++; @@ -526,12 +533,12 @@ putc(void *buf, const int c) } void -puts(void *buf, const char *string) +puts(void *buf, char *string) { if ((buf == stdout || buf == stderr) && kill_output) return; - char *ref = (char *)string; + char *ref = string; while (ref[0] != 0) { putc(buf, ref[0]); @@ -543,10 +550,11 @@ void put_int64(void *channel, int64_t n, int length) { char conv[32], out[32]; + size_t i = 0, sign = 0; + memset(conv, 0, 32); memset(out, 0, 32); - int i = 0, sign = 0; if (n < 0) { n = -n; sign = 1; @@ -563,8 +571,8 @@ put_int64(void *channel, int64_t n, int length) if (length > 0) out[length] = '\0'; - int len = strlen(conv); - for (int i = 0; i < len; i++) + size_t len = strlen(conv); + for (i = 0; i < len; i++) out[i] = conv[(len - 1) - i]; puts(channel, out); @@ -574,10 +582,11 @@ void put_uint64(void *channel, uint64_t n, int length) { char conv[32], out[32]; + size_t i = 0; + memset(conv, 0, 32); memset(out, 0, 32); - int i = 0; do { conv[i++] = (n % 10) + '0'; } while ((n /= 10) != 0); @@ -585,8 +594,8 @@ put_uint64(void *channel, uint64_t n, int length) if (length > 0) out[length] = '\0'; - int len = strlen(conv); - for (int i = 0; i < len; i++) + size_t len = strlen(conv); + for (i = 0; i < len; i++) out[i] = conv[(len - 1) - i]; puts(channel, out); @@ -630,7 +639,7 @@ fflush(void *channel) int disable_format = 0; void -vfprintf(void *channel, const char *format, va_list ap) +vfprintf(void *channel, char *format, va_list ap) { if ((channel == stdout || channel == stderr) && kill_output) return; @@ -671,15 +680,10 @@ vfprintf(void *channel, const char *format, va_list ap) break; } break; - case 's': - // For now, this warning stays. - disable_format = 1; // Disable format strings. - fprintf(channel, va_arg(ap, char *)); - disable_format = 0; // Reenable. - break; case 'c': putc(channel, va_arg(ap, int)); break; + case 's': case 'p': puts(channel, va_arg(ap, char *)); break; @@ -709,7 +713,7 @@ vfprintf(void *channel, const char *format, va_list ap) } void -fprintf(void *channel, const char *format, ...) +fprintf(void *channel, char *format, ...) { // The output suppression is in all the functions to minimize overhead. // Function calls and format conversions take time and we don't just want @@ -726,7 +730,7 @@ fprintf(void *channel, const char *format, ...) } void -printf(void *channel, const char *format, ...) +printf(char *format, ...) { va_list ap; va_start(ap, format); diff --git a/source/std/fs.c b/source/std/fs.c index d4204f8..8599810 100644 --- a/source/std/fs.c +++ b/source/std/fs.c @@ -12,7 +12,7 @@ static int set_up_fs = 0; // This function is based on PathDeleteWorker from GodMode9. // It was easier to just import it. int -recurse_call_back(char *fpath, void (*call_fun)(char*)) +recurse_call_back(char *fpath, void (*call_fun_param)(char*)) { FILINFO fno; DIR pdir; @@ -35,9 +35,9 @@ recurse_call_back(char *fpath, void (*call_fun)(char*)) if (f2.fattrib & AM_DIR) { // return value won't matter - recurse_call_back(fpath, call_fun); + recurse_call_back(fpath, call_fun_param); } else { - call_fun(fpath); + call_fun_param(fpath); } } @@ -45,15 +45,15 @@ recurse_call_back(char *fpath, void (*call_fun)(char*)) --fname; fname[0] = 0; - call_fun(fpath); + call_fun_param(fpath); return 0; } -void recurse_call(char *name, void (*call_fun)(char*)) { +void recurse_call(char *name, void (*call_fun_param)(char*)) { char fpath[256]; strncpy(fpath, name, 256); - recurse_call_back(fpath, call_fun); + recurse_call_back(fpath, call_fun_param); } int @@ -61,7 +61,7 @@ rrmdir(char *name) { char fpath[256]; strncpy(fpath, name, 256); - recurse_call(fpath, f_unlink); + recurse_call(fpath, (void (*)(char*))f_unlink); return 0; } diff --git a/source/std/memory.c b/source/std/memory.c index fa30d53..6609d6c 100644 --- a/source/std/memory.c +++ b/source/std/memory.c @@ -4,12 +4,12 @@ #include size_t -strlen(const char *string) +strlen(char *string) { - char *string_end = (char *)string; + char *string_end = string; while (string_end[0]) string_end++; - return string_end - string; + return (size_t)(string_end - string); } size_t @@ -46,7 +46,7 @@ void memmove(void *dest, const void *src, size_t size) { // memcpy does the job of moving backwards just fine - if (dest < src || (uint8_t*)src + size <= (uint8_t*)dest) { + if (dest < src || (const uint8_t*)src + size <= (uint8_t*)dest) { memcpy(dest, src, size); return; } -- 2.39.5