Fix some errors (#1020)

Fix some critical errors
This commit is contained in:
Unreal Karaulov 2021-12-03 00:47:57 +03:00 committed by GitHub
parent 5dcda02b65
commit 3cda059669
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
13 changed files with 37 additions and 23 deletions

View File

@ -289,7 +289,18 @@ size_t CAmxxReader::GetBufferSize()
m_pFile = NULL; \ m_pFile = NULL; \
return m_Status; \ return m_Status; \
} }
#define DATAREAD_RELEASE(addr, itemsize, itemcount) \
if (fread(addr, itemsize, itemcount, m_pFile) != static_cast<size_t>(itemcount)) \
{ \
if (feof(m_pFile)) \
m_Status = Err_FileInvalid; \
else \
m_Status = Err_FileRead; \
fclose(m_pFile); \
m_pFile = NULL; \
delete[] tempBuffer;\
return m_Status; \
}
CAmxxReader::Error CAmxxReader::GetSection(void *buffer) CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
{ {
if (!m_pFile) if (!m_pFile)
@ -311,7 +322,7 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
PluginEntry *pe = &(m_Bh.plugins[m_Entry]); PluginEntry *pe = &(m_Bh.plugins[m_Entry]);
char *tempBuffer = new char[m_SectionLength + 1]; char *tempBuffer = new char[m_SectionLength + 1];
fseek(m_pFile, pe->offs, SEEK_SET); fseek(m_pFile, pe->offs, SEEK_SET);
DATAREAD((void *)tempBuffer, 1, m_SectionLength); DATAREAD_RELEASE((void *)tempBuffer, 1, m_SectionLength);
uLongf destLen = GetBufferSize(); uLongf destLen = GetBufferSize();
int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength); int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
delete [] tempBuffer; delete [] tempBuffer;
@ -335,7 +346,7 @@ CAmxxReader::Error CAmxxReader::GetSection(void *buffer)
// read the data to a temporary buffer // read the data to a temporary buffer
char *tempBuffer = new char[m_SectionLength + 1]; char *tempBuffer = new char[m_SectionLength + 1];
//fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile); //fread(tempBuffer, sizeof(char), m_SectionLength, m_pFile);
DATAREAD((void*)tempBuffer, 1, m_SectionLength); DATAREAD_RELEASE((void*)tempBuffer, 1, m_SectionLength);
// decompress // decompress
int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength); int result = uncompress((Bytef *)buffer, &destLen, (Bytef *)tempBuffer, m_SectionLength);
delete [] tempBuffer; delete [] tempBuffer;

View File

