2
0
mirror of https://github.com/rehlds/rehlds.git synced 2024-12-28 15:45:46 +03:00

Fixed saving temporary string in PF_lightstyle_I (#532)

Fixed saving temporary string in PF_lightstyle_I
Marked mismatched code (HLTV)
Fixed lightstyle copying in ParseSaveTables (SinglePlayer)
This commit is contained in:
Artem Golubikhin 2017-10-09 18:06:05 +03:00 committed by theAsmodai
parent ae28ee69b4
commit 2829c7ffde
7 changed files with 25 additions and 5 deletions

View File

@ -353,6 +353,13 @@ void World::AddLightStyle(int index, char *style)
m_System->Printf("WARNING! World::SetLightStyle: style too long (%i).\n", length);
}
// FIXME: code mismatch
// Original code:
// Q_strncopy(..., 64);
// ...[63] = '\0';
// Current code:
// Q_strncopy(..., 64);
// ...[64] = '\0';
Q_strlcpy(m_Lightstyles[index], style);
}

View File

@ -251,6 +251,7 @@ protected:
entity_state_t m_Instanced_BaseLines[MAX_INSTANCED_BASELINES];
int m_MaxInstanced_BaseLine;
// TODO: wtf, why 65? here should be 64
char m_Lightstyles[MAX_LIGHTSTYLES][65];
movevars_t m_MoveVars;

View File

@ -24,6 +24,7 @@
#define MAX_LIGHTSTYLE_INDEX_BITS 6
#define MAX_LIGHTSTYLES (1<<MAX_LIGHTSTYLE_INDEX_BITS)
constexpr auto MAX_LIGHTSTYLE_SIZE = size_t{64};
// Resource counts
#define MAX_MODEL_INDEX_BITS 9 // sent as a short

View File

@ -1636,8 +1636,7 @@ SAVERESTOREDATA *SaveGamestate(void)
if (g_psv.lightstyles[i])
{
light.index = i;
Q_strncpy(light.style, g_psv.lightstyles[i], 63);
light.style[63] = 0;
Q_strlcpy(light.style, g_psv.lightstyles[i]);
gEntityInterface.pfnSaveWriteFields(pSaveData, "LIGHTSTYLE", &light, gLightstyleDescription, ARRAYSIZE(gLightstyleDescription));
}
}
@ -1844,10 +1843,15 @@ void ParseSaveTables(SAVERESTOREDATA *pSaveData, SAVE_HEADER *pHeader, int updat
gEntityInterface.pfnSaveReadFields(pSaveData, "LIGHTSTYLE", &light, gLightstyleDescription, ARRAYSIZE(gLightstyleDescription));
if (updateGlobals)
{
#ifdef REHLDS_FIXES
Q_strlcpy(g_rehlds_sv.lightstyleBuffers[light.index], light.style);
g_psv.lightstyles[light.index] = g_rehlds_sv.lightstyleBuffers[light.index];
#else // REHLDS_FIXES
char *val = (char *)Hunk_Alloc(Q_strlen(light.style) + 1);
Q_strncpy(val, light.style, 3);
val[3] = 0;
Q_strncpy(val, light.style, ARRAYSIZE(val) - 1);
val[ARRAYSIZE(val) - 1] = '\0';
g_psv.lightstyles[light.index] = val;
#endif // REHLDS_FIXES
}
}
}

View File

@ -69,7 +69,7 @@ typedef struct SAVE_HEADER_s
typedef struct SAVELIGHTSTYLE_s
{
int index;
char style[64];
char style[MAX_LIGHTSTYLE_SIZE];
} SAVELIGHTSTYLE;
typedef struct TITLECOMMENT_s

View File

@ -1711,7 +1711,12 @@ int EXT_FUNC PF_DecalIndex(const char *name)
void EXT_FUNC PF_lightstyle_I(int style, const char *val)
{
#ifdef REHLDS_FIXES
Q_strlcpy(g_rehlds_sv.lightstyleBuffers[style], val);
g_psv.lightstyles[style] = g_rehlds_sv.lightstyleBuffers[style];
#else // REHLDS_FIXES
g_psv.lightstyles[style] = val;
#endif // REHLDS_FIXES
if (g_psv.state != ss_active)
return;

View File

@ -170,6 +170,8 @@ struct rehlds_server_t {
resource_t resources[RESOURCE_MAX_COUNT];
char precachedGenericResourceNames[RESOURCE_MAX_COUNT][MAX_QPATH];
size_t precachedGenericResourceCount;
char lightstyleBuffers[MAX_LIGHTSTYLES][MAX_LIGHTSTYLE_SIZE];
#endif
};