AmendHub

Download:

jcs

/

subtext

/

amendments

/

300

*: Minor fixes found by cppcheck and scan-build

Mostly unused variables

jcs made amendment 300 about 1 year ago
--- ansi.c Fri Jan 1 02:02:55 1904 +++ ansi.c Sun Feb 5 09:34:46 2023 @@ -272,7 +272,6 @@ void ansi_probe_screen_size(struct session *s) { short cols, rows; - size_t count = 0; char c[2] = { 0 }; if (!s->vt100) --- bile.c Tue Nov 29 17:13:48 2022 +++ bile.c Sun Feb 5 09:37:19 2023 @@ -126,10 +126,9 @@ struct bile * bile_open(const Str255 filename, short vrefnum) { struct bile *bile = NULL; - struct bile_object map_obj, *o; char magic[BILE_MAGIC_LEN + 1]; - size_t file_size, map_size, size; - short fh, old_map_tried = 0; + size_t file_size, size; + short fh; _bile_error = 0; @@ -270,7 +269,6 @@ struct bile_object * bile_find(struct bile *bile, const OSType type, const unsigned long id) { struct bile_object *o, *ocopy; - unsigned long n; char note[MALLOC_NOTE_SIZE]; bile_check_sanity(bile); @@ -470,7 +468,7 @@ bile_read_object(struct bile *bile, const struct bile_ void *data, const size_t len) { struct bile_object verify; - size_t rsize, wantlen, ret; + size_t rsize, wantlen; bile_check_sanity(bile); @@ -552,7 +550,6 @@ bile_read(struct bile *bile, const OSType type, const void *data, const size_t len) { struct bile_object *o; - size_t ret; bile_check_sanity(bile); @@ -608,7 +605,6 @@ bile_write(struct bile *bile, const OSType type, const { struct bile_object *old, *new_obj; size_t wrote; - short error; bile_check_sanity(bile); @@ -767,7 +763,6 @@ bile_unmarshall_object(struct bile *bile, short bile_verify(struct bile *bile) { - struct bile_object o; size_t n, size, pos; char data; @@ -817,7 +812,6 @@ struct bile_object * bile_alloc(struct bile *bile, const OSType type, const unsigned long id, const size_t size) { - struct bile_object newo; size_t last_pos = BILE_HEADER_LEN; size_t n, map_pos; @@ -967,6 +961,9 @@ bile_write_map(struct bile *bile) new_map[new_nobjects++] = *obj; } + if (new_map_obj_in_new_map == NULL) + panic("bile_write_map: no new map object in new map"); + /* shrink to new object count */ new_map_size = BILE_OBJECT_SIZE * new_nobjects; new_map_obj->size = new_map_size; @@ -1024,9 +1021,7 @@ size_t bile_xwriteat(struct bile *bile, const size_t pos, const void *data, const size_t len) { - short error; size_t wsize, tsize; - long asize; bile_check_sanity(bile); --- board.c Tue Nov 8 13:03:12 2022 +++ board.c Sun Feb 5 09:43:02 2023 @@ -273,9 +273,8 @@ board_list_posts(struct session *s, struct board *boar char time[24]; unsigned long indent_parent_ids[10] = { 0 }; char indent_s[22]; - size_t n, size, idx; + size_t n, size; struct username_cache *user; - struct bile_object *obj; struct board_thread thread = { 0 }; struct board_post post; short indent, j, k; @@ -378,9 +377,8 @@ board_compose(struct session *s, struct board *board, char *initial_subject, char *initial_body) { struct board_post post = { 0 }; - char *data = NULL, *tmp = NULL; - size_t size; - short c, ret; + char *tmp = NULL; + short c; if (!s->user) { session_printf(s, "Posting is not available to guests.\r\n" @@ -545,14 +543,12 @@ board_post_read(struct session *s, struct board *board { 'q', "QqXx", "Return to threads" }, { '?', "?", "List these options" }, }; - char time[32]; + char time[32], prompt[7 + BOARD_NAME_LENGTH + 8]; struct board_thread thread; struct board_post post; - struct username_cache *sender, *recipient; + struct username_cache *sender; struct session_menu_option *dopts = NULL; - unsigned long new_id; - char prompt[7 + BOARD_NAME_LENGTH + 8]; - size_t n, size; + size_t size; short ret = POST_READ_RETURN_DONE; char c; char *data; @@ -641,7 +637,7 @@ board_post_read(struct session *s, struct board *board ret = POST_READ_RETURN_FIND; done = true; } else { - session_printf(s, "\r\Post not deleted.\r\n"); + session_printf(s, "\r\nPost not deleted.\r\n"); session_flush(s); } break; @@ -715,8 +711,8 @@ board_find_post_ids(struct board *board, size_t *npost thread_map = xcalloc(sizeof(struct board_thread_map), nthreads, "board_find_post_ids thread_map"); - for (n = 0; o = bile_get_nth_of_type(board->bile, n, - BOARD_THREAD_RTYPE); n++) { + for (n = 0; (o = bile_get_nth_of_type(board->bile, n, + BOARD_THREAD_RTYPE)); n++) { if (n >= nthreads) { xfree(&o); break; --- chat.c Tue Nov 29 21:33:16 2022 +++ chat.c Sun Feb 5 09:43:53 2023 @@ -23,6 +23,7 @@ #include "chat.h" #include "db.h" #include "session.h" +#include "user.h" #include "util.h" #define CHAT_MAX_INPUT 100 @@ -103,8 +104,7 @@ chat_printf_line(struct session *s, short around_bar, if (pbuf_line != chat_pbuf) { if (!around_bar) - final_len = strlcat(chat_final_pbuf, "\r\n", - sizeof(chat_final_pbuf)); + strlcat(chat_final_pbuf, "\r\n", sizeof(chat_final_pbuf)); final_len = strlcat(chat_final_pbuf, " ", sizeof(chat_final_pbuf)); } @@ -257,8 +257,8 @@ chat_start(struct session *s, char *with_node) xfree(&input); } - session_logf(s, "Left chat with %s", with_node[0] ? with_node : - "everyone"); + session_logf(s, "Left chat with %s", with_node && with_node[0] ? + with_node : "everyone"); snprintf(chat_tbuf, sizeof(chat_tbuf), "*** %s%s has left chat", --- console.c Mon Sep 12 15:32:31 2022 +++ console.c Sun Feb 5 09:46:55 2023 @@ -22,6 +22,7 @@ #include "console.h" #include "focusable.h" #include "session.h" +#include "user.h" #include "util.h" /* for monaco 9 */ @@ -130,7 +131,7 @@ console_idle(struct focusable *focusable, EventRecord struct console *console = (struct console *)focusable->cookie; struct session *session = console->session; GrafPtr old_port; - short n, len, cursor, iac = 0; + short n, cursor, iac = 0; if (session->obuflen == 0) return; @@ -196,7 +197,6 @@ console_idle(struct focusable *focusable, EventRecord } } - len = session->obuflen; session->obuflen = 0; output_done: @@ -219,8 +219,6 @@ void console_update(struct focusable *focusable, EventRecord *event) { struct console *console = (struct console *)focusable->cookie; - GrafPtr old_win; - Rect r; short what = -1; if (event != NULL) @@ -246,7 +244,6 @@ console_key_down(struct focusable *focusable, EventRec { struct console *console = (struct console *)focusable->cookie; unsigned char k; - short km, option_mask, control_mask; if (console->session->ibuflen >= nitems(console->session->ibuf)) return; @@ -406,11 +403,9 @@ console_redraw(struct console *console, short force) { Rect chunk; GrafPtr old_port; - short n, nsize, cell, curbold = -1, line, off, c, firstdirty; - unsigned char curattr, a; + short curbold = -1, line, off, c, firstdirty; + unsigned char curattr = 0, a; - nsize = console->ncolumns * console->nlines; - GetPort(&old_port); SetPort(console->win); @@ -559,7 +554,7 @@ console_parse_csi(struct console *console) short parambuflen; short start, count, offset; struct session *session; - char parambuf[4]; + char parambuf[5]; unsigned char c; if (console->csilen == 0) @@ -599,7 +594,8 @@ console_parse_csi(struct console *console) param1 = 1; if (console->csilen > 1) { - for (x = 0; x < console->csilen - 1, x < nitems(parambuf); x++) { + for (x = 0; x < console->csilen - 1 && + x < nitems(parambuf) - 1; x++) { parambuf[x] = console->csi[x]; parambuf[x + 1] = '\0'; } @@ -624,7 +620,7 @@ console_parse_csi(struct console *console) y = console->csilen - 1; if (y > 0) { - for (x = 0; x < y && x < 4; x++) { + for (x = 0; x < y && x < nitems(parambuf) - 1; x++) { parambuf[x] = console->csi[x]; parambuf[x + 1] = '\0'; } @@ -632,7 +628,8 @@ console_parse_csi(struct console *console) if (y < console->csilen - 2) { parambuf[0] = '\0'; - for (x = 0; x < (console->csilen - 1 - y) && x < 4; x++) { + for (x = 0; x < (console->csilen - 1 - y) && + x < nitems(parambuf) - 1; x++) { parambuf[x] = console->csi[y + 1 + x]; parambuf[x + 1] = '\0'; } @@ -855,7 +852,7 @@ console_parse_csi(struct console *console) parambuf[0] = '\0'; parambuflen = 0; - } else if (parambuflen < 4) { + } else if (parambuflen < nitems(parambuf) - 1) { parambuf[parambuflen] = console->csi[x]; parambuflen++; parambuf[parambuflen] = '\0'; --- db.c Wed Nov 30 13:29:58 2022 +++ db.c Sun Feb 5 10:26:09 2023 @@ -142,7 +142,7 @@ db_create(void) Point pt = { 75, 100 }; SFReply reply; struct bile *bile; - short error; + short error = 0; SFPutFile(pt, "\pCreate new Subtext DB:", "\p", NULL, &reply); if (!reply.good) @@ -170,8 +170,8 @@ db_init(Str255 path, short vrefnum, struct bile *bile) { Str255 fullpath; struct db *tdb; - Handle resh, lastfileh; - short was_new, error, i; + Handle lastfileh; + short was_new; was_new = (bile != NULL); @@ -192,7 +192,7 @@ db_init(Str255 path, short vrefnum, struct bile *bile) /* we got this far, store it as the last-accessed file */ if (vrefnum == 0) - memcpy(fullpath, path, sizeof(fullpath)); + memcpy(&fullpath, path, sizeof(fullpath)); else getpath(vrefnum, path, &fullpath, true); lastfileh = Get1Resource('STR ', STR_LAST_DB); @@ -277,9 +277,7 @@ short db_migrate(struct db *tdb, short is_new) { struct user *user; - struct bile_object *bob; struct db *olddb; - char *error; char ver; if (is_new) { @@ -572,7 +570,6 @@ db_cache_boards(struct db *tdb) Str255 db_filename, board_filename; size_t n, size; unsigned long *ids; - short error; struct bile_object *obj; char *data = NULL; char note[MALLOC_NOTE_SIZE]; @@ -663,7 +660,7 @@ db_board_create(struct db *tdb, struct board *board, b nboard_object_fields, board, &data, &size, "db_board_create"); if (ret != 0 || size == 0) { warn("db_board_create: failed to marshall object"); - return; + return NULL; } if (bile_write(tdb->bile, DB_BOARD_RTYPE, board->id, data, @@ -676,7 +673,7 @@ db_board_create(struct db *tdb, struct board *board, b panic("getpath failed on %s", PtoCstr(tdb->bile->filename)); PtoCstr(db_filename); - snprintf((char *)board_filename, sizeof(board_filename), "%s:%ld.%s", + snprintf((char *)&board_filename, sizeof(board_filename), "%s:%ld.%s", db_filename, board->id, BOARD_FILENAME_EXT); CtoPstr(board_filename); @@ -799,7 +796,7 @@ db_folder_create(struct db *tdb, struct folder *folder nfolder_object_fields, folder, &data, &size, "db_folder_create"); if (ret != 0 || size == 0) { warn("db_folder_create: failed to marshall object"); - return; + return NULL; } if (bile_write(tdb->bile, DB_FOLDER_RTYPE, folder->id, data, @@ -812,7 +809,7 @@ db_folder_create(struct db *tdb, struct folder *folder panic("getpath failed on %s", PtoCstr(tdb->bile->filename)); PtoCstr(db_filename); - snprintf((char *)folder_filename, sizeof(folder_filename), + snprintf((char *)&folder_filename, sizeof(folder_filename), "%s:%ld.%s", db_filename, folder->id, FOLDER_FILENAME_EXT); CtoPstr(folder_filename); @@ -825,7 +822,7 @@ db_folder_create(struct db *tdb, struct folder *folder panic("Failed creating new folder bile at %s: %d", PtoCstr(folder_filename), bile_error(NULL)); - memcpy(folder_dir, folder->path, sizeof(folder_dir)); + memcpy(&folder_dir, folder->path, sizeof(folder_dir)); CtoPstr(folder_dir); if (!FIsDir(folder_dir)) { error = DirCreate(tdb->bile->vrefnum, 0, folder_dir, &newid); --- folder.c Tue Nov 8 13:05:21 2022 +++ folder.c Sun Feb 5 10:30:25 2023 @@ -198,7 +198,7 @@ folder_show(struct session *s, struct folder *folder) { '?', "?", "List menu options" }, }; char prompt[6 + BOARD_NAME_LENGTH + 8]; - size_t n, page, pages, nfile_ids; + size_t page, pages, nfile_ids; unsigned long *file_ids = NULL; short ret; char c; @@ -299,10 +299,8 @@ folder_list_files(struct session *s, struct folder *fo unsigned long pages) { char time[24]; - size_t n, off, size, idx; - struct bile_object *obj; + size_t n, off, size; struct folder_file file; - short j, k; char *data; session_printf(s, "{{B}}%s: %s (Page %ld of %ld){{/B}}\r\n", @@ -353,7 +351,7 @@ folder_upload(struct session *s, struct folder *folder struct zmodem_session *zs; char *upload_path = NULL, *data = NULL, *tmp = NULL, *errorstr = NULL; size_t size; - short c, n, ret, error; + short c, n, error; if (!s->user) { session_printf(s, "Uploading is not available to guests.\r\n" @@ -661,17 +659,15 @@ folder_file_view(struct session *s, struct folder *fol { '?', "?", "List these options" }, }; char time[32]; + char prompt[6 + BOARD_NAME_LENGTH + 1 + FOLDER_FILE_FILENAME_LENGTH]; + char *path = NULL, *data, c; struct folder_file file; struct username_cache *uploader; struct zmodem_session *zs; struct session_menu_option *dopts = NULL; FILE *fp; - char *path = NULL; - char prompt[6 + BOARD_NAME_LENGTH + 1 + FOLDER_FILE_FILENAME_LENGTH]; - size_t n, size; - char c; - char *data; - short cc, ret; + size_t size; + short cc, ret = FILE_VIEW_RETURN_FIND; bool done = false, show_help = false; size = bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, id, &data); @@ -816,7 +812,7 @@ folder_file_view(struct session *s, struct folder *fol ret = FILE_VIEW_RETURN_FIND; done = true; } else { - session_printf(s, "\r\Post not deleted.\r\n"); + session_printf(s, "\r\nPost not deleted.\r\n"); session_flush(s); } break; @@ -860,7 +856,7 @@ folder_find_file_ids(struct folder *folder, size_t *nf unsigned long id; char filename[10]; /* only sorted to 10 character places */ } *name_map = NULL, tmp_map; - size_t n, size; + size_t n; short i, j; char *data; @@ -871,8 +867,8 @@ folder_find_file_ids(struct folder *folder, size_t *nf name_map = xcalloc(*nfile_ids, sizeof(struct file_name_map), "folder_find_file_ids"); - for (n = 0; o = bile_get_nth_of_type(folder->bile, n, - FOLDER_FILE_RTYPE); n++) { + for (n = 0; (o = bile_get_nth_of_type(folder->bile, n, + FOLDER_FILE_RTYPE)); n++) { if (n >= *nfile_ids) break; bile_read_alloc(folder->bile, FOLDER_FILE_RTYPE, o->id, &data); @@ -918,8 +914,6 @@ folder_file_save(struct folder *folder, struct folder_ short ret; char *data; size_t size; - ssize_t n, j; - size_t insert; file->id = bile_next_id(folder->bile, FOLDER_FILE_RTYPE); file->time = Time; @@ -1040,8 +1034,8 @@ folder_file_valid_filename(struct session *session, } } - for (n = 0; o = bile_get_nth_of_type(folder->bile, n, - FOLDER_FILE_RTYPE); n++) { + for (n = 0; (o = bile_get_nth_of_type(folder->bile, n, + FOLDER_FILE_RTYPE)); n++) { if (o->id == file->id) { xfree(&o); continue; --- logger.c Fri Nov 18 14:18:20 2022 +++ logger.c Sun Feb 5 10:32:56 2023 @@ -20,11 +20,12 @@ #include "focusable.h" #include "logger.h" #include "subtext.h" +#include "user.h" #include "util.h" struct logger *logger = NULL; -void logger_layout(bool init, Rect *init_bounds); +void logger_layout(Rect *init_bounds); void logger_key_down(struct focusable *focusable, EventRecord *event); void logger_mouse_down(struct focusable *focusable, EventRecord *event); void logger_resize(struct focusable *focusable, EventRecord *event); @@ -66,7 +67,7 @@ logger_init(void) bounds.right -= bounds.left; bounds.bottom -= bounds.top; bounds.top = bounds.left = 0; - logger_layout(true, &bounds); + logger_layout(&bounds); focusable = xmalloczero(sizeof(struct focusable), "logger focusable"); focusable->win = logger->win; @@ -84,10 +85,11 @@ logger_init(void) } void -logger_layout(bool init, Rect *init_bounds) +logger_layout(Rect *init_bounds) { Rect bounds, inset_bounds, win_bounds; - + bool init = (init_bounds != NULL); + if (init) win_bounds = *init_bounds; else @@ -226,7 +228,6 @@ logger_mouse_down(struct focusable *focusable, EventRe ControlHandle control; Rect r; int val, adj; - short part; p = event->where; GlobalToLocal(&p); @@ -243,7 +244,7 @@ logger_mouse_down(struct focusable *focusable, EventRe return; } - switch (part = FindControl(p, logger->win, &control)) { + switch (FindControl(p, logger->win, &control)) { case inUpButton: case inDownButton: case inPageUp: @@ -285,7 +286,7 @@ logger_resize(struct focusable *focusable, EventRecord height = HiWord(newsize); width = LoWord(newsize); SizeWindow(focusable->win, width, height, true); - logger_layout(false, NULL); + logger_layout(NULL); } size_t @@ -308,9 +309,8 @@ size_t logger_vprintf(const char *format, va_list ap) { static char buf[600]; - ssize_t left, len; + ssize_t len; time_t now = Time; - short line_height = 0; if (!logger) return 0; @@ -335,6 +335,8 @@ logger_vprintf(const char *format, va_list ap) if (logger->autoflush) logger_flush_buffer(false); + + return len; } void --- mail.c Fri Nov 11 22:23:27 2022 +++ mail.c Sun Feb 5 10:33:32 2023 @@ -126,7 +126,7 @@ mail_menu(struct session *s) { 'q', "QqXx", "Return to main menu" }, { '?', "?", "Show this help menu" }, }; - size_t nmsgs, nmail_ids, id; + size_t nmsgs, nmail_ids; unsigned long *mail_ids = NULL, page, pages; short ret; char c; @@ -619,7 +619,7 @@ mail_find_ids_for_user(struct user *user, size_t *nmai unsigned long msg_user_id; struct bile_object *o; struct mail_message msg; - size_t n, nmsgs_for_user, nret, mail_ids_size, id, size; + size_t n, nmsgs_for_user, mail_ids_size, id, size; short i, j; char *data; bool read; @@ -631,7 +631,7 @@ mail_find_ids_for_user(struct user *user, size_t *nmai *nmail_ids = 0; nmsgs_for_user = 0; - for (n = 0; o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE); + for (n = 0; (o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE)); n++) { id = o->id; bile_read(db->bile, DB_MESSAGE_RTYPE, id, (char *)&msg_user_id, --- main.c Fri Nov 18 14:24:04 2022 +++ main.c Sun Feb 5 10:36:26 2023 @@ -140,7 +140,7 @@ main(void) strftime(today, sizeof(today), "%Y%m%d", date_tm); if (strcmp(today, last_daily_job) != 0) { session_purge_logs(db->config.session_log_days); - strlcpy(last_daily_job, today, sizeof(today)); + strlcpy(last_daily_job, today, sizeof(last_daily_job)); } } @@ -279,8 +279,7 @@ handle_exit(void) bool handle_menu(long menu_id) { - bool ret = false; - bool quit = false; + bool ret = false, quit; size_t n; switch (HiWord(menu_id)) { @@ -330,7 +329,8 @@ handle_menu(long menu_id) xfree(&tfocusables); } - ExitToShell(); + if (quit) + ExitToShell(); break; } } @@ -349,7 +349,7 @@ handle_menu(long menu_id) main_menu_edit(); break; } - ret = 1; + ret = true; break; case VIEWS_SUBMENU_ID: switch (LoWord(menu_id)) { @@ -375,7 +375,7 @@ handle_menu(long menu_id) view_editor_show(DB_TEXT_SIGNOFF_ID, "Edit: Session Signoff view"); break; } - ret = 1; + ret = true; break; } @@ -386,8 +386,6 @@ handle_menu(long menu_id) void blanker_idle(void) { - unsigned long t; - if (!blanker_on && !nsessions && (Time - blanker_last_blank > db->config.blanker_idle_seconds)) { HideMenuBar(); --- main_menu.c Fri Nov 11 23:02:08 2022 +++ main_menu.c Sun Feb 5 10:37:04 2023 @@ -29,7 +29,6 @@ main_menu_init(void) struct main_menu_option *opts = NULL, *old_opts = NULL; size_t size; char *menu = NULL; - bool ok = false; Handle default_menu; size = bile_read_alloc(db->bile, DB_TEXT_TYPE, DB_TEXT_MENU_OPTIONS_ID, @@ -53,7 +52,7 @@ main_menu_init(void) } opts = main_menu_parse(menu, size); - free(&menu); + xfree(&menu); if (opts == NULL) { main_menu_edit(); return; @@ -77,7 +76,7 @@ main_menu_parse(char *opts, size_t len) { char *line, *action, *menu_key, *all_keys, *label; size_t n, m, linelen, lastsep, linenum, ret_size; - short count, actionid, ret_count; + short actionid, ret_count; struct main_menu_option *ret = NULL; #define LINESIZE 1024 --- serial.c Sun Feb 5 09:31:46 2023 +++ serial.c Sun Feb 5 10:38:19 2023 @@ -58,7 +58,6 @@ /* The number of seconds of continuous write timeouts before we hang up */ #define SERIAL_WRITE_GIVE_UP 45 -static bool serial_initialized = false; static short serial_out_refnum = 0, serial_in_refnum = 0; static char serial_input_internal_buf[1024]; static char serial_input_buf[128]; @@ -188,10 +187,10 @@ serial_init(void) (db->config.modem_port == 2 ? "printer" : "modem"), db->config.modem_speed, db->config.modem_parity); - if ((error = SerReset(serial_in_refnum, baud + parity)) != 0) - panic("SerReset(in) failed: %d", error); - if ((error = SerReset(serial_out_refnum, baud + parity)) != 0) - panic("SerReset(out) failed: %d", error); + if ((error = SerReset(serial_in_refnum, baud + parity)) != 0) + panic("SerReset(in) failed: %d", error); + if ((error = SerReset(serial_out_refnum, baud + parity)) != 0) + panic("SerReset(out) failed: %d", error); SerSetBuf(serial_in_refnum, (Ptr)&serial_input_internal_buf, sizeof(serial_input_internal_buf)); @@ -269,8 +268,7 @@ serial_printf(const char *format, ...) { static char serial_printf_tbuf[256]; va_list ap; - size_t len, n; - long one; + size_t len; va_start(ap, format); len = vsnprintf(serial_printf_tbuf, sizeof(serial_printf_tbuf), @@ -415,7 +413,6 @@ void serial_idle(void) { SerStaRec status; - long count, i; char *line; SerStatus(serial_in_refnum, &status); @@ -485,11 +482,8 @@ serial_idle(void) short serial_input(struct session *session) { - struct serial_node *node = (struct serial_node *)session->cookie; - unsigned short rlen; long len; short error, n; - unsigned char c; if (session->ending) return 0; --- session.c Sun Jan 15 21:14:20 2023 +++ session.c Sun Feb 5 10:42:38 2023 @@ -370,7 +370,7 @@ session_print_menu(struct session *session, bool short { struct main_menu_option *option = NULL; size_t size; - short i, j; + short i; char *output = NULL; if (short_menu && session_output_view_or_printf(session, @@ -386,7 +386,7 @@ session_print_menu(struct session *session, bool short if (option->action == ACTION_NONE) break; - if (option->menu_key == 0 || option->label == NULL) + if (option->menu_key == 0 || option->label[0] == '\0') continue; size = session_expand_template(session, option->label, &output); @@ -1218,8 +1218,13 @@ expand_var: retpos += vallen; } } - data[retpos] = '\0'; + if (data == NULL) { + *ret = NULL; + return 0; + } + + data[retpos] = '\0'; *ret = data; return retpos; } @@ -1580,8 +1585,6 @@ session_purge_logs(short days) struct session_log log; size_t n, size = 0, count = 0, delta; unsigned long secs, *ids = NULL; - struct tm *date_tm; - char date[20]; secs = (60UL * 60UL * 24UL * (unsigned long)days); --- settings.c Fri Nov 18 09:28:24 2022 +++ settings.c Sun Feb 5 10:43:38 2023 @@ -47,12 +47,11 @@ struct_editor(struct session *s, const struct struct_f const size_t nfields, void *data, size_t dsize, void **result, char *title, char *prompt) { - Handle ihandle; const struct struct_field *sf; long lval; char co, initial[20]; char *input = NULL, *new_data; - short itype, hit, n, sval; + short n, sval; bool found, any_changes = false; unsigned short c; @@ -263,7 +262,7 @@ get_input: snprintf(initial, sizeof(initial), "0.0.0.0"); else { long2ip(lval, ip_str); - snprintf(initial, sizeof(initial), ip_str); + snprintf(initial, sizeof(initial), "%s", ip_str); } input = session_field_input(s, 16, 16, initial, false, 0); @@ -447,7 +446,7 @@ view_editor_mouse_down(struct focusable *focusable, Ev Point p; ControlHandle control; Rect r; - short val, adj, part; + short val, adj; p = event->where; GlobalToLocal(&p); @@ -459,7 +458,7 @@ view_editor_mouse_down(struct focusable *focusable, Ev return; } - switch (part = FindControl(p, view_editor->win, &control)) { + switch (FindControl(p, view_editor->win, &control)) { case inButton: if (TrackControl(control, p, 0L)) { if (control == view_editor->save_button) --- settings.h Tue Nov 8 14:34:51 2022 +++ settings.h Sun Feb 5 10:44:01 2023 @@ -31,8 +31,8 @@ struct struct_field { char name[32]; short type; unsigned short off; - unsigned short min; - unsigned short max; + unsigned long min; + unsigned long max; }; short struct_editor(struct session *s, const struct struct_field *fields, --- sysop.c Wed Nov 30 13:29:04 2022 +++ sysop.c Sun Feb 5 10:44:34 2023 @@ -369,14 +369,9 @@ sysop_edit_motd(struct session *s) { 'q', "QqXx", "Return to sysop menu" }, { '?', "?", "List menu options" }, }; - char prompt[30]; - struct session_menu_option *opt; - size_t n, size; - short ret; - char c, *data = NULL; + char c; bool show_help = true; bool done = false; - bool found = false; while (!done && !s->ending) { c = session_menu(s, "MOTD Editor", "Sysop:MOTD", opts, --- tcp.c Sat Jul 23 19:46:52 2022 +++ tcp.c Sun Feb 5 10:44:47 2023 @@ -97,7 +97,6 @@ _TCPPassiveOpen(TCPiopb *pb, StreamPtr stream, ip_addr Ptr userData, TCPIOCompletionProc ioCompletion, Boolean async) { OSErr osErr; - short index; memset(pb, 0, sizeof(*pb)); --- telnet.c Tue Oct 25 16:49:50 2022 +++ telnet.c Sun Feb 5 10:45:41 2023 @@ -189,7 +189,7 @@ void telnet_atexit(void) { struct telnet_node *node; - short n, error; + short n; for (n = 0; n < MAX_TELNET_NODES; n++) { node = telnet_nodes[n]; @@ -256,7 +256,7 @@ void telnet_idle(void) { struct telnet_node *node; - short n, j, error; + short n, error; if (!db->config.telnet_port) return; @@ -558,7 +558,7 @@ telnet_input(struct session *session) break; case IAC_NEWENV: { char k[sizeof(node->iac_sb)], v[sizeof(node->iac_sb)]; - char l = 0; + unsigned char l = 0; bool inv = false; k[0] = v[0] = '\0'; @@ -724,7 +724,7 @@ short telnet_output(struct session *session) { struct telnet_node *node = (struct telnet_node *)session->cookie; - short n, error; + short error; unsigned char c; unsigned long now; @@ -829,7 +829,7 @@ telnet_close(struct session *session) { struct telnet_node *node = (struct telnet_node *)session->cookie; size_t len; - short error, n; + short error; unsigned char *tmp; if (node->from_trusted_proxy) @@ -859,7 +859,7 @@ telnet_close(struct session *session) session_logf(session, "Closing telnet connection from %s", node->ip_s); - error = _TCPClose(&telnet_exit_pb, node->stream, nil, nil, false); + _TCPClose(&telnet_exit_pb, node->stream, nil, nil, false); /* TODO: allow some time to fully close? */ } --- user.c Tue Nov 8 10:46:49 2022 +++ user.c Sun Feb 5 10:55:59 2023 @@ -79,7 +79,7 @@ user_cache_usernames(void) void user_save(struct user *user) { - size_t len, n; + size_t len; if (!user->id) { user->id = bile_next_id(db->bile, DB_USER_RTYPE); @@ -192,7 +192,7 @@ user_set_password(struct user *user, const char *passw short n; /* make a random salt out of a sha256 of some random longs */ - for (n = 0; n < sizeof(tmp); n++) + for (n = 0; n < nitems(tmp) - 1; n++) tmp[n] = xorshift32(); SHA256Data((const u_int8_t *)tmp, sizeof(tmp), salt); @@ -290,11 +290,11 @@ user_first_sysop_username(void) struct user user; struct bile_object *o; char *ret = NULL; - size_t nuser, len; + size_t nuser; nuser = 0; while ((o = bile_get_nth_of_type(db->bile, nuser, DB_USER_RTYPE))) { - len = bile_read(db->bile, DB_USER_RTYPE, o->id, (char *)&user, + bile_read(db->bile, DB_USER_RTYPE, o->id, (char *)&user, sizeof(user)); xfree(&o); if (user.is_sysop) { @@ -387,7 +387,7 @@ user_delete(struct user *user) /* delete the user's mail */ n = 0; - while (o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE)) { + while ((o = bile_get_nth_of_type(db->bile, n, DB_MESSAGE_RTYPE))) { id = o->id; bile_read(db->bile, DB_MESSAGE_RTYPE, id, (char *)&msg_user_id, sizeof(msg_user_id)); --- uthread.c Sun Nov 6 20:33:37 2022 +++ uthread.c Sun Feb 5 10:47:09 2023 @@ -195,8 +195,7 @@ uthread_begin(struct uthread *uthread) void uthread_coordinate(void) { - short i, n; - unsigned char *gap; + short i; for (i = 0; i < NUM_UTHREADS; i++) { if (uthreads[i].state == UTHREAD_STATE_DEAD) --- util.c Fri Sep 16 17:56:10 2022 +++ util.c Sun Feb 5 10:48:19 2023 @@ -264,7 +264,9 @@ void * xrealloc(void *src, size_t size) { void *ptr, *tsrc; +#ifdef MALLOC_DEBUG unsigned long n; +#endif char note[MALLOC_NOTE_SIZE] = "realloc from null"; #ifdef MALLOC_DEBUG @@ -971,7 +973,6 @@ bool FIsDir(Str255 path) { struct stat st; - short ret; if (FStat(path, &st) != 0) return false; @@ -1771,9 +1772,8 @@ static int nullio(FILE *fp, int i); int bounded_vfprintf(FILE *fp, const char *fmt, va_list arg) { - register int c, i, j, nwritten = 0; + register int c, i, nwritten = 0; register unsigned long n; - long double x; register char *s; #define VFPRINTF_BUFLEN 512 char buf[VFPRINTF_BUFLEN], *digits, *t; @@ -1994,7 +1994,7 @@ conv: switch (c) { else { if (!F.havePrecision) i = strlen(s); - else if (t = memchr(s, '\0', F.precision)) + else if ((t = memchr(s, '\0', F.precision)) != NULL) i = t - s; else i = F.precision; --- util.h Fri Nov 11 16:57:46 2022 +++ util.h Mon Jan 2 15:10:58 2023 @@ -170,4 +170,6 @@ char * strsep(char **stringp, const char *delim); int snprintf(char *s, size_t size, const char *fmt, ...); int vsnprintf(char *s, size_t size, const char *fmt, void *p); +void malloc_map_dump(void); + #endif