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/minefield.cpp | |
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.
Diffstat (limited to 'noncore/games/minesweep/minefield.cpp') (more/less context) (show whitespace changes)
-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 | |||
@@ -659,89 +659,91 @@ void MineField::showMines() | |||
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 | ||