mirror of
https://git.do.srb2.org/KartKrew/Kart-Public.git
synced 2024-12-26 12:21:19 +00:00
Miscellaneous memory bug fixes to make AddressSanitizer happy
This commit is contained in:
parent
48ddb25fd6
commit
70128776ac
10 changed files with 57 additions and 36 deletions
|
@ -1934,6 +1934,7 @@ static void CL_LoadReceivedSavegame(void)
|
|||
static void SendAskInfo(INT32 node)
|
||||
{
|
||||
const tic_t asktime = I_GetTime();
|
||||
|
||||
netbuffer->packettype = PT_ASKINFO;
|
||||
netbuffer->u.askinfo.version = VERSION;
|
||||
netbuffer->u.askinfo.time = (tic_t)LONG(asktime);
|
||||
|
@ -1946,7 +1947,7 @@ static void SendAskInfo(INT32 node)
|
|||
if (node != 0 && node != BROADCASTADDR &&
|
||||
cv_rendezvousserver.string[0])
|
||||
{
|
||||
I_NetRequestHolePunch();
|
||||
I_NetRequestHolePunch(node);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -75,7 +75,7 @@ boolean (*I_NetCanGet)(void) = NULL;
|
|||
void (*I_NetCloseSocket)(void) = NULL;
|
||||
void (*I_NetFreeNodenum)(INT32 nodenum) = NULL;
|
||||
SINT8 (*I_NetMakeNodewPort)(const char *address, const char* port) = NULL;
|
||||
void (*I_NetRequestHolePunch)(void) = NULL;
|
||||
void (*I_NetRequestHolePunch)(INT32 node) = NULL;
|
||||
void (*I_NetRegisterHolePunch)(void) = NULL;
|
||||
boolean (*I_NetOpenSocket)(void) = NULL;
|
||||
boolean (*I_Ban) (INT32 node) = NULL;
|
||||
|
|
|
@ -3397,7 +3397,7 @@ static void DEH_LoadDehackedFile(MYFILE *f, UINT16 wad)
|
|||
|
||||
if (i > 0 && i <= NUMMAPS)
|
||||
{
|
||||
if (mapheaderinfo[i])
|
||||
if (mapheaderinfo[i-1])
|
||||
G_SetGameModified(multiplayer, true); // only mark as a major mod if it replaces an already-existing mapheaderinfo
|
||||
readlevelheader(f, i);
|
||||
}
|
||||
|
|
|
@ -1276,6 +1276,9 @@ INT32 G_KeyStringtoNum(const char *keystr)
|
|||
{
|
||||
UINT32 j;
|
||||
|
||||
if (!keystr[0])
|
||||
return 0;
|
||||
|
||||
if (!keystr[1] && keystr[0] > ' ' && keystr[0] <= 'z')
|
||||
return keystr[0];
|
||||
|
||||
|
|
|
@ -245,7 +245,7 @@ static void HWR_ResizeBlock(INT32 originalwidth, INT32 originalheight,
|
|||
min = blockwidth;
|
||||
}
|
||||
|
||||
for (k = 2048, j = 0; k > max; j++)
|
||||
for (k = 2048, j = 0; k > max && j < 8; j++)
|
||||
k>>=1;
|
||||
grInfo->smallLodLog2 = gr_lods[j];
|
||||
grInfo->largeLodLog2 = gr_lods[j];
|
||||
|
|
|
@ -474,7 +474,7 @@ void HWR_InitMD2(void)
|
|||
size_t i;
|
||||
INT32 s;
|
||||
FILE *f;
|
||||
char name[18], filename[32];
|
||||
char name[20], filename[32];
|
||||
float scale, offset;
|
||||
|
||||
CONS_Printf("InitMD2()...\n");
|
||||
|
@ -561,7 +561,7 @@ md2found:
|
|||
void HWR_AddPlayerMD2(int skin) // For MD2's that were added after startup
|
||||
{
|
||||
FILE *f;
|
||||
char name[18], filename[32];
|
||||
char name[20], filename[32];
|
||||
float scale, offset;
|
||||
|
||||
if (nomd2s)
|
||||
|
@ -610,7 +610,7 @@ void HWR_AddSpriteMD2(size_t spritenum) // For MD2s that were added after startu
|
|||
FILE *f;
|
||||
// name[18] is used to check for names in the mdls.dat file that match with sprites or player skins
|
||||
// sprite names are always 4 characters long, and names is for player skins can be up to 19 characters long
|
||||
char name[18], filename[32];
|
||||
char name[20], filename[32];
|
||||
float scale, offset;
|
||||
|
||||
if (nomd2s)
|
||||
|
@ -660,18 +660,18 @@ spritemd2found:
|
|||
// 0.0722 to blue
|
||||
// (See this same define in k_kart.c!)
|
||||
#define SETBRIGHTNESS(brightness,r,g,b) \
|
||||
brightness = (UINT8)(((1063*(UINT16)(r))/5000) + ((3576*(UINT16)(g))/5000) + ((361*(UINT16)(b))/5000))
|
||||
brightness = (UINT8)(((1063*(UINT32)(r))/5000) + ((3576*(UINT32)(g))/5000) + ((361*(UINT32)(b))/5000))
|
||||
|
||||
static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch, GLMipmap_t *grmip, INT32 skinnum, skincolors_t color)
|
||||
{
|
||||
UINT16 w = gpatch->width, h = gpatch->height;
|
||||
UINT32 size = w*h;
|
||||
RGBA_t *image, *blendimage, *cur, blendcolor;
|
||||
UINT8 translation[16]; // First the color index
|
||||
UINT8 cutoff[16]; // Brightness cutoff before using the next color
|
||||
UINT8 translation[17]; // First the color index
|
||||
UINT8 cutoff[17]; // Brightness cutoff before using the next color
|
||||
UINT8 translen = 0;
|
||||
UINT8 i;
|
||||
UINT8 colorbrightnesses[16];
|
||||
UINT8 colorbrightnesses[17];
|
||||
UINT8 color_match_lookup[256]; // optimization attempt
|
||||
|
||||
blendcolor = V_GetColor(0); // initialize
|
||||
|
@ -741,6 +741,11 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
translen++;
|
||||
}
|
||||
|
||||
if (translen > 0)
|
||||
translation[translen] = translation[translen-1]; // extended to accomodate secondi if firsti equal to translen-1
|
||||
if (translen > 1)
|
||||
cutoff[translen] = cutoff[translen-1] = 0; // as above
|
||||
|
||||
if (skinnum == TC_RAINBOW && translen > 0)
|
||||
{
|
||||
UINT16 b;
|
||||
|
@ -756,7 +761,7 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
{
|
||||
UINT16 brightdif = 256;
|
||||
|
||||
color_match_lookup[i] = 0;
|
||||
color_match_lookup[b] = 0;
|
||||
for (i = 0; i < translen; i++)
|
||||
{
|
||||
if (b > colorbrightnesses[i]) // don't allow greater matches (because calculating a makeshift gradient for this is already a huge mess as is)
|
||||
|
@ -773,6 +778,9 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
}
|
||||
}
|
||||
|
||||
if (translen > 0)
|
||||
colorbrightnesses[translen] = colorbrightnesses[translen-1];
|
||||
|
||||
while (size--)
|
||||
{
|
||||
if (skinnum == TC_BOSS)
|
||||
|
@ -918,6 +926,8 @@ static void HWR_CreateBlendedTexture(GLPatch_t *gpatch, GLPatch_t *blendgpatch,
|
|||
secondi = firsti+1;
|
||||
|
||||
mulmax = cutoff[firsti] - cutoff[secondi];
|
||||
if (mulmax == 0)
|
||||
mulmax = 1; // don't divide by zero on equal cutoffs (however unlikely)
|
||||
mul = cutoff[firsti] - brightness;
|
||||
}
|
||||
|
||||
|
|
|
@ -52,6 +52,8 @@ consvar_t cv_masterserver_token = {
|
|||
NULL, 0, NULL, NULL, 0, 0, NULL/* C90 moment */
|
||||
};
|
||||
|
||||
#define HMS_QUERY_VERSION "?v=2.2"
|
||||
|
||||
#ifdef MASTERSERVER
|
||||
|
||||
static int hms_started;
|
||||
|
@ -171,7 +173,7 @@ HMS_connect (const char *format, ...)
|
|||
|
||||
va_start (ap, format);
|
||||
url = malloc(seek + vsnprintf(0, 0, format, ap) +
|
||||
sizeof "?v=2" - 1 +
|
||||
sizeof HMS_QUERY_VERSION - 1 +
|
||||
token_length + 1);
|
||||
va_end (ap);
|
||||
|
||||
|
@ -185,8 +187,8 @@ HMS_connect (const char *format, ...)
|
|||
seek += vsprintf(&url[seek], format, ap);
|
||||
va_end (ap);
|
||||
|
||||
strcpy(&url[seek], "?v=2.2");
|
||||
seek += sizeof "?v=2.2" - 1;
|
||||
strcpy(&url[seek], HMS_QUERY_VERSION);
|
||||
seek += sizeof HMS_QUERY_VERSION - 1;
|
||||
|
||||
if (quack_token)
|
||||
sprintf(&url[seek], "&token=%s", quack_token);
|
||||
|
|
|
@ -152,7 +152,7 @@ extern void (*I_NetCloseSocket)(void);
|
|||
|
||||
/** \brief send a hole punching request
|
||||
*/
|
||||
extern void (*I_NetRequestHolePunch)(void);
|
||||
extern void (*I_NetRequestHolePunch)(INT32 node);
|
||||
|
||||
/** \brief register this machine on the hole punching server
|
||||
*/
|
||||
|
|
|
@ -1533,9 +1533,9 @@ static void rendezvous(int size)
|
|||
free(addrs);
|
||||
}
|
||||
|
||||
static void SOCK_RequestHolePunch(void)
|
||||
static void SOCK_RequestHolePunch(INT32 node)
|
||||
{
|
||||
mysockaddr_t * addr = &clientaddress[doomcom->remotenode];
|
||||
mysockaddr_t * addr = &clientaddress[node];
|
||||
|
||||
holepunchpacket->addr = addr->ip4.sin_addr.s_addr;
|
||||
holepunchpacket->port = addr->ip4.sin_port;
|
||||
|
|
|
@ -52,7 +52,7 @@ typedef struct drawitem_s {
|
|||
fixed_t sy;
|
||||
INT32 num;
|
||||
INT32 digits;
|
||||
const char *str;
|
||||
size_t stroffset; // offset into strbuf to get str
|
||||
UINT16 color;
|
||||
UINT8 strength;
|
||||
INT32 align;
|
||||
|
@ -123,6 +123,10 @@ void LUA_HUD_DestroyDrawList(huddrawlist_h list)
|
|||
{
|
||||
Z_Free(list->items);
|
||||
}
|
||||
if (list->strbuf)
|
||||
{
|
||||
Z_Free(list->strbuf);
|
||||
}
|
||||
Z_Free(list);
|
||||
}
|
||||
|
||||
|
@ -150,7 +154,7 @@ static size_t AllocateDrawItem(huddrawlist_h list)
|
|||
// copy string to list's internal string buffer
|
||||
// lua can deallocate the string before we get to use it, so it's important to
|
||||
// keep our own copy
|
||||
static const char *CopyString(huddrawlist_h list, const char* str)
|
||||
static size_t CopyString(huddrawlist_h list, const char* str)
|
||||
{
|
||||
size_t lenstr;
|
||||
|
||||
|
@ -164,10 +168,10 @@ static const char *CopyString(huddrawlist_h list, const char* str)
|
|||
}
|
||||
|
||||
{
|
||||
const char *result = (const char *) &list->strbuf[list->strbuf_len];
|
||||
strncpy(&list->strbuf[list->strbuf_len], str, lenstr + 1);
|
||||
size_t old_len = list->strbuf_len;
|
||||
strncpy(&list->strbuf[old_len], str, lenstr + 1);
|
||||
list->strbuf_len += lenstr + 1;
|
||||
return result;
|
||||
return old_len;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -280,7 +284,7 @@ void LUA_HUD_AddDrawString(
|
|||
item->type = DI_DrawString;
|
||||
item->x = x;
|
||||
item->y = y;
|
||||
item->str = CopyString(list, str);
|
||||
item->stroffset = CopyString(list, str);
|
||||
item->flags = flags;
|
||||
item->align = align;
|
||||
}
|
||||
|
@ -298,7 +302,7 @@ void LUA_HUD_AddDrawKartString(
|
|||
item->type = DI_DrawKartString;
|
||||
item->x = x;
|
||||
item->y = y;
|
||||
item->str = CopyString(list, str);
|
||||
item->stroffset = CopyString(list, str);
|
||||
item->flags = flags;
|
||||
}
|
||||
|
||||
|
@ -315,7 +319,7 @@ void LUA_HUD_AddDrawLevelTitle(
|
|||
item->type = DI_DrawLevelTitle;
|
||||
item->x = x;
|
||||
item->y = y;
|
||||
item->str = CopyString(list, str);
|
||||
item->stroffset = CopyString(list, str);
|
||||
item->flags = flags;
|
||||
}
|
||||
|
||||
|
@ -343,6 +347,7 @@ void LUA_HUD_DrawList(huddrawlist_h list)
|
|||
for (i = 0; i < list->items_len; i++)
|
||||
{
|
||||
drawitem_t *item = &list->items[i];
|
||||
const char *itemstr = &list->strbuf[item->stroffset];
|
||||
|
||||
switch (item->type)
|
||||
{
|
||||
|
@ -366,38 +371,38 @@ void LUA_HUD_DrawList(huddrawlist_h list)
|
|||
{
|
||||
// hu_font
|
||||
case align_left:
|
||||
V_DrawString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case align_center:
|
||||
V_DrawCenteredString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawCenteredString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case align_right:
|
||||
V_DrawRightAlignedString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawRightAlignedString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case align_fixed:
|
||||
V_DrawStringAtFixed(item->x, item->y, item->flags, item->str);
|
||||
V_DrawStringAtFixed(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
// hu_font, 0.5x scale
|
||||
case align_small:
|
||||
V_DrawSmallString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawSmallString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case align_smallright:
|
||||
V_DrawRightAlignedSmallString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawRightAlignedSmallString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
// tny_font
|
||||
case align_thin:
|
||||
V_DrawThinString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawThinString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case align_thinright:
|
||||
V_DrawRightAlignedThinString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawRightAlignedThinString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
}
|
||||
break;
|
||||
case DI_DrawKartString:
|
||||
V_DrawKartString(item->x, item->y, item->flags, item->str);
|
||||
V_DrawKartString(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case DI_DrawLevelTitle:
|
||||
V_DrawLevelTitle(item->x, item->y, item->flags, item->str);
|
||||
V_DrawLevelTitle(item->x, item->y, item->flags, itemstr);
|
||||
break;
|
||||
case DI_FadeScreen:
|
||||
V_DrawFadeScreen(item->color, item->strength);
|
||||
|
|
Loading…
Reference in a new issue