]> git.mxchange.org Git - quix0rs-blobwars.git/commitdiff
Use strlcat() and strlcpy(), #define wrappers when these functions are not available.
authorGuus Sliepen <guus@debian.org>
Tue, 27 Jul 2010 16:06:27 +0000 (18:06 +0200)
committerGuus Sliepen <guus@debian.org>
Tue, 27 Jul 2010 16:06:27 +0000 (18:06 +0200)
41 files changed:
src/CAudio.cpp
src/CCutscene.cpp
src/CData.cpp
src/CEngine.cpp
src/CEntity.cpp
src/CFileData.cpp
src/CGame.cpp
src/CGameData.cpp
src/CGraphics.cpp
src/CHub.cpp
src/CKeyboard.cpp
src/CLineDef.cpp
src/CMap.cpp
src/CMedalServer.cpp
src/CObjective.cpp
src/CPak.cpp
src/CPersistData.cpp
src/CPersistant.cpp
src/CSpawnPoint.cpp
src/CSwitch.cpp
src/CTeleporter.cpp
src/CTrain.cpp
src/CTrap.cpp
src/CWeapon.cpp
src/CWidget.cpp
src/aquaBoss.cpp
src/cutscene.cpp
src/droidBoss.cpp
src/finalBattle.cpp
src/galdov.cpp
src/game.cpp
src/headers.h
src/hub.cpp
src/loadSave.cpp
src/main.cpp
src/mapEditor.cpp
src/mias.cpp
src/player.cpp
src/switches.cpp
src/tankBoss.cpp
src/title.cpp

index 521c18ba750ea5a34fd1d864ebbea56a05a08b5a..c2a37124f92acab453b18459828b20417a28c02b 100644 (file)
@@ -149,11 +149,11 @@ bool Audio::loadMusic(const char *filename)
                        line[l - 1] = 0;
 
                if(!strncasecmp(line, "title=", 6))
-                        strncpy(songtitle, line + 6, sizeof songtitle);
+                        strlcpy(songtitle, line + 6, sizeof songtitle);
                else if(!strncasecmp(line, "album=", 6))
-                        strncpy(songalbum, line + 6, sizeof songalbum);
+                        strlcpy(songalbum, line + 6, sizeof songalbum);
                else if(!strncasecmp(line, "artist=", 7))
-                        strncpy(songartist, line + 7, sizeof songartist);
+                        strlcpy(songartist, line + 7, sizeof songartist);
                else if(!strncasecmp(line, "license=", 8))
                {
                        if(!strncasecmp(line + 8, "CC-BY ", 6))
@@ -166,7 +166,7 @@ bool Audio::loadMusic(const char *filename)
        if(fp)
                fclose(fp);
        
-       strncpy(levelMusicName, filename, sizeof levelMusicName);
+       strlcpy(levelMusicName, filename, sizeof levelMusicName);
 
        return true;
 }
index 9da816f9166a603939259248d9860eac51c8d939..bf3d537401af7796382bc9d168b8b4f1ae88ee4d 100644 (file)
@@ -29,6 +29,6 @@ Cutscene::Cutscene()
 
 void Cutscene::appendText(const char *line)
 {
-       strncat(text, " ", sizeof text);
-       strncat(text, line, sizeof text);
+       strlcat(text, " ", sizeof text);
+       strlcat(text, line, sizeof text);
 }
index 12642eddc75fab3be6a6d99249c56c7b2b701156..e0823944af448c356004fc2a8c9996807e662261 100644 (file)
@@ -36,8 +36,8 @@ void Data::set(const char *key, const char *value, int current, int target)
                return;
        }
 
-       strncpy(this->key, key, sizeof this->key);
-       strncpy(this->value, value, sizeof this->value);
+       strlcpy(this->key, key, sizeof this->key);
+       strlcpy(this->value, value, sizeof this->value);
        this->current = current;
        this->target = target;
 }
index 2520ba1d58cdae2c415acca4ac58e67379c232d6..02175277e4df59843a4fd77b278d0aaa7364cd19 100644 (file)
@@ -64,7 +64,7 @@ Engine::Engine()
        binaryBuffer = NULL;
        #ifdef FRAMEWORK_SDL
        char pakPath[PATH_MAX];
