From 0a083f438538c579eb696352feefed04b09c1900 Mon Sep 17 00:00:00 2001 From: "jean.chalard" Date: Mon, 25 Jan 2010 09:58:30 +0000 Subject: [PATCH] J : * Fixes for compilation on 64-bit architectures : string position-returning functions return size_t, not uint. Fix that. * Fixes warnings with new gcc about non-fixed string AND no arguments. NOTE : 64-bit architectures still do not compile. There are 2 different places where printf is used with a specifier that is not large enough on 64-bit because size_t is now a ulong and not a uint. The solution on GNU systems is the %zu specifier, but as I'm not sure it is supported on windows I don't want to introduce a huge hard-to-notice bug, so I'll do it at a time when I got a windowser to back me up. --- projects/mtg/include/AllAbilities.h | 12 ++++++------ projects/mtg/src/AIPlayer.cpp | 6 +++--- projects/mtg/src/ActionStack.cpp | 8 ++++---- projects/mtg/src/CardGui.cpp | 2 +- projects/mtg/src/Credits.cpp | 4 ++-- projects/mtg/src/ExtraCost.cpp | 2 +- projects/mtg/src/MTGAbility.cpp | 24 ++++++++++++------------ projects/mtg/src/MTGDeck.cpp | 12 ++++++------ projects/mtg/src/ManaCost.cpp | 6 +++--- projects/mtg/src/OptionItem.cpp | 9 ++++----- projects/mtg/src/ShopItem.cpp | 2 +- projects/mtg/src/TargetChooser.cpp | 6 +++--- projects/mtg/src/TestSuiteAI.cpp | 4 ++-- 13 files changed, 48 insertions(+), 49 deletions(-) diff --git a/projects/mtg/include/AllAbilities.h b/projects/mtg/include/AllAbilities.h index f38182a3b..56007be9a 100644 --- a/projects/mtg/include/AllAbilities.h +++ b/projects/mtg/include/AllAbilities.h @@ -649,14 +649,14 @@ public: //TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class; for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){ - unsigned int found = sabilities.find(Constants::MTGBasicAbilities[j]); + size_t found = sabilities.find(Constants::MTGBasicAbilities[j]); if (found != string::npos){ abilities.push_back(j); } } for (int j = 0; j < Constants::MTG_NB_COLORS; j++){ - unsigned int found = sabilities.find(Constants::MTGColorStrings[j]); + size_t found = sabilities.find(Constants::MTGColorStrings[j]); if (found != string::npos){ colors.push_back(j); } @@ -664,7 +664,7 @@ public: string s = stypes; while (s.size()){ - unsigned int found = s.find(" "); + size_t found = s.find(" "); if (found != string::npos){ int id = Subtypes::subtypesList->find(s.substr(0,found)); types.push_back(id); @@ -2154,14 +2154,14 @@ public: //TODO this is a copy/past of other code that's all around the place, everything should be in a dedicated parser class; for (int j = 0; j < Constants::NB_BASIC_ABILITIES; j++){ - unsigned int found = sabilities.find(Constants::MTGBasicAbilities[j]); + size_t found = sabilities.find(Constants::MTGBasicAbilities[j]); if (found != string::npos){ abilities.push_back(j); } } for (int j = 0; j < Constants::MTG_NB_COLORS; j++){ - unsigned int found = sabilities.find(Constants::MTGColorStrings[j]); + size_t found = sabilities.find(Constants::MTGColorStrings[j]); if (found != string::npos){ colors.push_back(j); } @@ -2169,7 +2169,7 @@ public: string s = stypes; while (s.size()){ - unsigned int found = s.find(" "); + size_t found = s.find(" "); if (found != string::npos){ int id = Subtypes::subtypesList->find(s.substr(0,found)); types.push_back(id); diff --git a/projects/mtg/src/AIPlayer.cpp b/projects/mtg/src/AIPlayer.cpp index 335056b47..b1c885ba9 100644 --- a/projects/mtg/src/AIPlayer.cpp +++ b/projects/mtg/src/AIPlayer.cpp @@ -565,10 +565,10 @@ AIPlayer * AIPlayerFactory::createAIPlayer(MTGAllCards * collection, Player * op char deckFileSmall[512]; if (deckid == -1){ //Evil twin - sprintf(deckFile, opponent->deckFile.c_str()); + sprintf(deckFile, "%s", opponent->deckFile.c_str()); OutputDebugString(opponent->deckFile.c_str()); - sprintf(avatarFile, "baka.jpg"); - sprintf(deckFileSmall, "ai_baka_eviltwin"); + sprintf(avatarFile, "%s", "baka.jpg"); + sprintf(deckFileSmall, "%s", "ai_baka_eviltwin"); }else{ if (!deckid){ int nbdecks = 0; diff --git a/projects/mtg/src/ActionStack.cpp b/projects/mtg/src/ActionStack.cpp index 2c77ddcd6..ada369ce4 100644 --- a/projects/mtg/src/ActionStack.cpp +++ b/projects/mtg/src/ActionStack.cpp @@ -771,17 +771,17 @@ void ActionStack::Render(){ // seconds if the user disables auto progressing interrupts by setting the seconds // value to zero in Options. if (options[Options::INTERRUPT_SECONDS].number == 0) - sprintf(buffer, _("Interrupt?").c_str()); + sprintf(buffer, "%s", _("Interrupt?").c_str()); else - sprintf(buffer, "%s %i", _("Interrupt?").c_str(),static_cast(timer)); + sprintf(buffer, "%s %i", _("Interrupt?").c_str(),static_cast(timer)); //WALDORF - removed all the unnecessary math. just display the prompt at the // top of the box. mFont->DrawString(buffer, x0 + 5, y0); - if (mCount > 1) sprintf(buffer, _("X Interrupt - 0 No - [] No to All").c_str()); - else sprintf(buffer, _("X Interrupt - 0 No").c_str()); + if (mCount > 1) sprintf(buffer, "%s", _("X Interrupt - 0 No - [] No to All").c_str()); + else sprintf(buffer, "%s", _("X Interrupt - 0 No").c_str()); // WALDORF - puts the button legend right under the prompt. the stack // will be displayed below it now. no more need to do wierd currY math. diff --git a/projects/mtg/src/CardGui.cpp b/projects/mtg/src/CardGui.cpp index cbfbeea5b..fcccc3784 100644 --- a/projects/mtg/src/CardGui.cpp +++ b/projects/mtg/src/CardGui.cpp @@ -185,7 +185,7 @@ void CardGui::alternateRender(MTGCard * card, const Pos& pos){ { char name[4096]; - sprintf(name, _(card->data->getName()).c_str()); + sprintf(name, "%s", _(card->data->getName()).c_str()); float w = font->GetStringWidth(name) * 0.8 * pos.actZ; if (w > BigWidth - 30) font->SetScale((BigWidth - 30) / w); diff --git a/projects/mtg/src/Credits.cpp b/projects/mtg/src/Credits.cpp index ffe30b825..91f86cb2e 100644 --- a/projects/mtg/src/Credits.cpp +++ b/projects/mtg/src/Credits.cpp @@ -179,7 +179,7 @@ void Credits::Render(){ f3->SetColor(ARGB(255,255,255,255)); char buffer[512]; if (!g->turn){ - sprintf(buffer, _("Please check your deck (not enough cards?)").c_str() ); + sprintf(buffer, "%s", _("Please check your deck (not enough cards?)").c_str() ); }else{ if (!p1->isAI() && p2->isAI() ){ if (g->gameOver != p1){ @@ -192,7 +192,7 @@ void Credits::Render(){ f2->DrawString(unlockedString.c_str(),SCREEN_WIDTH/2, 80,JGETEXT_CENTER); } }else{ - sprintf (buffer, _("You have been defeated").c_str()); + sprintf (buffer, "%s", _("You have been defeated").c_str()); } }else{ int winner = 2; diff --git a/projects/mtg/src/ExtraCost.cpp b/projects/mtg/src/ExtraCost.cpp index 31322cf06..fcbe0f5e7 100644 --- a/projects/mtg/src/ExtraCost.cpp +++ b/projects/mtg/src/ExtraCost.cpp @@ -71,7 +71,7 @@ void SacrificeCost::Render(){ mFont->SetScale(DEFAULT_MAIN_FONT_SCALE); mFont->SetColor(ARGB(255,255,255,255)); char buffer[200]; - sprintf(buffer, _("sacrifice").c_str()); + sprintf(buffer, "%s", _("sacrifice").c_str()); mFont->DrawString(buffer, 20 ,20, JGETEXT_LEFT); } diff --git a/projects/mtg/src/MTGAbility.cpp b/projects/mtg/src/MTGAbility.cpp index 637c19ec6..9df8de843 100644 --- a/projects/mtg/src/MTGAbility.cpp +++ b/projects/mtg/src/MTGAbility.cpp @@ -273,7 +273,7 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG } int limit = 0; - unsigned int limit_str = sWithoutTc.find("limit:"); + size_t limit_str = sWithoutTc.find("limit:"); if (limit_str != string::npos){ limit = atoi(sWithoutTc.substr(limit_str+6).c_str()); } @@ -577,9 +577,9 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //Damage found = s.find("damage"); if (found != string::npos){ - unsigned int start = s.find(":",found); + size_t start = s.find(":",found); if (start == string::npos) start = s.find(" ",found); - unsigned int end = s.find(" ",start); + size_t end = s.find(" ",start); string d; if (end != string::npos){ d = s.substr(start+1,end-start-1); @@ -598,8 +598,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //gain/lose life found = s.find("life:"); if (found != string::npos){ - unsigned int start = found+4; - unsigned int end = s.find(" ",start); + size_t start = found+4; + size_t end = s.find(" ",start); string life_s; if (end != string::npos){ life_s = s.substr(start+1,end-start-1); @@ -617,8 +617,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //Draw found = s.find("draw:"); if (found != string::npos){ - unsigned int start = s.find(":",found); - unsigned int end = s.find(" ",start); + size_t start = s.find(":",found); + size_t end = s.find(" ",start); string nbcardsStr; if (end != string::npos){ nbcardsStr = s.substr(start+1,end-start-1); @@ -636,8 +636,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //Deplete found = s.find("deplete:"); if (found != string::npos){ - unsigned int start = s.find(":",found); - unsigned int end = s.find(" ",start); + size_t start = s.find(":",found); + size_t end = s.find(" ",start); int nbcards; if (end != string::npos){ nbcards = atoi(s.substr(start+1,end-start-1).c_str()); @@ -665,8 +665,8 @@ MTGAbility * AbilityFactory::parseMagicLine(string s, int id, Spell * spell, MTG //Discard found = s.find("discard:"); if (found != string::npos){ - unsigned int start = s.find(":",found); - unsigned int end = s.find(" ",start); + size_t start = s.find(":",found); + size_t end = s.find(" ",start); int nbcards; if (end != string::npos){ nbcards = atoi(s.substr(start+1,end-start-1).c_str()); @@ -971,7 +971,7 @@ int AbilityFactory::getAbilities(vector * v, Spell * spell, MTGCar string line; int size = magicText.size(); if (size == 0) return 0; - unsigned int found; + size_t found; int result = id; while (magicText.size()){ diff --git a/projects/mtg/src/MTGDeck.cpp b/projects/mtg/src/MTGDeck.cpp index f5346987a..9fc186739 100644 --- a/projects/mtg/src/MTGDeck.cpp +++ b/projects/mtg/src/MTGDeck.cpp @@ -17,7 +17,7 @@ using std::string; //MTGAllCards int MTGAllCards::processConfLine(string s, MTGCard *card, CardPrimitive * primitive){ if (s.size() && s[0] == '#') return 0; - unsigned int i = s.find_first_of("="); + size_t i = s.find_first_of("="); if (i == string::npos){ #if defined (_DEBUG) char buffer[4096]; @@ -114,7 +114,7 @@ int MTGAllCards::processConfLine(string s, MTGCard *card, CardPrimitive * primit case 's': //subtype if(!primitive) primitive = NEW CardPrimitive(); while (value.size()){ - unsigned int found = value.find(" "); + size_t found = value.find(" "); if (found != string::npos){ primitive->setSubtype(value.substr(0,found)); value = value.substr(found+1); @@ -136,7 +136,7 @@ int MTGAllCards::processConfLine(string s, MTGCard *card, CardPrimitive * primit }else if (key.compare("type")==0) { if(!primitive) primitive = NEW CardPrimitive(); while (value.size()){ - unsigned int found = value.find(" "); + size_t found = value.find(" "); if (found != string::npos){ primitive->setType(value.substr(0,found).c_str()); value = value.substr(found+1); @@ -514,7 +514,7 @@ int MTGDeck::addRandomCards(int howmany, int * setIds, int nbSets, int rarity, c char subtype[4096]; if (_subtype) - sprintf(subtype, _subtype); + sprintf(subtype, "%s", _subtype); vector subcollection; @@ -832,7 +832,7 @@ string MTGSetInfo::getBlock(){ void MTGSetInfo::processConfLine(string line){ - unsigned int i = line.find_first_of("="); + size_t i = line.find_first_of("="); if (i == string::npos) return; @@ -848,4 +848,4 @@ void MTGSetInfo::processConfLine(string line){ block = setlist.findBlock(value.c_str()); else if(key.compare("year") == 0) year = atoi(value.c_str()); - } \ No newline at end of file + } diff --git a/projects/mtg/src/ManaCost.cpp b/projects/mtg/src/ManaCost.cpp index 79728f176..0c53c569e 100644 --- a/projects/mtg/src/ManaCost.cpp +++ b/projects/mtg/src/ManaCost.cpp @@ -20,8 +20,8 @@ ManaCost * ManaCost::parseManaCost(string s, ManaCost * _manaCost, MTGCardInstan manaCost = NEW ManaCost(); } int state = 0; - unsigned int start = 0; - unsigned int end = 0; + size_t start = 0; + size_t end = 0; while (!s.empty() && state != -1){ switch(state){ case 0: @@ -464,4 +464,4 @@ int ManaPool::pay (ManaCost * _cost){ } } return result; -} \ No newline at end of file +} diff --git a/projects/mtg/src/OptionItem.cpp b/projects/mtg/src/OptionItem.cpp index 3c9832f44..927d264a7 100644 --- a/projects/mtg/src/OptionItem.cpp +++ b/projects/mtg/src/OptionItem.cpp @@ -87,11 +87,10 @@ void OptionInteger::Render(){ mFont->DrawString(_(displayValue).c_str(),x,y); char buf[512]; if (maxValue == 1){ - if (value){ - sprintf(buf, _("Yes").c_str()); - }else{ - sprintf(buf,_("No").c_str()); - } + if (value) + sprintf(buf, "%s", _("Yes").c_str()); + else + sprintf(buf, "%s", _("No").c_str()); }else{ if(value == defValue && strDefault.size()) sprintf(buf, "%s", _(strDefault).c_str()); diff --git a/projects/mtg/src/ShopItem.cpp b/projects/mtg/src/ShopItem.cpp index d33d10876..a8b3e389b 100644 --- a/projects/mtg/src/ShopItem.cpp +++ b/projects/mtg/src/ShopItem.cpp @@ -330,7 +330,7 @@ void ShopItems::Render(){ mFont->SetColor(ARGB(255,255,255,255)); char c[4096]; r->FillRect(0,SCREEN_HEIGHT-17,SCREEN_WIDTH,17,ARGB(128,0,0,0)); - sprintf(c, _("[]:other cards").c_str()); + sprintf(c, "%s", _("[]:other cards").c_str()); unsigned int len = 4 + mFont->GetStringWidth(c); mFont->DrawString(c,SCREEN_WIDTH-len,SCREEN_HEIGHT-14); diff --git a/projects/mtg/src/TargetChooser.cpp b/projects/mtg/src/TargetChooser.cpp index 8d00fa890..0259c5f3e 100644 --- a/projects/mtg/src/TargetChooser.cpp +++ b/projects/mtg/src/TargetChooser.cpp @@ -31,7 +31,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta found = s.find("player"); if (found != string::npos){ int maxtargets = 1; - unsigned int several = s.find_first_of('s',5); + size_t several = s.find_first_of('s',5); if (several != string::npos) maxtargets = -1; found = s.find("creature"); if (found != string::npos) return NEW DamageableTargetChooser(card,maxtargets,other); //Any Damageable target (player, creature) @@ -106,7 +106,7 @@ TargetChooser * TargetChooserFactory::createTargetChooser(string s, MTGCardInsta string attributes = typeName.substr(found+1,end-found-1); cd = NEW CardDescriptor(); while(attributes.size()){ - unsigned int found2 = attributes.find(";"); + size_t found2 = attributes.find(";"); string attribute; if (found2 != string::npos){ cd->mode = CD_OR; @@ -736,4 +736,4 @@ bool DamageTargetChooser::canTarget(Targetable * target){ DamageTargetChooser* DamageTargetChooser::clone() const{ DamageTargetChooser * a = NEW DamageTargetChooser(*this); return a; - } \ No newline at end of file + } diff --git a/projects/mtg/src/TestSuiteAI.cpp b/projects/mtg/src/TestSuiteAI.cpp index 3c5b3e6c2..6f7684753 100644 --- a/projects/mtg/src/TestSuiteAI.cpp +++ b/projects/mtg/src/TestSuiteAI.cpp @@ -123,7 +123,7 @@ int TestSuiteAI::Act(float dt){ g->mLayers->actionLayer()->stuffHappened = 1; }else if(action.find("p1")!=string::npos || action.find("p2")!=string::npos){ Player * p = g->players[1]; - unsigned int start = action.find("p1"); + size_t start = action.find("p1"); if (start != string::npos) p = g->players[0]; g->cardClick(NULL, p); }else{ @@ -186,7 +186,7 @@ TestSuiteState::TestSuiteState(){ } void TestSuiteState::parsePlayerState(int playerId, string s){ - unsigned int limiter = s.find(":"); + size_t limiter = s.find(":"); string areaS; int area; if (limiter != string::npos){