diff options
author | Solomon Peachy <pizza@shaftnet.org> | 2020-10-27 11:14:23 -0400 |
---|---|---|
committer | Solomon Peachy <pizza@shaftnet.org> | 2020-10-28 08:42:49 -0400 |
commit | a605cdf7008f856946cbf01193f4dffc3ee63fdb (patch) | |
tree | 53368641340ffd9d10f77f56b2bde66916a1cfd1 /apps/plugins | |
parent | 621e363e70e69a92169494515c5637551ceba219 (diff) | |
download | rockbox-a605cdf7008f856946cbf01193f4dffc3ee63fdb.tar.gz rockbox-a605cdf7008f856946cbf01193f4dffc3ee63fdb.zip |
Fix multiple potential null pointer dereferencess
GCC's optimizer thinks all of these _will_ fail at some point
Change-Id: I287eeb574162a5d3b3347654d25aa1f53e9f5563
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/chessbox/chessbox_pgn.c | 14 | ||||
-rw-r--r-- | apps/plugins/reversi/reversi-gui.c | 7 |
2 files changed, 15 insertions, 6 deletions
diff --git a/apps/plugins/chessbox/chessbox_pgn.c b/apps/plugins/chessbox/chessbox_pgn.c index 40e88e500b..0d9da441b1 100644 --- a/apps/plugins/chessbox/chessbox_pgn.c +++ b/apps/plugins/chessbox/chessbox_pgn.c | |||
@@ -623,6 +623,7 @@ struct pgn_game_node* pgn_list_games(const char* filename){ | |||
623 | /* a new game header is found */ | 623 | /* a new game header is found */ |
624 | if (line_buffer[0] == '['){ | 624 | if (line_buffer[0] == '['){ |
625 | temp_node = (struct pgn_game_node *)pl_malloc(sizeof size_node); | 625 | temp_node = (struct pgn_game_node *)pl_malloc(sizeof size_node); |
626 | if (!temp_node) return NULL; | ||
626 | temp_node->next_node = NULL; | 627 | temp_node->next_node = NULL; |
627 | if (curr_node == NULL) { | 628 | if (curr_node == NULL) { |
628 | first_game = curr_node = temp_node; | 629 | first_game = curr_node = temp_node; |
@@ -773,9 +774,11 @@ void pgn_parse_game(const char* filename, | |||
773 | */ | 774 | */ |
774 | if (first_ply != NULL){ | 775 | if (first_ply != NULL){ |
775 | temp_ply = (struct pgn_ply_node *)pl_malloc(sizeof size_ply); | 776 | temp_ply = (struct pgn_ply_node *)pl_malloc(sizeof size_ply); |
776 | temp_ply->player = neutral; | 777 | if (temp_ply) { |
777 | temp_ply->prev_node = curr_node; | 778 | temp_ply->player = neutral; |
778 | curr_node->next_node = temp_ply; | 779 | temp_ply->prev_node = curr_node; |
780 | curr_node->next_node = temp_ply; | ||
781 | } | ||
779 | } | 782 | } |
780 | selected_game->first_ply = first_ply; | 783 | selected_game->first_ply = first_ply; |
781 | 784 | ||
@@ -793,6 +796,7 @@ struct pgn_game_node* pgn_init_game(void){ | |||
793 | 796 | ||
794 | /* create an "end of game" dummy ply and assign defaults */ | 797 | /* create an "end of game" dummy ply and assign defaults */ |
795 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); | 798 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); |
799 | if (!ply) return NULL; | ||
796 | ply->player = neutral; | 800 | ply->player = neutral; |
797 | ply->pgn_text[0] = '\0'; | 801 | ply->pgn_text[0] = '\0'; |
798 | ply->prev_node = NULL; | 802 | ply->prev_node = NULL; |
@@ -800,6 +804,8 @@ struct pgn_game_node* pgn_init_game(void){ | |||
800 | 804 | ||
801 | /* create the game and assign defaults */ | 805 | /* create the game and assign defaults */ |
802 | game = (struct pgn_game_node *)pl_malloc(sizeof game_size); | 806 | game = (struct pgn_game_node *)pl_malloc(sizeof game_size); |
807 | if (!game) return NULL; | ||
808 | |||
803 | game->game_number = 0; | 809 | game->game_number = 0; |
804 | rb->strcpy(game->white_player,"Player"); | 810 | rb->strcpy(game->white_player,"Player"); |
805 | rb->strcpy(game->black_player,"GnuChess"); | 811 | rb->strcpy(game->black_player,"GnuChess"); |
@@ -823,6 +829,7 @@ void pgn_append_ply(struct pgn_game_node* game, | |||
823 | struct pgn_ply_node ply_size, *ply, *temp; | 829 | struct pgn_ply_node ply_size, *ply, *temp; |
824 | 830 | ||
825 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); | 831 | ply = (struct pgn_ply_node *)pl_malloc(sizeof ply_size); |
832 | if (!ply) return; | ||
826 | ply->player = ply_player; | 833 | ply->player = ply_player; |
827 | ply->column_from = move_buffer[0] - 'a'; | 834 | ply->column_from = move_buffer[0] - 'a'; |
828 | ply->row_from = move_buffer[1] - '1'; | 835 | ply->row_from = move_buffer[1] - '1'; |
@@ -847,6 +854,7 @@ void pgn_append_ply(struct pgn_game_node* game, | |||
847 | } else { | 854 | } else { |
848 | temp->prev_node->next_node = ply; | 855 | temp->prev_node->next_node = ply; |
849 | } | 856 | } |
857 | |||
850 | temp->prev_node = ply; | 858 | temp->prev_node = ply; |
851 | } | 859 | } |
852 | 860 | ||
diff --git a/apps/plugins/reversi/reversi-gui.c b/apps/plugins/reversi/reversi-gui.c index aca54a1ea3..74dd98b676 100644 --- a/apps/plugins/reversi/reversi-gui.c +++ b/apps/plugins/reversi/reversi-gui.c | |||
@@ -637,12 +637,13 @@ enum plugin_status plugin_start(const void *parameter) { | |||
637 | draw_screen = false; | 637 | draw_screen = false; |
638 | } | 638 | } |
639 | switch(cur_player) { | 639 | switch(cur_player) { |
640 | case BLACK: | ||
641 | cur_strategy = black_strategy; | ||
642 | break; | ||
643 | case WHITE: | 640 | case WHITE: |
644 | cur_strategy = white_strategy; | 641 | cur_strategy = white_strategy; |
645 | break; | 642 | break; |
643 | case BLACK: | ||
644 | default: | ||
645 | cur_strategy = black_strategy; | ||
646 | break; | ||
646 | } | 647 | } |
647 | 648 | ||
648 | if(cur_strategy->is_robot && !game_finished) { | 649 | if(cur_strategy->is_robot && !game_finished) { |