AmendHub

Download:

jcs

/

subtext

/

amendments

/

114

*: Minor bug fixes, better NULL checks


jcs made amendment 114 over 2 years ago
--- mail.c Tue May 24 22:59:15 2022 +++ mail.c Wed Jun 1 16:44:05 2022 @@ -60,7 +60,7 @@ size_t nmail_object_fields = nitems(mail_object_fields void mail_free_message_strings(struct mail_message *msg); short mail_save(struct session *s, struct mail_message *msg); short mail_read(struct session *s, unsigned long id, short idx); -void mail_list(struct session *s, unsigned long *mail_ids, size_t nmsgs, +void mail_list(struct session *s, size_t nmsgs, unsigned long *mail_ids, size_t page, size_t pages); short mail_get_message_id(struct session *s, size_t nmsgs, char *prompt, short initial); @@ -68,11 +68,11 @@ short mail_get_message_id(struct session *s, size_t nm void mail_free_message_strings(struct mail_message *msg) { - if (msg->subject) { + if (msg->subject != NULL) { free(msg->subject); msg->subject = NULL; } - if (msg->body) { + if (msg->body != NULL) { free(msg->body); msg->body = NULL; } @@ -109,7 +109,7 @@ get_id: } get_id_done: - if (tmp) + if (tmp != NULL) free(tmp); return ret; } @@ -126,9 +126,8 @@ mail_menu(struct session *s) { 'q', "QqXx", "Return to main menu" }, { '?', "?", "Show this help menu" }, }; - char title[30]; - size_t nmsgs, nmail_ids, id, page, pages; - unsigned long *mail_ids = NULL; + size_t nmsgs, nmail_ids, id; + unsigned long *mail_ids = NULL, page, pages; short ret; char c; bool show_help = false; @@ -147,6 +146,8 @@ mail_menu(struct session *s) while (!done) { if (find_message_ids) { + if (mail_ids != NULL) + free(mail_ids); nmsgs = mail_find_ids_for_user(s->user, &nmail_ids, &mail_ids, page * MSGS_PER_PAGE, MSGS_PER_PAGE, false); /* ceil(nmsgs / MSGS_PER_PAGE) */ @@ -159,7 +160,7 @@ mail_menu(struct session *s) } if (show_list) { - mail_list(s, mail_ids, nmail_ids, page + 1, pages); + mail_list(s, nmail_ids, mail_ids, page + 1, pages); show_list = false; } @@ -234,7 +235,8 @@ handle_opt: } } - free(mail_ids); + if (mail_ids != NULL) + free(mail_ids); } void @@ -383,13 +385,13 @@ mail_compose_start: } mail_compose_done: - if (to_username) + if (to_username != NULL) free(to_username); mail_free_message_strings(&msg); } void -mail_list(struct session *s, unsigned long *mail_ids, size_t nmsgs, +mail_list(struct session *s, size_t nmail_ids, unsigned long *mail_ids, size_t page, size_t pages) { char time[10]; @@ -404,13 +406,13 @@ mail_list(struct session *s, unsigned long *mail_ids, ansi(s, ANSI_BOLD, ANSI_END), ansi(s, ANSI_RESET, ANSI_END)); session_flush(s); - for (n = 0; n < nmsgs; n++) { + for (n = 0; n < nmail_ids; n++) { size = bile_read_alloc(db->bile, DB_MESSAGE_RTYPE, mail_ids[n], &data); if (size == 0) break; bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg); + nitems(mail_object_fields), data, size, &msg, true); free(data); user = user_find_username(msg.sender_user_id); @@ -461,7 +463,7 @@ mail_read(struct session *s, unsigned long id, short i } bile_unmarshall_object(db->bile, mail_object_fields, - nitems(mail_object_fields), data, size, &msg); + nitems(mail_object_fields), data, size, &msg, true); free(data); sender = user_find_username(msg.sender_user_id); @@ -622,17 +624,16 @@ mail_find_ids_for_user(struct user *user, size_t *nmai if (only_unread) { size = bile_read_alloc(db->bile, DB_MESSAGE_RTYPE, id, &data); - bile_unmarshall_object(db->bile, - mail_object_fields, nmail_object_fields, data, size, &msg); + bile_unmarshall_object(db->bile, mail_object_fields, + nmail_object_fields, data, size, &msg, false); read = msg.read; - mail_free_message_strings(&msg); if (read) continue; } if (mail_ids != NULL) { EXPAND_TO_FIT(*mail_ids, mail_ids_size, - nmsgs_for_user * sizeof(long), sizeof(long), + (nmsgs_for_user + 1) * sizeof(long), sizeof(long), sizeof(long) * 16); (*mail_ids)[nmsgs_for_user] = id; } --- main.c Mon May 23 13:04:06 2022 +++ main.c Wed Jun 1 13:09:38 2022 @@ -50,6 +50,7 @@ main(void) short event_in, n, finder_action, finder_count; char key; + util_init(); uthread_init(); InitGraf(&thePort); --- session.c Tue May 24 16:46:13 2022 +++ session.c Wed Jun 1 16:46:32 2022 @@ -207,7 +207,7 @@ get_another_char: case '8': case '9': case '0': - board_view(s, c - '0'); + board_show(s, c - '0'); break; case '!': if (!s->user || !s->user->is_sysop) { @@ -270,7 +270,7 @@ session_close(struct session *session) /* remove session from sessions */ newnsessions = nsessions - 1; if (newnsessions) { - newsessions = xmallocarray(newnsessions, sizeof(struct session)); + newsessions = xcalloc(newnsessions, sizeof(struct session)); nsessions = 0; for (n = 0; n < newnsessions; n++) { if (sessions[n] == session) @@ -708,13 +708,14 @@ session_login(struct session *s) if (username[0] == '\0') { n--; free(username); + username = NULL; continue; } } if (strcmp(username, GUEST_USERNAME) == 0) { - free(username); session_log(s, "Successful guest login in as %s", username); + free(username); return AUTH_USER_OK; } @@ -782,9 +783,9 @@ session_login(struct session *s) } login_bail: - if (username) + if (username != NULL) free(username); - if (password) + if (password != NULL) free(password); session_output_string(s, "Thanks for playing\r\n"); session_flush(s); @@ -1104,7 +1105,7 @@ session_page_sysop(struct session *s) session_flush(s); page_done: - if (message) + if (message != NULL) free(message); } --- signup.c Fri May 20 10:42:08 2022 +++ signup.c Wed Jun 1 13:10:21 2022 @@ -109,11 +109,11 @@ signup(struct session *s) session_log(s, "New user account created for %s", user->username); signup_done: - if (username) + if (username != NULL) free(username); - if (password) + if (password != NULL) free(password); - if (password_confirm) + if (password_confirm != NULL) free(password_confirm); return user; --- user.c Mon May 23 13:58:48 2022 +++ user.c Wed Jun 1 13:10:51 2022 @@ -272,7 +272,7 @@ user_valid_username(char *username, char **error) ret = 1; done: - if (lower) + if (lower != NULL) free(lower); return ret; } --- user_settings.c Fri May 20 10:42:25 2022 +++ user_settings.c Wed Jun 1 13:11:01 2022 @@ -170,9 +170,9 @@ user_settings_password(struct session *s) break; } - if (password) + if (password != NULL) free(password); - if (password_confirm) + if (password_confirm != NULL) free(password_confirm); }