@ -96,12 +96,14 @@ static cell AMX_NATIVE_CALL read_file(AMX *amx, cell *params)
{ {
length = strlen(buffer); length = strlen(buffer);
if (length > 0)
{
if (buffer[length - 1] == '\n') if (buffer[length - 1] == '\n')
buffer[--length] = '\0'; buffer[--length] = '\0';
if (buffer[length - 1] == '\r') if (buffer[length - 1] == '\r')
buffer[--length] = '\0'; buffer[--length] = '\0';
}
cell* textLen = get_amxaddr(amx, params[5]); cell* textLen = get_amxaddr(amx, params[5]);
*textLen = set_amxstring_utf8(amx, params[3], buffer, length, params[4]); *textLen = set_amxstring_utf8(amx, params[3], buffer, length, params[4]);

View File

@ -46,7 +46,7 @@
#define _MAX_PATH 250 #define _MAX_PATH 250
#endif #endif
#if !defined DIRSEP_CHAR #if !defined DIRSEP_CHAR
#if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE___ #if defined LINUX || defined __FreeBSD__ || defined __OpenBSD__ || defined __APPLE__
#define DIRSEP_CHAR '/' #define DIRSEP_CHAR '/'
#elif defined macintosh #elif defined macintosh
#define DIRSEP_CHAR ':' #define DIRSEP_CHAR ':'

View File

@ -229,8 +229,8 @@ void ListboxItemSelected(HWND hDlg) {
// Retrieve complete stats record of this position. Position in listbox should be same as rank in our records! // Retrieve complete stats record of this position. Position in listbox should be same as rank in our records!
RankSystem::RankStats* stats = g_rank.findEntryInRankByPos((int)nItem + 1); RankSystem::RankStats* stats = g_rank.findEntryInRankByPos((int)nItem + 1);
if (stats == NULL) { if (stats == NULL) {
char msg[] = "Error: Couldn't find the record by position! (nItem = %d)"; char msg[512];
sprintf(msg, msg, nItem); sprintf(msg, "Error: Couldn't find the record by position! (nItem = %d)", nItem);
MessageBox(hDlg, msg, "Oh fiddlesticks!", MB_OK); MessageBox(hDlg, msg, "Oh fiddlesticks!", MB_OK);
ClearStatsfields(hDlg); ClearStatsfields(hDlg);
return; return;

View File

@ -307,10 +307,10 @@ static cell AMX_NATIVE_CALL custom_wpn_dmg(AMX *amx, cell *params){ // wid,att,v
CPlayer* pAtt = GET_PLAYER_POINTER_I(att); CPlayer* pAtt = GET_PLAYER_POINTER_I(att);
CPlayer* pVic = GET_PLAYER_POINTER_I(vic); CPlayer* pVic = GET_PLAYER_POINTER_I(vic);
if ( !pAtt ) pAtt = pVic;
pVic->pEdict->v.dmg_inflictor = NULL; pVic->pEdict->v.dmg_inflictor = NULL;
pAtt->saveHit( pVic , weapon , dmg, aim ); pAtt->saveHit( pVic , weapon , dmg, aim );
if ( !pAtt ) pAtt = pVic;
int TA = 0; int TA = 0;
if ( (pVic->teamId == pAtt->teamId) && ( pVic != pAtt) ) if ( (pVic->teamId == pAtt->teamId) && ( pVic != pAtt) )
TA = 1; TA = 1;

View File

@ -506,7 +506,7 @@ static cell AMX_NATIVE_CALL objective_set_data(AMX *amx, cell *params){ // index
GET_CP_PD(pent).model_body_neutral = ivalue; GET_CP_PD(pent).model_body_neutral = ivalue;
return 1; return 1;
case CP_model_body_allies : case CP_model_body_allies :
GET_CP_PD(pent).model_body_axis = ivalue; GET_CP_PD(pent).model_body_allies = ivalue;
return 1; return 1;
case CP_model_body_axis : case CP_model_body_axis :
GET_CP_PD(pent).model_body_axis = ivalue; GET_CP_PD(pent).model_body_axis = ivalue;

View File

@ -387,12 +387,12 @@ static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params)
pVic->pEdict->v.dmg_inflictor = NULL; pVic->pEdict->v.dmg_inflictor = NULL;
if(pAtt->index != pVic->index)
pAtt->saveHit(pVic , weapon , dmg, aim);
if(!pAtt) if(!pAtt)
pAtt = pVic; pAtt = pVic;
if(pAtt->index != pVic->index)
pAtt->saveHit(pVic , weapon , dmg, aim);
int TA = 0; int TA = 0;
if((pVic->pEdict->v.team == pAtt->pEdict->v.team) && (pVic != pAtt)) if((pVic->pEdict->v.team == pAtt->pEdict->v.team) && (pVic != pAtt))

View File

@ -1110,9 +1110,9 @@ static cell AMX_NATIVE_CALL set_es(AMX *amx, cell *params)
es->vuser3.z = amx_ctof(ptr[2]); es->vuser3.z = amx_ctof(ptr[2]);
return 1; return 1;
case ES_vUser4: case ES_vUser4:
es->vuser3.x = amx_ctof(ptr[0]); es->vuser4.x = amx_ctof(ptr[0]);
es->vuser3.y = amx_ctof(ptr[1]); es->vuser4.y = amx_ctof(ptr[1]);
es->vuser3.z = amx_ctof(ptr[2]); es->vuser4.z = amx_ctof(ptr[2]);
return 1; return 1;
} }

View File

@ -262,10 +262,10 @@ static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params){ // wid,att,vic,dmg
CPlayer* pAtt = GET_PLAYER_POINTER_I(att); CPlayer* pAtt = GET_PLAYER_POINTER_I(att);
CPlayer* pVic = GET_PLAYER_POINTER_I(vic); CPlayer* pVic = GET_PLAYER_POINTER_I(vic);
if ( !pAtt ) pAtt = pVic;
pVic->pEdict->v.dmg_inflictor = NULL; pVic->pEdict->v.dmg_inflictor = NULL;
pAtt->saveHit( pVic , weapon , dmg, aim ); pAtt->saveHit( pVic , weapon , dmg, aim );
if ( !pAtt ) pAtt = pVic;
int TA = 0; int TA = 0;
if ( (pVic->pEdict->v.team == pAtt->pEdict->v.team ) && ( pVic != pAtt) ) if ( (pVic->pEdict->v.team == pAtt->pEdict->v.team ) && ( pVic != pAtt) )
TA = 1; TA = 1;

View File

@ -47,7 +47,7 @@ bool isModuleActive(){
bool util_strncmp( const char *sz1, const char *sz2, int size){ bool util_strncmp( const char *sz1, const char *sz2, int size){
int i = 0; int i = 0;
while( sz1[i] && i<=size){ while( i<=size && sz1[i] ){
if ( sz1[i] != sz2[i] ) if ( sz1[i] != sz2[i] )
return false; return false;
i++; i++;

View File

@ -295,10 +295,10 @@ static cell AMX_NATIVE_CALL cwpn_dmg(AMX *amx, cell *params){ // wid,att,vic,dmg
CPlayer* pAtt = GET_PLAYER_POINTER_I(att); CPlayer* pAtt = GET_PLAYER_POINTER_I(att);
CPlayer* pVic = GET_PLAYER_POINTER_I(vic); CPlayer* pVic = GET_PLAYER_POINTER_I(vic);
if ( !pAtt ) pAtt = pVic;
pVic->pEdict->v.dmg_inflictor = NULL; pVic->pEdict->v.dmg_inflictor = NULL;
pAtt->saveHit( pVic , weapon , dmg, aim ); pAtt->saveHit( pVic , weapon , dmg, aim );
if ( !pAtt ) pAtt = pVic;
int TA = 0; int TA = 0;
if ( (pVic->pEdict->v.team == pAtt->pEdict->v.team ) && ( pVic != pAtt) ) if ( (pVic->pEdict->v.team == pAtt->pEdict->v.team ) && ( pVic != pAtt) )
TA = 1; TA = 1;

View File

@ -122,6 +122,7 @@ void Client_TSHealth_End(void* mValue){
weapon = 37; // throwing knife weapon = 37; // throwing knife
aim = pAttacker ? pAttacker->aiming : 0; aim = pAttacker ? pAttacker->aiming : 0;
if (pAttacker)
pAttacker->saveHit( mPlayer , weapon , damage, aim ); pAttacker->saveHit( mPlayer , weapon , damage, aim );
} }
} }

View File

@ -831,7 +831,7 @@ MMDB_lookup_result_s MMDB_lookup_string(MMDB_s *const mmdb,
struct addrinfo *addresses = NULL; struct addrinfo *addresses = NULL;
*gai_error = resolve_any_address(ipstr, &addresses); *gai_error = resolve_any_address(ipstr, &addresses);
if (!*gai_error) { if (!*gai_error && NULL != addresses) {
result = MMDB_lookup_sockaddr(mmdb, addresses->ai_addr, mmdb_error); result = MMDB_lookup_sockaddr(mmdb, addresses->ai_addr, mmdb_error);
} }