Fix debug header size miscalculation
This commit is contained in:
parent
568c277b03
commit
a2a8039e69
@ -54,6 +54,7 @@ int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, FILE *fp)
|
|||||||
{
|
{
|
||||||
AMX_HEADER amxhdr;
|
AMX_HEADER amxhdr;
|
||||||
AMX_DBG_HDR dbghdr;
|
AMX_DBG_HDR dbghdr;
|
||||||
|
size_t size;
|
||||||
unsigned char *ptr;
|
unsigned char *ptr;
|
||||||
int index, dim;
|
int index, dim;
|
||||||
AMX_DBG_LINE *line;
|
AMX_DBG_LINE *line;
|
||||||
@ -121,7 +122,8 @@ int AMXAPI dbg_LoadInfo(AMX_DBG *amxdbg, FILE *fp)
|
|||||||
|
|
||||||
/* load the entire symbolic information block into memory */
|
/* load the entire symbolic information block into memory */
|
||||||
memcpy(amxdbg->hdr, &dbghdr, sizeof dbghdr);
|
memcpy(amxdbg->hdr, &dbghdr, sizeof dbghdr);
|
||||||
if (fread(amxdbg->hdr + 1, 1, (size_t)(dbghdr.size - sizeof dbghdr), fp) == 0) {
|
size=(size_t)(dbghdr.size - sizeof dbghdr);
|
||||||
|
if (fread(amxdbg->hdr + 1, 1, size, fp) < size) {
|
||||||
dbg_FreeInfo(amxdbg);
|
dbg_FreeInfo(amxdbg);
|
||||||
return AMX_ERR_FORMAT;
|
return AMX_ERR_FORMAT;
|
||||||
} /* if */
|
} /* if */
|
||||||
|
@ -1119,7 +1119,7 @@ static void append_dbginfo(FILE *fout)
|
|||||||
if (prevstr!=NULL) {
|
if (prevstr!=NULL) {
|
||||||
assert(prevname!=NULL);
|
assert(prevname!=NULL);
|
||||||
dbghdr.files++;
|
dbghdr.files++;
|
||||||
dbghdr.size+=sizeof(cell)+strlen(prevname)+1;
|
dbghdr.size+=sizeof(AMX_DBG_FILE)+strlen(prevname);
|
||||||
} /* if */
|
} /* if */
|
||||||
previdx=codeidx;
|
previdx=codeidx;
|
||||||
} /* if */
|
} /* if */
|
||||||
@ -1130,7 +1130,7 @@ static void append_dbginfo(FILE *fout)
|
|||||||
if (prevstr!=NULL) {
|
if (prevstr!=NULL) {
|
||||||
assert(prevname!=NULL);
|
assert(prevname!=NULL);
|
||||||
dbghdr.files++;
|
dbghdr.files++;
|
||||||
dbghdr.size+=sizeof(cell)+strlen(prevname)+1;
|
dbghdr.size+=sizeof(AMX_DBG_FILE)+strlen(prevname);
|
||||||
} /* if */
|
} /* if */
|
||||||
|
|
||||||
/* line number table */
|
/* line number table */
|
||||||
@ -1149,9 +1149,12 @@ static void append_dbginfo(FILE *fout)
|
|||||||
assert(str[0]!='\0' && str[1]==':');
|
assert(str[0]!='\0' && str[1]==':');
|
||||||
if (str[0]=='S') {
|
if (str[0]=='S') {
|
||||||
dbghdr.symbols++;
|
dbghdr.symbols++;
|
||||||
name=strchr(str+2,':');
|
name=skipwhitespace(strchr(str+2,':')+1);
|
||||||
assert(name!=NULL);
|
assert(name!=NULL);
|
||||||
dbghdr.size+=sizeof(AMX_DBG_SYMBOL)+strlen(skipwhitespace(name+1));
|
str=strchr(name,' ');
|
||||||
|
assert(str!=NULL);
|
||||||
|
assert((int)(str-name)<sizeof symname);
|
||||||
|
dbghdr.size+=sizeof(AMX_DBG_SYMBOL)+(str-name);
|
||||||
if ((prevstr=strchr(name,'['))!=NULL)
|
if ((prevstr=strchr(name,'['))!=NULL)
|
||||||
while ((prevstr=strchr(prevstr+1,':'))!=NULL)
|
while ((prevstr=strchr(prevstr+1,':'))!=NULL)
|
||||||
dbghdr.size+=sizeof(AMX_DBG_SYMDIM);
|
dbghdr.size+=sizeof(AMX_DBG_SYMDIM);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user