From 7071dfc1d1e468a0700ecff0661abeacbfb980ac Mon Sep 17 00:00:00 2001 From: Stefano Ceccherini Date: Mon, 19 Jul 2010 06:17:52 +0000 Subject: [PATCH] Style. Add NULL guard to the color schemes struct, although the code was safe neverthless (for now) git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@37575 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- src/apps/terminal/AppearPrefView.cpp | 35 +++++++++++++++------------- src/apps/terminal/Colors.cpp | 5 ++-- src/apps/terminal/Colors.h | 6 ++--- 3 files changed, 25 insertions(+), 21 deletions(-) diff --git a/src/apps/terminal/AppearPrefView.cpp b/src/apps/terminal/AppearPrefView.cpp index d5ce4eafca..0c6f35e6b5 100644 --- a/src/apps/terminal/AppearPrefView.cpp +++ b/src/apps/terminal/AppearPrefView.cpp @@ -95,12 +95,12 @@ AppearancePrefView::AppearancePrefView(const char* name, fFont = new BMenuField(B_TRANSLATE("Font:"), fontMenu); fFontSize = new BMenuField(B_TRANSLATE("Size:"), sizeMenu); - BPopUpMenu *schemasPopUp =_MakeColorSchemaMenu(MSG_COLOR_SCHEMA_CHANGED, gPredefinedSchemas, + BPopUpMenu* schemasPopUp =_MakeColorSchemaMenu(MSG_COLOR_SCHEMA_CHANGED, gPredefinedSchemas, gPredefinedSchemas[0]); fColorSchemaField = new BMenuField(B_TRANSLATE("Color schema:"), schemasPopUp); - BPopUpMenu *colorsPopUp =_MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable, + BPopUpMenu* colorsPopUp =_MakeMenu(MSG_COLOR_FIELD_CHANGED, kColorTable, kColorTable[0]); fColorField = new BMenuField(B_TRANSLATE("Color:"), @@ -242,14 +242,17 @@ AppearancePrefView::MessageReceived(BMessage* msg) case MSG_COLOR_SCHEMA_CHANGED: { - color_schema *newSchema = NULL; - msg->FindPointer("color_schema", (void**)&newSchema); - if (newSchema == &gCustomSchema) - _EnableCustomColors(true); - else - _EnableCustomColors(false); - _ChangeColorSchema(newSchema); - modified = true; + color_schema* newSchema = NULL; + if (msg->FindPointer("color_schema", + (void**)&newSchema) == B_OK) { + + if (newSchema == &gCustomSchema) + _EnableCustomColors(true); + else + _EnableCustomColors(false); + _ChangeColorSchema(newSchema); + modified = true; + } break; } @@ -283,7 +286,7 @@ AppearancePrefView::_EnableCustomColors(bool enable) void AppearancePrefView::_ChangeColorSchema(color_schema* schema) { - PrefHandler *pref = PrefHandler::Default(); + PrefHandler* pref = PrefHandler::Default(); pref->setRGB(PREF_TEXT_FORE_COLOR, schema->text_fore_color); pref->setRGB(PREF_TEXT_BACK_COLOR, schema->text_back_color); @@ -295,9 +298,9 @@ AppearancePrefView::_ChangeColorSchema(color_schema* schema) void -AppearancePrefView::_SetCurrentColorSchema(BMenuField *field) +AppearancePrefView::_SetCurrentColorSchema(BMenuField* field) { - PrefHandler *pref = PrefHandler::Default(); + PrefHandler* pref = PrefHandler::Default(); gCustomSchema.text_fore_color = pref->getRGB(PREF_TEXT_FORE_COLOR); gCustomSchema.text_back_color = pref->getRGB(PREF_TEXT_BACK_COLOR); @@ -306,9 +309,9 @@ AppearancePrefView::_SetCurrentColorSchema(BMenuField *field) gCustomSchema.select_fore_color = pref->getRGB(PREF_SELECT_FORE_COLOR); gCustomSchema.select_back_color = pref->getRGB(PREF_SELECT_BACK_COLOR); - const char *currentSchemaName = NULL; + const char* currentSchemaName = NULL; - color_schema **schemas = const_cast(gPredefinedSchemas); + color_schema** schemas = const_cast(gPredefinedSchemas); while (*schemas) { if (gCustomSchema == **schemas) { currentSchemaName = (*schemas)->name; @@ -319,7 +322,7 @@ AppearancePrefView::_SetCurrentColorSchema(BMenuField *field) bool found = false; for (int32 i = 0; i < fColorSchemaField->Menu()->CountItems(); i++) { - BMenuItem *item = fColorSchemaField->Menu()->ItemAt(i); + BMenuItem* item = fColorSchemaField->Menu()->ItemAt(i); if (!strcmp(item->Label(), currentSchemaName)) { item->SetMarked(true); found = true; diff --git a/src/apps/terminal/Colors.cpp b/src/apps/terminal/Colors.cpp index 6669fcec42..512e199804 100644 --- a/src/apps/terminal/Colors.cpp +++ b/src/apps/terminal/Colors.cpp @@ -34,15 +34,16 @@ struct color_schema gCustomSchema = { "Custom" }; -const color_schema *gPredefinedSchemas[] = { +const color_schema* gPredefinedSchemas[] = { &kBlackOnWhite, &kWhiteOnBlack, &gCustomSchema, + NULL }; bool -color_schema::operator==(const color_schema &schema) +color_schema::operator==(const color_schema& schema) { if (text_fore_color == schema.text_fore_color && text_back_color == schema.text_back_color diff --git a/src/apps/terminal/Colors.h b/src/apps/terminal/Colors.h index f21a4ccc97..bdd87b8c18 100644 --- a/src/apps/terminal/Colors.h +++ b/src/apps/terminal/Colors.h @@ -8,14 +8,14 @@ #include struct color_schema { - const char *name; + const char* name; rgb_color text_fore_color; rgb_color text_back_color; rgb_color cursor_fore_color; rgb_color cursor_back_color; rgb_color select_fore_color; rgb_color select_back_color; - bool operator==(const color_schema &color); + bool operator==(const color_schema& color); }; @@ -23,7 +23,7 @@ extern const rgb_color kBlack; extern const rgb_color kWhite; extern color_schema gCustomSchema; -extern const color_schema *gPredefinedSchemas[]; +extern const color_schema* gPredefinedSchemas[]; #endif // _COLORS_H