-       strncpy(pakPath, PAKFULLPATH, sizeof(pakPath));
+       strlcpy(pakPath, PAKFULLPATH, sizeof(pakPath));
        if (CFBundleGetMainBundle() != NULL) {
                CFURLRef pakURL = CFBundleCopyResourceURL(CFBundleGetMainBundle(), CFSTR(PAKNAME), NULL, NULL);
                if (pakURL != NULL) {
@@ -229,7 +229,7 @@ void Engine::getInput()
                                }
 
                                keyState[event.key.keysym.sym] = 1;
-                               strncpy(lastKeyPressed, SDL_GetKeyName(event.key.keysym.sym), sizeof lastKeyPressed);
+                               strlcpy(lastKeyPressed, SDL_GetKeyName(event.key.keysym.sym), sizeof lastKeyPressed);
                                addKeyEvent();
                                break;
 
@@ -314,7 +314,7 @@ void Engine::clearInput()
 
 void Engine::setUserHome(const char *path)
 {
-       strncpy(userHomeDirectory, path, sizeof userHomeDirectory);
+       strlcpy(userHomeDirectory, path, sizeof userHomeDirectory);
        debug(("User Home = %s\n", path));
 }
 
@@ -489,7 +489,7 @@ void Engine::setInfoMessage(const char *message, int priority, int type)
 {
        if (priority >= messagePriority)
        {
-               strncpy(this->message, message, sizeof this->message);
+               strlcpy(this->message, message, sizeof this->message);
                messageTime = 180;
                messagePriority = priority;
                messageType = type;
@@ -957,7 +957,7 @@ int Engine::getValueOfFlagTokens(const char *realLine)
        char line[1024];
        bool found;
        int value;
-       strncpy(line, realLine, sizeof line);
+       strlcpy(line, realLine, sizeof line);
 
        int flags = 0;
 
index e1575ca62069b0a9e6cca8889ede6bbe870e5042..9fcf6a88e94d04f9065c2980acef3b27dfd73c8b 100644 (file)
@@ -52,7 +52,7 @@ Entity::Entity()
 
 void Entity::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
 }
 
 void Entity::setSprites(Sprite *sprite1, Sprite *sprite2, Sprite *sprite3)
index f3ebe92891340aefa9655200d6f14b0d0fe01d53..52643f0473071d0b7efa6ae781adb9dd2fcda96f 100644 (file)
@@ -36,7 +36,7 @@ void FileData::set(const char *filename, Uint32 fSize, Uint32 cSize, Uint32 loca
                return;
        }
        
-       strncpy(this->filename, filename, sizeof this->filename);
+       strlcpy(this->filename, filename, sizeof this->filename);
        
        this->fSize = fSize;
        this->cSize = cSize;
index a5fa060eb739dcc54bac2e2d7b04446c942f9021..b75820da037c620dd94def504354d7da7e99679e 100644 (file)
@@ -66,8 +66,8 @@ void Game::clear()
                bulletsHit[i] = bulletsFired[i] = 0;
        }
 
-       strncpy(mapName, "data/grasslands1", sizeof mapName);
-       strncpy(stageName, "Grasslands", sizeof stageName);
+       strlcpy(mapName, "data/grasslands1", sizeof mapName);
+       strlcpy(stageName, "Grasslands", sizeof stageName);
 
        continuesUsed = 0;
        levelsStarted = 0;
@@ -221,12 +221,12 @@ void Game::totalUpStats()
 
 void Game::setStageName(const char *name)
 {
-       strncpy(stageName, name, sizeof stageName);
+       strlcpy(stageName, name, sizeof stageName);
 }
 
 void Game::setMapName(const char *name)
 {
-       strncpy(mapName, name, sizeof mapName);
+       strlcpy(mapName, name, sizeof mapName);
 }
 
 void Game::setMissionOver(int reason)
index a7d17cf6db77aa4852a2f9032b30c0d3be3413f1..36e1112ccdbbedb95e96ec87a8903bac950608ee 100644 (file)
@@ -90,7 +90,7 @@ void GameData::setMIARescueCount(const char *key, int rescues, int total)
                data = (Data*)data->next;
                if (strcmp(newKey, data->key) == 0)
                {
-                       strncpy(data->value, "MIAs", sizeof data->value);
+                       strlcpy(data->value, "MIAs", sizeof data->value);
                        data->current = rescues;
                        data->target = total;
                        return;
index 353a837febd36331bb01bf4c5bd3e319fc8e614b..6dde3df167f10191bccce5397e3f1db6a6d40e1b 100644 (file)
@@ -616,7 +616,7 @@ void Graphics::loadFont(int i, const char *filename, int pixelSize)
 Sprite *Graphics::addSprite(const char *name)
 {
        Sprite *sprite = new Sprite;
-       strncpy(sprite->name, name, sizeof sprite->name);
+       strlcpy(sprite->name, name, sizeof sprite->name);
 
        spriteList.add(sprite);
 
@@ -946,8 +946,8 @@ void Graphics::clearChatString()
 
 void Graphics::createChatString(const char *in)
 {
-       strncat(chatString, " ", sizeof chatString);
-       strncat(chatString, in, sizeof chatString);
+       strlcat(chatString, " ", sizeof chatString);
+       strlcat(chatString, in, sizeof chatString);
 }
 
 void Graphics::drawChatString(SDL_Surface *surface, int y)
index 4c8192eca6748e82023cc5626e5bb907d375753d..ad04651f8476dc8d5c53a8add00cabf3915be0a8 100644 (file)
@@ -33,8 +33,8 @@ HubLevel::HubLevel()
 
 void HubLevel::set(const char *stageName, const char *filename, int x, int y)
 {
-       strncpy(this->stageName, stageName, sizeof this->stageName);
-       strncpy(this->filename, filename, sizeof this->filename);
+       strlcpy(this->stageName, stageName, sizeof this->stageName);
+       strlcpy(this->filename, filename, sizeof this->filename);
        this->x = x;
        this->y = y;
 }
index b9bc5bc9c79b6a28a9f7c74e182f776d2319ef5b..d0f877aeab7fab80a9b87a4d3797b380cfb1d3ad 100644 (file)
@@ -49,7 +49,7 @@ const char *Keyboard::translateKey(int key)
                return "...";
        }
        
-       strncpy(keyName, _(SDL_GetKeyName((SDLKey)key)), sizeof keyName);
+       strlcpy(keyName, _(SDL_GetKeyName((SDLKey)key)), sizeof keyName);
        
        /*
        This is not really neccessary, but it just makes
index 916bdf68a3306c96b74e295b5aa84c1b733b47d9..06865737ccbd6f0217b9c6b586010708a4d8012e 100644 (file)
@@ -33,9 +33,9 @@ LineDef::LineDef()
 
 void LineDef::set(const char *name, const char *linkName, const char *activateMessage, int x, int y, int width, int height)
 {
-       strncpy(this->name, name, sizeof this->name);
-       strncpy(this->linkName, linkName, sizeof this->linkName);
-       strncpy(this->activateMessage, activateMessage, sizeof this->activateMessage);
+       strlcpy(this->name, name, sizeof this->name);
+       strlcpy(this->linkName, linkName, sizeof this->linkName);
+       strlcpy(this->activateMessage, activateMessage, sizeof this->activateMessage);
        this->x = x;
        this->y = y;
        this->width = width;
index 72ce7876f375cd38c7e74e63453825e4d333a40d..007c57b5edf19ae5f118f3f9c38dcbc402cbc984 100644 (file)
@@ -220,7 +220,7 @@ void Map::destroyPersistant(const char *name)
                
                if (strcmp(p->stageName, name) == 0)
                {
-                       strncpy(p->stageName, "@none@", sizeof p->stageName);
+                       strlcpy(p->stageName, "@none@", sizeof p->stageName);
                        p->clear();
                        return;
                }
@@ -229,7 +229,7 @@ void Map::destroyPersistant(const char *name)
 
 void Map::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
        
        if (strstr(name, "BioMech"))
        {
index fc9e9b61996f522e0900a135a2c8c169a8e4e50f..1ec4e79ea8a60cb56e4cd77d98d0e511ca39686f 100644 (file)
@@ -50,7 +50,7 @@ bool MedalServer::connect(const char *privateKey)
        
        debug(("Connected %s to %s:%d\n", privateKey, MEDAL_SERVER_HOST, MEDAL_SERVER_PORT));
        
-       strncpy(this->privateKey, privateKey, sizeof this->privateKey);
+       strlcpy(this->privateKey, privateKey, sizeof this->privateKey);
        connected = true;
        
        return true;
@@ -70,7 +70,7 @@ int MedalServer::postMedal(const char *str)
        char *store;
        
        char medal[128];
-       strncpy(medal, str, sizeof medal);
+       strlcpy(medal, str, sizeof medal);
        
        for (unsigned int i = 0 ; i < strlen(medal) ; i++)
        {
@@ -123,7 +123,7 @@ int MedalServer::postMedal(const char *str)
                        
                        if (response == 4)
                        {
-                               strncpy(rubyMessage, message, sizeof rubyMessage);
+                               strlcpy(rubyMessage, message, sizeof rubyMessage);
                                gotRuby = true;
                        }
                        else
index 9bf75f310b79d4e12a3f180f6b0c8e4b304e3f51..aa5c6fb78f72a4e477c33419bc4f6675b57efca0 100644 (file)
@@ -34,8 +34,8 @@ Objective::Objective()
 
 Objective::Objective(const char *description, const char *target, int targetValue, bool required)
 {
-       strncpy(this->description, description, sizeof this->description);
-       strncpy(this->target, target, sizeof this->target);
+       strlcpy(this->description, description, sizeof this->description);
+       strlcpy(this->target, target, sizeof this->target);
        this->targetValue = targetValue;
        this->required = required;
 
index 6c4c16ab02eca94fec96557d9ce5966599efb6d2..a6811d33f1300ce000ecf7f8549f0dfbd29a92b1 100644 (file)
@@ -61,7 +61,7 @@ void Pak::showPakErrorAndExit()
 void Pak::setPakFile(const char *pakFilename)
 {
        #if USEPAK
-       strncpy(this->pakFilename, pakFilename, sizeof this->pakFilename);
+       strlcpy(this->pakFilename, pakFilename, sizeof this->pakFilename);
        
        debug(("Pak : Filename set to %s\n", pakFilename));
 
index cd4bf141fe7ecba819cd4e9693c43dbafa4db63b..1a1f300a994430eff505459ba781c89a59bdb346 100644 (file)
@@ -37,7 +37,7 @@ bool PersistData::setData(const char *data)
                return false;
        }
        
-       strncpy(this->data, data, sizeof this->data);
+       strlcpy(this->data, data, sizeof this->data);
        
        return true;
 }
index 82f03d677ea62e683491fe3b28d235c1099b9272..2ea8e6137ee83b2c195931ea1f56f25d0c7aba0a 100644 (file)
@@ -34,7 +34,7 @@ Persistant::~Persistant()
 
 void Persistant::setName(const char *name)
 {
-       strncpy(this->stageName, name, sizeof this->stageName);
+       strlcpy(this->stageName, name, sizeof this->stageName);
 }
 
 void Persistant::clear()
index c7c91e5836cb9692bb0f1bb4739c4aaf2dd42fb0..178b7c22627c03ace2051a2093c4ea7c616d91dd 100644 (file)
@@ -42,7 +42,7 @@ void SpawnPoint::reset()
 
 void SpawnPoint::create(const char *name, int x, int y, int spawnType, int spawnSubType, int minInterval, int maxInterval, bool active)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
        this->x = x;
        this->y = y;
        this->spawnType = spawnType;
index d5492f4cc2c00329b16fba96e68658be57099850..ef1c59df0f261e2b84ca3832187ab3cb66282942 100644 (file)
@@ -37,10 +37,10 @@ Switch::Switch()
 
 void Switch::set(const char *name, const char *linkName, const char *requiredObjectName, const char *activateMessage, int type, int x, int y, bool activated)
 {
-       strncpy(this->name, name, sizeof this->name);
-       strncpy(this->linkName, linkName, sizeof this->linkName);
-       strncpy(this->requiredObjectName, requiredObjectName, sizeof this->requiredObjectName);
-       strncpy(this->activateMessage, activateMessage, sizeof this->activateMessage);
+       strlcpy(this->name, name, sizeof this->name);
+       strlcpy(this->linkName, linkName, sizeof this->linkName);
+       strlcpy(this->requiredObjectName, requiredObjectName, sizeof this->requiredObjectName);
+       strlcpy(this->activateMessage, activateMessage, sizeof this->activateMessage);
        this->type = type;
        this->x = x;
        this->y = y;
index 9f213aabb64dc2ff28674e02d7d4e85ab0f97569..ae299a08c391e9c97b23b483806d1d775073e1c2 100644 (file)
@@ -29,7 +29,7 @@ Teleporter::Teleporter()
 
 void Teleporter::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
 }
 
 void Teleporter::set(int x, int y, int destX, int destY)
index b385278d7407293a412a4bd36096f032ff32ab09..89d53029f91ad5d5032700078a594b4b7f56ace4 100644 (file)
@@ -76,7 +76,7 @@ bool Train::waitsForPlayer()
 
 void Train::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
 }
 
 void Train::set(int startX, int startY, int endX, int endY, int pause, bool fromStart)
index 224f924a8a67ecf1ee3d15d3057d3dfd9d625b26..a43304d031080701eae573ccdff82f8bc8d6e826 100644 (file)
@@ -30,7 +30,7 @@ Trap::Trap()
 
 void Trap::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
 }
 
 void Trap::setTrapType(int type)
index 7268b8b9d56998225e1676547b21b985e35aae28..53d962bfbbced144ca460b07827e09fad2292b27 100644 (file)
@@ -34,7 +34,7 @@ Weapon::Weapon()
 
 void Weapon::setName(const char *name)
 {
-       strncpy(this->name, name, sizeof this->name);
+       strlcpy(this->name, name, sizeof this->name);
 }
 
 int Weapon::getSpeed(int face)
index fbf8c3850d6a9248643fe968fce799968387256e..eaca00857356d53cca5f5c7aac837abd9273a5a8 100644 (file)
@@ -43,10 +43,10 @@ void Widget::setProperties(const char *name, const char *groupName, const char *
                exit(1);
        }
 
-       strncpy(this->name, name, sizeof this->name);
-       strncpy(this->groupName, groupName, sizeof this->groupName);
-       strncpy(this->label, label, sizeof this->label);
-       strncpy(this->options, options, sizeof this->options);
+       strlcpy(this->name, name, sizeof this->name);
+       strlcpy(this->groupName, groupName, sizeof this->groupName);
+       strlcpy(this->label, label, sizeof this->label);
+       strlcpy(this->options, options, sizeof this->options);
        this->x = x;
        this->y = y;
        this->min = min;
index 73df1ab123099e0c2da75a590eaafb08f87e88ff..2e50744fb219e96c0983f8a3066497c97d4a8ee9 100644 (file)
@@ -287,7 +287,7 @@ void aquaBossMainInit()
        debug(("aquaBossMainInit\n"));
        
        map.boss[0] = new Boss();
-       strncpy(map.boss[0]->name, "BioMech Aqua Blob", sizeof map.boss[0]->name);
+       strlcpy(map.boss[0]->name, "BioMech Aqua Blob", sizeof map.boss[0]->name);
        map.boss[0]->health = 45 * game.skill;
        map.boss[0]->maxHealth = 45 * game.skill;
        map.boss[0]->setSprites(graphics.getSprite("AquaBossRight", true), graphics.getSprite("AquaBossLeft", true), graphics.getSprite("AquaBossLeft", true));
index 3d49d767384f78260d8e5942ac00f93b5476d45e..1952bb7c8db7fa223dceb2d28c4050b317c071e4 100644 (file)
@@ -51,7 +51,7 @@ void createSceneList()
                        line = strtok(NULL, "\n");
                        if (strcmp(line, "@none@") != 0)
                        {
-                               strncpy(scene->sprite, line, sizeof scene->sprite);
+                               strlcpy(scene->sprite, line, sizeof scene->sprite);
                                debug(("Loading cutscene image %s\n", scene->sprite));
                                graphics.quickSprite(scene->sprite, graphics.loadImage(scene->sprite));
                        }
index 69e8aa333fffec878fa8d2534aefcac2f1430d26..da6b9fb680e6ad8949b18fe7cfab59b552ec29e0 100644 (file)
@@ -365,7 +365,7 @@ void droidBossInit()
        debug(("droidBossInit\n"));
        
        map.boss[0] = new Boss();
-       strncpy(map.boss[0]->name, "BioMech Jetpack Blob", sizeof map.boss[0]->name);
+       strlcpy(map.boss[0]->name, "BioMech Jetpack Blob", sizeof map.boss[0]->name);
        map.boss[0]->health = 30 * game.skill;
        map.boss[0]->maxHealth = 30 * game.skill;
        map.boss[0]->setSprites(graphics.getSprite("JetpackBlobRight1", true), graphics.getSprite("JetpackBlobLeft1", true), graphics.getSprite("JetpackBlobLeft1", true));
@@ -387,7 +387,7 @@ void droidBossInit()
        for (int i = 1 ; i < 6 ; i++)
        {
                map.boss[i] = new Boss();
-               strncpy(map.boss[i]->name, "Orb Bomb", sizeof map.boss[i]->name);
+               strlcpy(map.boss[i]->name, "Orb Bomb", sizeof map.boss[i]->name);
                map.boss[i]->setSprites(graphics.getSprite("DroidOrb", true), graphics.getSprite("DroidOrb", true), graphics.getSprite("DroidOrb", true));
                map.boss[i]->active = false;
                map.boss[i]->face = 1;
index e69b96f92016b4fe6ca98a0dab4584eb30fa366e..197862b3d6ca2f1cf4ea1452c0d32181c1daa1f3 100644 (file)
@@ -147,7 +147,7 @@ void galdovInitBlackDroids()
                        map.boss[i] = new Boss();
                }
                debug(("BlackDroid %d init\n", i));
-               strncpy(map.boss[i]->name, "BlackDrod", sizeof map.boss[i]->name);
+               strlcpy(map.boss[i]->name, "BlackDrod", sizeof map.boss[i]->name);
                map.boss[i]->health = -90;
                map.boss[i]->maxHealth = -90;
                map.boss[i]->setSprites(graphics.getSprite("BlackDroidRight", true), graphics.getSprite("BlackDroidLeft", true), graphics.getSprite("BlackDroidDie", true));
@@ -493,7 +493,7 @@ void galdovFinalSplit()
                if (map.boss[i] == NULL)
                {
                        map.boss[i] = new Boss();
-                       strncpy(map.boss[i]->name, "MiniGaldov", sizeof map.boss[i]->name);
+                       strlcpy(map.boss[i]->name, "MiniGaldov", sizeof map.boss[i]->name);
                        map.boss[i]->health = 10 * game.skill;
                        map.boss[i]->maxHealth = 10 * game.skill;
                }
@@ -556,7 +556,7 @@ void galdovFinalInit()
        debug(("galdovFinalInit\n"));
        
        map.boss[0] = new Boss();
-       strncpy(map.boss[0]->name, "Galdov", sizeof map.boss[0]->name);
+       strlcpy(map.boss[0]->name, "Galdov", sizeof map.boss[0]->name);
        map.boss[0]->health = 45 * game.skill;
        map.boss[0]->maxHealth = 45 * game.skill;
        map.boss[0]->setSprites(graphics.getSprite("GaldovRight", true), graphics.getSprite("GaldovLeft", true), graphics.getSprite("GaldovDie", true));
@@ -680,7 +680,7 @@ void galdovFinalShieldInit()
                        delete map.boss[i];
                }
                map.boss[i] = new Boss();
-               strncpy(map.boss[i]->name, "OrbBomb", sizeof map.boss[i]->name);
+               strlcpy(map.boss[i]->name, "OrbBomb", sizeof map.boss[i]->name);
                map.boss[i]->setSprites(graphics.getSprite("DroidOrb", true), graphics.getSprite("DroidOrb", true), graphics.getSprite("DroidOrb", true));
                map.boss[i]->health = 999999;
                map.boss[i]->maxHealth = 99999;
index 5de463f54b4fa736f61ffe1a0342751623516b45..fa491dc2720be1e723b55a480f8c54fff0fdd7cf 100644 (file)
@@ -456,7 +456,7 @@ void galdovInit()
        debug(("galdovInit\n"));
        
        map.boss[0] = new Boss();
-       strncpy(map.boss[0]->name, "Galdov", sizeof map.boss[0]->name);
+       strlcpy(map.boss[0]->name, "Galdov", sizeof map.boss[0]->name);
        map.boss[0]->health = 45 * game.skill;
        map.boss[0]->maxHealth = 45 * game.skill;
        map.boss[0]->setSprites(graphics.getSprite("GaldovRight", true), graphics.getSprite("GaldovLeft", true), graphics.getSprite("GaldovLeft", true));
@@ -480,7 +480,7 @@ void galdovInit()
        for (int i = 1 ; i < 10 ; i++)
        {
                map.boss[i] = new Boss();
-               strncpy(map.boss[i]->name, "Fake", sizeof map.boss[i]->name);
+               strlcpy(map.boss[i]->name, "Fake", sizeof map.boss[i]->name);
                map.boss[i]->setSprites(graphics.getSprite("GaldovRight", true), graphics.getSprite("GaldovLeft", true), graphics.getSprite("GaldovLeft", true));
                map.boss[i]->x = 9999;
                map.boss[i]->y = 9999;
index 1e04687b08b11cc87095cb83eabda4b1a6b6e65d..8a442afe6b3370f8fb59e04e9389285707b468e8 100644 (file)
@@ -318,7 +318,7 @@ int gameover()
                Widget *widget = engine.getWidgetByName("gameOverNo");
                char postfix[100];
                snprintf(postfix, sizeof postfix, " (%d)", game.canContinue);
-               strncat(widget->label, postfix, sizeof widget->label);
+               strlcat(widget->label, postfix, sizeof widget->label);
        }
 
        while (true)
@@ -575,7 +575,7 @@ int doGame()
        #if DEBUG
        Uint32 now;
        char fps[10];
-       strncpy(fps, "fps", sizeof fps);
+       strlcpy(fps, "fps", sizeof fps);
        #endif
 
        engine.messageTime = -1;
index f8501592b908d00e31eadb9302dc95579b755b3a..faf00088d3324e0852d7097939138a91a4921d80 100755 (executable)
@@ -45,6 +45,11 @@ extern DECLSPEC int SDLCALL SDL_GetGamma(float *red, float *green, float *blue);
 #include <libintl.h>
 #define _(string) gettext(string)
 
+#if !defined(OpenBSD) && !defined(FreeBSD)
+#define strlcat(dest, src, n) strncat((dest), (src), (n) - 1)
+#define strlcpy(dest, src, n) do {strncpy((dest), (src), (n)); (dest)[(n) - 1] = 0;} while(false)
+#endif
+
 #include "defs.h"
 
 #include "CMath.h"
index bcfe2e15ef3e61dc5f3ae0644cc503fcf13c3dfa..4233fa98cdd2887322a621f8937f28b766f505fc 100644 (file)
@@ -280,7 +280,7 @@ void createObjectivesPanel(const char *levelName)
                                }
                                else
                                {
-                                       strncpy(string, _(data->value), sizeof string);
+                                       strlcpy(string, _(data->value), sizeof string);
                                        
                                        if (strlen(string) >= 25)
                                        {
@@ -546,8 +546,8 @@ int doHub()
 
        int rtn = -1;
        
-       strncpy(level, "@none@", sizeof level);
-       strncpy(game.stageName, "@none@", sizeof game.stageName);
+       strlcpy(level, "@none@", sizeof level);
+       strlcpy(game.stageName, "@none@", sizeof game.stageName);
 
        bool showData = false;
        bool showStats = false;
@@ -576,7 +576,7 @@ int doHub()
        if ((numberOfHubs == 0) && (gameData.completedWorld))
        {
                game.setMapName("data/spaceStation");
-               strncpy(game.stageName, "Space Station", sizeof game.stageName);
+               strlcpy(game.stageName, "Space Station", sizeof game.stageName);
                createObjectivesPanel("Space Station");
                showData = true;
                showStats = showMIAs = false;
index 7d2792c3c6fc1c7422ce2fe67d080d64e08e8f48..d77c21f800e16e3e8faf6948f61f944e98471c39 100644 (file)
@@ -42,14 +42,14 @@ void initSaveSlots()
 
                if (!fp)
                {
-                       strncpy(string, "%.2d - %s", sizeof string);
+                       strlcpy(string, "%.2d - %s", sizeof string);
                        snprintf(engine.saveSlot[i], sizeof engine.saveSlot[i], string, (i + 1), _("Empty"));
                }
                else
                {
                        if (fread(&tempGame, sizeof(Game), 1, fp) != 1)
                        {
-                               strncpy(string, "%.2d - %s", sizeof string);
+                               strlcpy(string, "%.2d - %s", sizeof string);
                                snprintf(engine.saveSlot[i], sizeof engine.saveSlot[i], string, (i + 1), _("Corrupt Save Data"));
                        }
                        else
@@ -163,7 +163,7 @@ bool loadGame(int slot)
                fgets(line, 1024, fp);
                
                sscanf(line, "%[^\n\r]", string[0]);
-               strncpy(stageName, string[0], sizeof stageName);
+               strlcpy(stageName, string[0], sizeof stageName);
                
                if (strcmp(stageName, "@EOF@") == 0)
                {
@@ -183,7 +183,7 @@ bool loadGame(int slot)
                        
                        fgets(line, 1024, fp);
                        
-                       strncpy(persistData->data, line, sizeof persistData->data);
+                       strlcpy(persistData->data, line, sizeof persistData->data);
                        
                        //debug(("Read %d: %s", i, persistData->data));
                        
@@ -237,7 +237,7 @@ int confirmSave()
        for (int i = 0 ; i < 5 ; i++)
        {
                snprintf(widgetName, sizeof widgetName, "slot%d", i + 1);
-               strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
+               strlcpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
        }
        
        engine.highlightWidget("slot1");
index 6d4e99f5c799b192e4de1aea73ad6f4f901148b9..bea1e30d4805e76f9511f53a5419b5ea23056304 100644 (file)
@@ -126,8 +126,8 @@ int main(int argc, char *argv[])
                else if (strcmp(argv[i], "-mono") == 0) engine.useAudio = 1;
                else if (strcmp(argv[i], "-version") == 0) showVersion();
                else if (strcmp(argv[i], "--help") == 0) showHelp();
-               else if (strcmp(argv[i], "-record") == 0) {recordMode = REPLAY_MODE::RECORD; strncpy(replayData.filename, argv[++i], sizeof replayData.filename);}
-               else if (strcmp(argv[i], "-playback") == 0) {recordMode = REPLAY_MODE::PLAYBACK; strncpy(replayData.filename, argv[++i], sizeof replayData.filename);}
+               else if (strcmp(argv[i], "-record") == 0) {recordMode = REPLAY_MODE::RECORD; strlcpy(replayData.filename, argv[++i], sizeof replayData.filename);}
+               else if (strcmp(argv[i], "-playback") == 0) {recordMode = REPLAY_MODE::PLAYBACK; strlcpy(replayData.filename, argv[++i], sizeof replayData.filename);}
                else if (strcmp(argv[i], "-map") == 0) {game.setMapName(argv[++i]); requiredSection = SECTION_GAME;}
                else if (strcmp(argv[i], "-listmaps") == 0) listMaps();
                else if (strcmp(argv[i], "-credits") == 0) requiredSection = SECTION_CREDITS;
@@ -148,7 +148,7 @@ int main(int argc, char *argv[])
                        
                case REPLAY_MODE::RECORD:
                        requiredSection = SECTION_GAME;
-                       strncpy(replayData.header.map, game.mapName, sizeof replayData.header.map);
+                       strlcpy(replayData.header.map, game.mapName, sizeof replayData.header.map);
                        replayData.header.skill = game.skill = 3;
                        replayData.setMode(REPLAY_MODE::RECORD);
                        break;
index 2f3bc9823c8bc987a7c9c5a3b44e4bede52e50cf..240553c1fdc57bb0ce17500ebba4890b19dabf6e 100644 (file)
@@ -268,7 +268,7 @@ void collectMapData()
                if (!strstr(string, " ENEMY \""))
                {
                        str = new String;
-                       strncpy(str->string, string, sizeof str->string);
+                       strlcpy(str->string, string, sizeof str->string);
                        stringTail->next = str;
                        stringTail = str;
                }
index 2415a3c8835709330dcf93d7fbffb770077a80d5..18345f43cb2bf3d0718a11fdeedf281e9a0f1450 100644 (file)
@@ -22,20 +22,20 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 
 void initMIAPhrases()
 {
-       strncpy(mia_scared[0], "help me...", sizeof mia_scared[0]);
-       strncpy(mia_scared[1], "i don't wanna die...", sizeof mia_scared[1]);
-       strncpy(mia_scared[2], "please... someone help...", sizeof mia_scared[2]);
-       strncpy(mia_scared[3], "i... i'm scared...", sizeof mia_scared[3]);
-       strncpy(mia_scared[4], "i wanna go home...", sizeof mia_scared[4]);
-       strncpy(mia_scared[5], "what was that?!", sizeof mia_scared[5]);
-       strncpy(mia_scared[6], "i don't like it here...", sizeof mia_scared[6]);
+       strlcpy(mia_scared[0], "help me...", sizeof mia_scared[0]);
+       strlcpy(mia_scared[1], "i don't wanna die...", sizeof mia_scared[1]);
+       strlcpy(mia_scared[2], "please... someone help...", sizeof mia_scared[2]);
+       strlcpy(mia_scared[3], "i... i'm scared...", sizeof mia_scared[3]);
+       strlcpy(mia_scared[4], "i wanna go home...", sizeof mia_scared[4]);
+       strlcpy(mia_scared[5], "what was that?!", sizeof mia_scared[5]);
+       strlcpy(mia_scared[6], "i don't like it here...", sizeof mia_scared[6]);
 }
 
 void addMIA(const char *name, int x, int y, int type)
 {
        Entity *mia = new Entity();
 
-       strncpy(mia->name, name, sizeof mia->name);
+       strlcpy(mia->name, name, sizeof mia->name);
        mia->id = type;
        mia->baseThink = 60;
        mia->health = 180;
index 151b07cc7d4ffcad3d6b1104b0f3ae863cec03f8..f923b6e2e419d34058da1852a3ed744dd2bad604 100644 (file)
@@ -66,7 +66,7 @@ void presentPlayerMedal(const char *tname)
        // Copy the input, so that threading
        // doesn't trip us up!
        char *data = new char[128];
-       strncpy(data, tname, sizeof data);
+       strlcpy(data, tname, sizeof data);
        
        SDL_Thread *thread = SDL_CreateThread(medalWorker, (void*)data);
        
index 96d74d9dc9b27010966994496865a6ab00e3013d..a02ae2400dd5486501837773946cdf600cf4bf11 100644 (file)
@@ -65,11 +65,11 @@ void checkSwitchContact(Entity *ent)
                                        
                                        if (swt->type == SWT_PRESSURE)
                                        {
-                                               strncpy(swt->requiredObjectName, "@none@", sizeof swt->requiredObjectName);
+                                               strlcpy(swt->requiredObjectName, "@none@", sizeof swt->requiredObjectName);
                                        }
                                        
                                        checkObjectives(swt->name, true);
-                                       strncpy(swt->name, "Switch", sizeof swt->name);
+                                       strlcpy(swt->name, "Switch", sizeof swt->name);
                                }
                                else
                                {
index 6db897fb5bbcdd1f9d81621a69a8039e2dcde969..522e67a479d9bf6876c9a633074fbdd1ab4ed6a3 100644 (file)
@@ -382,7 +382,7 @@ void tankBossMGInit()
        debug(("tankBossMGInit\n"));
        
        map.boss[0] = new Boss();
-       strncpy(map.boss[0]->name, "BioMech Tank V1.1", sizeof map.boss[0]->name);
+       strlcpy(map.boss[0]->name, "BioMech Tank V1.1", sizeof map.boss[0]->name);
        map.boss[0]->health = 65 * game.skill;
        map.boss[0]->maxHealth = 65 * game.skill;
        map.boss[0]->setSprites(graphics.getSprite("BlobTankCannonRight", true), graphics.getSprite("BlobTankCannonLeft", true), graphics.getSprite("BlobTankCannonLeft", true));
@@ -604,7 +604,7 @@ void tankBossGLInit()
        debug(("tankBossGLInit\n"));
        
        map.boss[1] = new Boss();
-       strncpy(map.boss[1]->name, "BioMech Tank V2.6", sizeof map.boss[1]->name);
+       strlcpy(map.boss[1]->name, "BioMech Tank V2.6", sizeof map.boss[1]->name);
        map.boss[1]->health = 65 * game.skill;
        map.boss[1]->maxHealth = 65 * game.skill;
        map.boss[1]->setSprites(graphics.getSprite("BlobTankGrenadeRight", true), graphics.getSprite("BlobTankGrenadeLeft", true), graphics.getSprite("BlobTankGrenadeLeft", true));
index b022cdb22394a6321b5b3769f71d18913c0551e6..c4e0619e740fe0621b9be09b2480cf8d2632980d 100644 (file)
@@ -118,7 +118,7 @@ void setupSaveWidgets()
        for (int i = 0 ; i < 5 ; i++)
        {
                snprintf(widgetName, sizeof widgetName, "save%d", i + 1);
-               strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
+               strlcpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
                
                if ((strstr(engine.saveSlot[i], _("Empty"))) || (strstr(engine.saveSlot[i], _("Corrupt"))))
                {
@@ -126,7 +126,7 @@ void setupSaveWidgets()
                }
                
                snprintf(widgetName, sizeof widgetName, "slot%d", i + 1);
-               strncpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
+               strlcpy(engine.getWidgetByName(widgetName)->label, engine.saveSlot[i], sizeof engine.getWidgetByName(widgetName)->label);
        }
 }
 
@@ -145,7 +145,7 @@ void loadTitleWidgets()
        setupSaveWidgets();
        
        Widget *widget = engine.getWidgetByName("labelManual");
-       strncpy(widget->label, GAMEPLAYMANUAL, sizeof widget->label);
+       strlcpy(widget->label, GAMEPLAYMANUAL, sizeof widget->label);
 
        showTitleWidgets();
 }