Revision: 2454
http://rigsofrods.svn.sourceforge.net/rigsofrods/?rev=2454&view=rev
Author: ulteq
Date: 2012-02-13 17:33:51 +0000 (Mon, 13 Feb 2012)
Log Message:
-----------
fixed several warnings:
- invalid array indexing
- array initialization
- strncpy related string null-termination
Modified Paths:
--------------
trunk/source/main/gameplay/CacheSystem.cpp
trunk/source/main/gameplay/Road.cpp
trunk/source/main/gameplay/road2.cpp
trunk/source/main/gfx/vidcam.cpp
trunk/source/main/physics/input_output/SerializedRig.cpp
trunk/source/main/utils/InputEngine.cpp
Modified: trunk/source/main/gameplay/CacheSystem.cpp
===================================================================
--- trunk/source/main/gameplay/CacheSystem.cpp 2012-02-06 09:19:52 UTC (rev
2453)
+++ trunk/source/main/gameplay/CacheSystem.cpp 2012-02-13 17:33:51 UTC (rev
2454)
@@ -1786,21 +1786,20 @@
LOG("error opening file: "+configlocation+"categories.cfg");
return;
}
- char line[1024] = {0};
+ char line[1024] = {};
while (!feof(fd))
{
int res = fscanf(fd, " %[^\n\r]", line);
if (line[0] == ';') continue;
- int number = 0;
- char title[256] = {0};
+ char title[256] = {};
const char delimiters[] = ",";
- char str_work[1024] = {0};
+ char str_work[1024] = {};
- strncpy(str_work, line, 1024);
-
+ strncpy(str_work, line, 1023);
+ str_work[1023] = '\0';
char *token = strtok(str_work, delimiters);
if (token == NULL) continue;
- number = atoi(token);
+ int number = atoi(token);
token = strtok(NULL, delimiters);
if (token == NULL) continue;
//strip spaces at the beginning
Modified: trunk/source/main/gameplay/Road.cpp
===================================================================
--- trunk/source/main/gameplay/Road.cpp 2012-02-06 09:19:52 UTC (rev 2453)
+++ trunk/source/main/gameplay/Road.cpp 2012-02-13 17:33:51 UTC (rev 2454)
@@ -82,7 +82,7 @@
sprintf(mname,"%s.mesh", name);
Entity *te = mSceneMgr->createEntity(oname, mname);
te->setCastShadows(false);
- if(free_rtype == MAX_RTYPES)
+ if(free_rtype >= MAX_RTYPES)
return;
rtypes[free_rtype].node=mSceneMgr->getRootSceneNode()->createChildSceneNode();
(rtypes[free_rtype].node)->attachObject(te);
@@ -96,7 +96,7 @@
Quaternion rot=tenode->getOrientation();
Vector3 pos=tenode->getPosition();
cur_rtype++;
- if (cur_rtype==free_rtype) cur_rtype=0;
+ if (cur_rtype>=free_rtype || cur_rtype>= MAX_RTYPES) cur_rtype=0;
tenode->setVisible(false);
tenode=rtypes[cur_rtype].node;
strcpy(curtype, rtypes[cur_rtype].name);
Modified: trunk/source/main/gameplay/road2.cpp
===================================================================
--- trunk/source/main/gameplay/road2.cpp 2012-02-06 09:19:52 UTC (rev
2453)
+++ trunk/source/main/gameplay/road2.cpp 2012-02-13 17:33:51 UTC (rev
2454)
@@ -339,7 +339,7 @@
//the two firsts must be the "high" points
void Road2::addQuad(Vector3 p1, Vector3 p2, Vector3 p3, Vector3 p4, int
texfit, bool collision, Vector3 pos, Vector3 lastpos, float width, bool flip)
{
- if(vertexcount>=MAX_VERTEX || tricount >= MAX_TRIS) return;
+ if(vertexcount+3 >= MAX_VERTEX || tricount*3+3+2 >= MAX_TRIS*3) return;
Vector2 texf[4];
textureFit(p1, p2, p3, p4, texfit, texf, pos, lastpos, width);
//vertexes
Modified: trunk/source/main/gfx/vidcam.cpp
===================================================================
--- trunk/source/main/gfx/vidcam.cpp 2012-02-06 09:19:52 UTC (rev 2453)
+++ trunk/source/main/gfx/vidcam.cpp 2012-02-13 17:33:51 UTC (rev 2454)
@@ -277,11 +277,12 @@
crole = PARSEINT (args[16]);
cmode = PARSEINT (args[17]);
strncpy(materialname, args[18].c_str(), 255);
+ materialname[255] = '\0';
if(n > 19)
strncpy(vidCamName, args[19].c_str(), 255);
else
strncpy(vidCamName, materialname, 255); // fallback,
use materialname
-
+
//if (texx <= 0 || !isPowerOfTwo(texx) || texy <= 0 ||
!isPowerOfTwo(texy))
// disabled isPowerOfTwo, as it can be a renderwindow now with
custom resolution
if (texx <= 0 || texy <= 0)
Modified: trunk/source/main/physics/input_output/SerializedRig.cpp
===================================================================
--- trunk/source/main/physics/input_output/SerializedRig.cpp 2012-02-06
09:19:52 UTC (rev 2453)
+++ trunk/source/main/physics/input_output/SerializedRig.cpp 2012-02-13
17:33:51 UTC (rev 2454)
@@ -6523,7 +6523,7 @@
void SerializedRig::addSoundSource(SoundScriptInstance *ssi, int nodenum, int
type, parsecontext_t *c)
{
if (!ssi) return; //fizzle
- if (free_soundsource==MAX_SOUNDSCRIPTS_PER_TRUCK)
+ if (free_soundsource>=MAX_SOUNDSCRIPTS_PER_TRUCK)
{
parser_warning(c, "Error, too many sound sources per vehicle!",
PARSER_ERROR);
return;
Modified: trunk/source/main/utils/InputEngine.cpp
===================================================================
--- trunk/source/main/utils/InputEngine.cpp 2012-02-06 09:19:52 UTC (rev
2453)
+++ trunk/source/main/utils/InputEngine.cpp 2012-02-13 17:33:51 UTC (rev
2454)
@@ -2486,6 +2486,7 @@
// separate all keys and construct the key combination
//LOG("try to add key: " + String(eventName)+","+
String(evtype)+","+String(keycodes));
strncpy(keycodes_work, keycodes, 255);
+ keycodes_work[255] = '\0';
char *token = strtok(keycodes_work, delimiters);
while (token != NULL)
@@ -2567,7 +2568,7 @@
case ET_JoystickAxisAbs:
{
int axisNo = 0;
- char options[250] = {};
+ char options[256] = {};
memset(options, 0, 250);
sscanf(line, "%s %s %d %d %s", eventName, evtype,
&joyNo, &axisNo, options);
int eventID = resolveEventName(String(eventName));
@@ -2584,8 +2585,8 @@
// 0 = all
// -1 = lower
// 1 = upper
- char tmp[250] = {};
- strncpy(tmp, options, 250);
+ char tmp[256] = {};
+ strncpy(tmp, options, 255);
char *token = strtok(tmp, delimiters);
while (token != NULL)
{
@@ -2861,8 +2862,8 @@
Ogre::String InputEngine::getEventGroup(Ogre::String eventName)
{
const char delimiters[] = "_";
- char tmp[250] = {};
- strncpy(tmp, eventName.c_str(), 250);
+ char tmp[256] = {};
+ strncpy(tmp, eventName.c_str(), 255);
char *token = strtok(tmp, delimiters);
while (token != NULL)
return Ogre::String(token);
This was sent by the SourceForge.net collaborative development platform, the
world's largest Open Source development site.
------------------------------------------------------------------------------
Try before you buy = See our experts in action!
The most comprehensive online learning library for Microsoft developers
is just $99.99! Visual Studio, SharePoint, SQL - plus HTML5, CSS3, MVC3,
Metro Style Apps, more. Free future releases when you subscribe now!
http://p.sf.net/sfu/learndevnow-dev2
_______________________________________________
Rigsofrods-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/rigsofrods-devel