author | erik <erik> | 2007-01-22 23:01:41 (UTC) |
---|---|---|
committer | erik <erik> | 2007-01-22 23:01:41 (UTC) |
commit | adcf6075db477909dd8170a74862a6ef91a5127f (patch) (unidiff) | |
tree | da0a1e35c5d392271bce29e84d3af5c30a864f56 /noncore/games/minesweep | |
parent | 9b4871054d01a47b4c546952a0948553413840d6 (diff) | |
download | opie-adcf6075db477909dd8170a74862a6ef91a5127f.zip opie-adcf6075db477909dd8170a74862a6ef91a5127f.tar.gz opie-adcf6075db477909dd8170a74862a6ef91a5127f.tar.bz2 |
Each file in this commit had a problem where a function might return
a null value for a pointer and that null value was not checked.
-rw-r--r-- | noncore/games/minesweep/minefield.cpp | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/noncore/games/minesweep/minefield.cpp b/noncore/games/minesweep/minefield.cpp index 72c05b0..1987ea5 100644 --- a/noncore/games/minesweep/minefield.cpp +++ b/noncore/games/minesweep/minefield.cpp | |||
@@ -611,137 +611,139 @@ void MineField::updateMine( int row, int col ) | |||
611 | m->activate( flagAction == NoAction ); | 611 | m->activate( flagAction == NoAction ); |
612 | 612 | ||
613 | if ( m->state() == Mine::Exploded ) { | 613 | if ( m->state() == Mine::Exploded ) { |
614 | emit gameOver( FALSE ); | 614 | emit gameOver( FALSE ); |
615 | setState( GameOver ); | 615 | setState( GameOver ); |
616 | return; | 616 | return; |
617 | } else if ( m->state() == Mine::Empty ) { | 617 | } else if ( m->state() == Mine::Empty ) { |
618 | setHint( row, col ); | 618 | setHint( row, col ); |
619 | if ( !wasEmpty ) | 619 | if ( !wasEmpty ) |
620 | nonminecount--; | 620 | nonminecount--; |
621 | } | 621 | } |
622 | 622 | ||
623 | if ( flagAction != NoAction ) { | 623 | if ( flagAction != NoAction ) { |
624 | if ( m->state() == Mine::Flagged ) { | 624 | if ( m->state() == Mine::Flagged ) { |
625 | if (mineguess > 0) { | 625 | if (mineguess > 0) { |
626 | --mineguess; | 626 | --mineguess; |
627 | emit mineCount( mineguess ); | 627 | emit mineCount( mineguess ); |
628 | if ( m->isMined() ) | 628 | if ( m->isMined() ) |
629 | --minecount; | 629 | --minecount; |
630 | } else { | 630 | } else { |
631 | m->setState(Mine::Hidden); | 631 | m->setState(Mine::Hidden); |
632 | } | 632 | } |
633 | } else if ( wasFlagged ) { | 633 | } else if ( wasFlagged ) { |
634 | ++mineguess; | 634 | ++mineguess; |
635 | emit mineCount( mineguess ); | 635 | emit mineCount( mineguess ); |
636 | if ( m->isMined() ) | 636 | if ( m->isMined() ) |
637 | ++minecount; | 637 | ++minecount; |
638 | } | 638 | } |
639 | } | 639 | } |
640 | 640 | ||
641 | updateCell( row, col ); | 641 | updateCell( row, col ); |
642 | 642 | ||
643 | if ( !minecount && !mineguess || !nonminecount ) { | 643 | if ( !minecount && !mineguess || !nonminecount ) { |
644 | emit gameOver( TRUE ); | 644 | emit gameOver( TRUE ); |
645 | setState( GameOver ); | 645 | setState( GameOver ); |
646 | } | 646 | } |
647 | } | 647 | } |
648 | 648 | ||
649 | void MineField::showMines() | 649 | void MineField::showMines() |
650 | { | 650 | { |
651 | for ( int c = 0; c < numCols; c++ ) | 651 | for ( int c = 0; c < numCols; c++ ) |
652 | for ( int r = 0; r < numRows; r++ ) { | 652 | for ( int r = 0; r < numRows; r++ ) { |
653 | Mine* m = mine( r, c ); | 653 | Mine* m = mine( r, c ); |
654 | if ( !m ) | 654 | if ( !m ) |
655 | continue; | 655 | continue; |
656 | if ( m->isMined() && m->state() == Mine::Hidden ) | 656 | if ( m->isMined() && m->state() == Mine::Hidden ) |
657 | m->setState( Mine::Mined ); | 657 | m->setState( Mine::Mined ); |
658 | if ( !m->isMined() && m->state() == Mine::Flagged ) | 658 | if ( !m->isMined() && m->state() == Mine::Flagged ) |
659 | m->setState( Mine::Wrong ); | 659 | m->setState( Mine::Wrong ); |
660 | 660 | ||
661 | updateCell( r, c ); | 661 | updateCell( r, c ); |
662 | } | 662 | } |
663 | } | 663 | } |
664 | 664 | ||
665 | void MineField::paletteChange( const QPalette &o ) | 665 | void MineField::paletteChange( const QPalette &o ) |
666 | { | 666 | { |
667 | Mine::paletteChange(); | 667 | Mine::paletteChange(); |
668 | QScrollView::paletteChange( o ); | 668 | QScrollView::paletteChange( o ); |
669 | } | 669 | } |
670 | 670 | ||
671 | void MineField::writeConfig(Config& cfg) const | 671 | void MineField::writeConfig(Config& cfg) const |
672 | { | 672 | { |
673 | cfg.setGroup("Field"); | 673 | cfg.setGroup("Field"); |
674 | cfg.writeEntry("Level",lev); | 674 | cfg.writeEntry("Level",lev); |
675 | QString grid=""; | 675 | QString grid=""; |
676 | if ( stat == Playing ) { | 676 | if ( stat == Playing ) { |
677 | for ( int x = 0; x < numCols; x++ ) | 677 | for ( int x = 0; x < numCols; x++ ) |
678 | for ( int y = 0; y < numRows; y++ ) { | 678 | for ( int y = 0; y < numRows; y++ ) { |
679 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat | 679 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat |
680 | const Mine* m = mine( y, x ); | 680 | const Mine* m = mine( y, x ); |
681 | int st = (int)m->state(); if ( m->isMined() ) st+=5; | 681 | int st = (int)m->state(); if ( m->isMined() ) st+=5; |
682 | grid += code + st; | 682 | grid += code + st; |
683 | } | 683 | } |
684 | } | 684 | } |
685 | cfg.writeEntry("Grid",grid); | 685 | cfg.writeEntry("Grid",grid); |
686 | } | 686 | } |
687 | 687 | ||
688 | void MineField::readConfig(Config& cfg) | 688 | void MineField::readConfig(Config& cfg) |
689 | { | 689 | { |
690 | cfg.setGroup("Field"); | 690 | cfg.setGroup("Field"); |
691 | lev = cfg.readNumEntry("Level",1); | 691 | lev = cfg.readNumEntry("Level",1); |
692 | setup(lev); | 692 | setup(lev); |
693 | flagAction = NoAction; | 693 | flagAction = NoAction; |
694 | ignoreClick = FALSE; | 694 | ignoreClick = FALSE; |
695 | currRow = currCol = 0; | 695 | currRow = currCol = 0; |
696 | QString grid = cfg.readEntry("Grid"); | 696 | QString grid = cfg.readEntry("Grid"); |
697 | int x; | 697 | int x; |
698 | if ( !grid.isEmpty() ) { | 698 | if ( !grid.isEmpty() ) { |
699 | int i=0; | 699 | int i=0; |
700 | minecount=0; | 700 | minecount=0; |
701 | mineguess=0; | 701 | mineguess=0; |
702 | for ( x = 0; x < numCols; x++ ) { | 702 | for ( x = 0; x < numCols; x++ ) { |
703 | for ( int y = 0; y < numRows; y++ ) { | 703 | for ( int y = 0; y < numRows; y++ ) { |
704 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat | 704 | char code='A'+(x*17+y*101)%21; // Reduce the urge to cheat |
705 | int st = (char)(QChar)grid[i++]-code; | 705 | int st = (char)(QChar)grid[i++]-code; |
706 | Mine* m = mine( y, x ); | 706 | Mine* m = mine( y, x ); |
707 | if (!m) | ||
708 | continue; | ||
707 | if ( st >= 5 ) { | 709 | if ( st >= 5 ) { |
708 | st-=5; | 710 | st-=5; |
709 | m->setMined(TRUE); | 711 | m->setMined(TRUE); |
710 | minecount++; | 712 | minecount++; |
711 | mineguess++; | 713 | mineguess++; |
712 | } | 714 | } |
713 | m->setState((Mine::MineState)st); | 715 | m->setState((Mine::MineState)st); |
714 | switch ( m->state() ) { | 716 | switch ( m->state() ) { |
715 | case Mine::Flagged: | 717 | case Mine::Flagged: |
716 | if (m->isMined()) | 718 | if (m->isMined()) |
717 | minecount--; | 719 | minecount--; |
718 | mineguess--; | 720 | mineguess--; |
719 | break; | 721 | break; |
720 | case Mine::Empty: | 722 | case Mine::Empty: |
721 | --nonminecount; | 723 | --nonminecount; |
722 | break; | 724 | break; |
723 | default: | 725 | default: |
724 | break; | 726 | break; |
725 | } | 727 | } |
726 | } | 728 | } |
727 | } | 729 | } |
728 | for ( x = 0; x < numCols; x++ ) { | 730 | for ( x = 0; x < numCols; x++ ) { |
729 | for ( int y = 0; y < numRows; y++ ) { | 731 | for ( int y = 0; y < numRows; y++ ) { |
730 | Mine* m = mine( y, x ); | 732 | Mine* m = mine( y, x ); |
731 | if ( m->state() == Mine::Empty ) | 733 | if ( m && m->state() == Mine::Empty ) |
732 | m->setHint(getHint(y,x)); | 734 | m->setHint(getHint(y,x)); |
733 | } | 735 | } |
734 | } | 736 | } |
735 | } | 737 | } |
736 | setState( Playing ); | 738 | setState( Playing ); |
737 | emit mineCount( mineguess ); | 739 | emit mineCount( mineguess ); |
738 | } | 740 | } |
739 | 741 | ||
740 | QSize MineField::sizeHint() const | 742 | QSize MineField::sizeHint() const |
741 | { | 743 | { |
742 | if ( qApp->desktop()->width() >= 240 ) | 744 | if ( qApp->desktop()->width() >= 240 ) |
743 | return QSize(200,200); | 745 | return QSize(200,200); |
744 | else | 746 | else |
745 | return QSize(160, 160); | 747 | return QSize(160, 160); |
746 | } | 748 | } |
747 | 749 | ||