char *ReadString(void)
{
int32_t len; /* length of the string */
char *str = NULL;
/* First, read the length of the string. */
if (!GetNextCode32(&len)) {
PrintError(14, NULL, "ReadString()");
return(NULL);
}
/* create space on heap */
if ((str = (char *) malloc(len*sizeof(char))) == NULL) {
PrintError(15, NULL, "ReadString()");
return(NULL);
}
/* read the string */
if (fread((void *) str, sizeof(char), len, datafile) != len) {
PrintError(15, NULL, "ReadString()");
return(NULL);
}
/* all went well */
/* don't forget to free(str) in calling function */
return(str);
}
#0 0x772b8a76 ntdll!RtlRunOnceBeginInitialize() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#1 0x772a7799 ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#2 0x772a5ec9 ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#3 0x772a5d3e ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#4 0x7734250d ntdll!RtlpNtSetValueKey() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#5 0x772a6dd9 ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#6 0x772a5ec9 ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#7 0x772a5d3e ntdll!RtlAllocateHeap() (C:\WINDOWS\SYSTEM32\ntdll.dll:??)
#8 0x770772a0 msvcrt!malloc() (C:\WINDOWS\System32\msvcrt.dll:??)
#9 0x409904 ReadString() (D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\fileio.c:117)
#10 0x40aa4a ReadFlags(offset=706786) (D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\fileio.c:553)
#11 0x406f45 InitDirs() (D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\dirs.c:92)
#12 0x40d540 main(argc=1, argv=0xbe0dd8) (D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\init.c:286)
Error #1: UNADDRESSABLE ACCESS beyond heap bounds: writing 0x012f3a28-0x012f3a2c 4 byte(s)
# 0 ReadFlags [D:/Marnix/Codeblocks/XVAN 2.4/01 - Interpreter/fileio.c:553]
# 1 InitDirs [D:/Marnix/Codeblocks/XVAN 2.4/01 - Interpreter/dirs.c:92]
# 2 main [D:/Marnix/Codeblocks/XVAN 2.4/01 - Interpreter/init.c:286]
Note: @0:00:06.109 in thread 11816
Note: next higher malloc: 0x012f3a50-0x012f3a54
Note: refers to 0 byte(s) beyond last valid byte in prior malloc
Note: prev lower malloc: 0x012f3a28-0x012f3a28
Note: instruction: mov %eax -> (%ebx)
-------------- Clean: Debug in Interpreter (compiler: GNU GCC Compiler)---------------
Cleaned "Interpreter - Debug"
-------------- Build: Debug in Interpreter (compiler: GNU GCC Compiler)---------------
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\arithmtc.c" -o obj\Debug\arithmtc.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\checkpar.c" -o obj\Debug\checkpar.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\cleanup.c" -o obj\Debug\cleanup.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c" -o obj\Debug\debug.o
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c: In function 'PrintLocationDirectory':
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c:135:28: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int64_t {aka long long int}' [-Wformat=]
sprintf(text_to_print, "\nOffset: %ld\n\n", loc_dir[i].offset);
^
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c: In function 'PrintObjectDirectory':
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c:181:28: warning: format '%ld' expects argument of type 'long int', but argument 3 has type 'int64_t {aka long long int}' [-Wformat=]
sprintf(text_to_print, "\nOffset: %ld\n\n", obj_dir[i].offset);
^
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c: In function 'PrintVerbDir':
D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\debug.c:598:12: warning: format '%ld' expects argument of type 'long int', but argument 2 has type 'int64_t {aka long long int}' [-Wformat=]
printf("offset: %ld\n", verb_dir[i].offset);
^
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\dirs.c" -o obj\Debug\dirs.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\disambig.c" -o obj\Debug\disambig.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\endian.c" -o obj\Debug\endian.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\errors.c" -o obj\Debug\errors.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\execute.c" -o obj\Debug\execute.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\fileio.c" -o obj\Debug\fileio.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\init.c" -o obj\Debug\init.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\input.c" -o obj\Debug\input.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\json.c" -o obj\Debug\json.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\ENG\ENG-article.c" -o obj\Debug\Languages\ENG\ENG-article.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\ENG\ENG-checksyntax.c" -o obj\Debug\Languages\ENG\ENG-checksyntax.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\ENG\ENG-moreinfo.c" -o obj\Debug\Languages\ENG\ENG-moreinfo.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\ENG\ENG-xeqfun.c" -o obj\Debug\Languages\ENG\ENG-xeqfun.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\NL\NL-article.c" -o obj\Debug\Languages\NL\NL-article.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\NL\NL-checksyntax.c" -o obj\Debug\Languages\NL\NL-checksyntax.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\NL\NL-moreinfo.c" -o obj\Debug\Languages\NL\NL-moreinfo.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\Languages\NL\NL-xeqfun.c" -o obj\Debug\Languages\NL\NL-xeqfun.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\lets-try.c" -o obj\Debug\lets-try.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\letsplay.c" -o obj\Debug\letsplay.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\output.c" -o obj\Debug\output.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\readfun.c" -o obj\Debug\readfun.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\readloc.c" -o obj\Debug\readloc.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\readobj.c" -o obj\Debug\readobj.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\readtrig.c" -o obj\Debug\readtrig.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\readverb.c" -o obj\Debug\readverb.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\resglobs.c" -o obj\Debug\resglobs.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\restart.c" -o obj\Debug\restart.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\restore.c" -o obj\Debug\restore.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\save.c" -o obj\Debug\save.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\spanTree.c" -o obj\Debug\spanTree.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\syntax.c" -o obj\Debug\syntax.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\sysfunc.c" -o obj\Debug\sysfunc.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\timers.c" -o obj\Debug\timers.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\trnslate.c" -o obj\Debug\trnslate.o
mingw32-gcc.exe -Wall -g -ILanguages\ENG -ILanguages\NL -I"..\01 - Interpreter" -c "D:\Marnix\Codeblocks\XVAN 2.4\01 - Interpreter\xeqfun.c" -o obj\Debug\xeqfun.o
mingw32-g++.exe -o bin\Debug\Interpreter.exe obj\Debug\arithmtc.o obj\Debug\checkpar.o obj\Debug\cleanup.o obj\Debug\debug.o obj\Debug\dirs.o obj\Debug\disambig.o obj\Debug\endian.o obj\Debug\errors.o obj\Debug\execute.o obj\Debug\fileio.o obj\Debug\init.o obj\Debug\input.o obj\Debug\json.o obj\Debug\Languages\ENG\ENG-article.o obj\Debug\Languages\ENG\ENG-checksyntax.o obj\Debug\Languages\ENG\ENG-moreinfo.o obj\Debug\Languages\ENG\ENG-xeqfun.o obj\Debug\Languages\NL\NL-article.o obj\Debug\Languages\NL\NL-checksyntax.o obj\Debug\Languages\NL\NL-moreinfo.o obj\Debug\Languages\NL\NL-xeqfun.o obj\Debug\lets-try.o obj\Debug\letsplay.o obj\Debug\output.o obj\Debug\readfun.o obj\Debug\readloc.o obj\Debug\readobj.o obj\Debug\readtrig.o obj\Debug\readverb.o obj\Debug\resglobs.o obj\Debug\restart.o obj\Debug\restore.o obj\Debug\save.o obj\Debug\spanTree.o obj\Debug\syntax.o obj\Debug\sysfunc.o obj\Debug\timers.o obj\Debug\trnslate.o obj\Debug\xeqfun.o
Output file is bin\Debug\Interpreter.exe with size 403.39 KB
Process terminated with status 0 (0 minute(s), 5 second(s))
0 error(s), 3 warning(s) (0 minute(s), 5 second(s))
for (i=0; i<nr_of_lflags; i++) {
if ( ((loc_flag_dbug[i]).name = ReadString()) == NULL)
return(ERROR);
if (!GetNextCode32(&(loc_flag_dbug[i]).owner))
return(ERROR);
}
/* Malloc() space for local flags debug info. */
if ((loc_flag_dbug = (debugInfo *) malloc(nr_of_lflags*sizeof(debugInfo))) == NULL) {
PrintError(15, NULL, "local flags debug info");
return(ERROR);
}
if (!GetNextCode32(&len)) {
PrintError(14, NULL, "ReadString()");
return(NULL);
}
/* create space on heap */
if ((str = (char *) malloc(len*sizeof(char))) == NULL) {
int32_t ReadFlags(int64_t offset)
{
int32_t code = NO_ID;
int32_t com_loc_len = 0; /* Length of common location flags string. */
int32_t com_obj_len = 0; /* Length of common object flags string. */
/* Length of local flags string is a global variable for save() function. */
int32_t nr_of_lflags; /* IF I INITIALIZE THIS VAR THE EXTRA LOCAL DECLARATION HAS NO EFFECT */
int i = 0;
int test = 0; /* WITH THIS LINE IT WORKS, IF I REMOVE IT, OR INTIALIZE nr_of_lflags THE PROBLEM RETURNS */
/* go to offset in datafile */
if (fseek(datafile, offset, 0) == -1) {
PrintError(16, NULL, "ReadFlags()");
return(ERROR);
}
/* check for the keyword */
if (!GetNextCode32(&code)) {
PrintError(23, NULL, "keyword record");
return(ERROR);
}
if (code != FLAGS) {
PrintError(21, NULL, "flags");
return(ERROR);
}
/* Read number of common flagbits. */
/* We need the number for the SetBitVal() function. */
if (!GetNextCode32(&nr_of_cflags)) {
PrintError(23, NULL, "nr_of_cflags");
return(ERROR);
}
/* calculate com_loc_len and com_obj_len. */
com_loc_len = ((nr_of_cflags*nr_of_locs)/WORD_LEN)+1;
com_obj_len = ((nr_of_cflags*nr_of_objs)/WORD_LEN)+1;
/* Create space on heap for com_loc_flags. */
if ((com_loc_flags = (int32_t *) malloc(com_loc_len*sizeof(int32_t))) == NULL) {
PrintError(15, NULL, "ReadFlags()");
return(ERROR);
}
/* Create space on heap for com_obj_flags. */
if ((com_obj_flags = (int32_t *) malloc(com_obj_len*sizeof(int32_t))) == NULL) {
PrintError(15, NULL, "ReadFlags()");
return(ERROR);
}
/* Read the com_loc_flags. */
if (fread((void *) com_loc_flags, sizeof(int32_t), com_loc_len, datafile)
!= com_loc_len) {
PrintError(23, NULL, "common location flags");
return(ERROR);
}
/* Read the com_obj_flags. */
if (fread((void *) com_obj_flags, sizeof(int32_t), com_obj_len, datafile)
!= com_obj_len) {
PrintError(23, NULL, "common object flags");
return(ERROR);
}
/* Read length of local flagbits string. */
/* We don't need the actual number of local flags. */
if (!GetNextCode32(&loc_flags_string_len)) {
PrintError(23, NULL, "loc_flags_string_len");
return(ERROR);
}
/* Create space on heap. */
if ((local_flags = (int32_t *) malloc(loc_flags_string_len*sizeof(int32_t))) == NULL) {
PrintError(15, NULL, "ReadFlags()");
return(ERROR);
}
/* read the information */
if (fread((void *) local_flags, sizeof(int32_t), loc_flags_string_len, datafile)
!= loc_flags_string_len) {
PrintError(23, NULL, "local flags");
return(ERROR);
}
/* Check if we must read debug info */ /* @@ */
if (debug) {
/* check for the keyword */
if (!GetNextCode32(&code)) {
PrintError(23, NULL, "keyword record");
return(ERROR);
}
if (code != DEBUG) {
PrintError(21, NULL, "debug");
return(ERROR);
}
/* Malloc() space for common flags debug info. */
if ((com_flag_dbug = (debugInfo *) malloc(nr_of_cflags*sizeof(debugInfo))) == NULL) {
PrintError(15, NULL, "common flags debug info");
return(ERROR);
}
/* Malloc() space for local flags debug info. */
if ((loc_flag_dbug = (debugInfo *) malloc(nr_of_lflags*sizeof(debugInfo))) == NULL) {
PrintError(15, NULL, "local flags debug info");
return(ERROR);
}
for (i=0; i<nr_of_cflags; i++) {
if ( ((com_flag_dbug[i]).name = ReadString()) == NULL)
return(ERROR);
}
/* read the number of local flags */
/* is is only needed when we have debug info */
if (!GetNextCode32(&nr_of_lflags)) {
PrintError(23, NULL, "nr_of_lflags");
return(ERROR);
}
for (i=0; i<nr_of_lflags; i++) {
if ( ((loc_flag_dbug[i]).name = ReadString()) == NULL) /* THIS rEADsTRING() CALL FAILS */
return(ERROR);
if (!GetNextCode32(&(loc_flag_dbug[i]).owner))
return(ERROR);
}
}
return(OK);
}
You are going to have to wait for an CB Debugging person. They will likely ask for a full debugging log.If you want to get help you have to accomplish this.
That's an indication of memory corruption. It's quite easy to do with C using malloc etc. It just hides problems so easily. And the best part is that the actual problem may not even be in that part of the code.Yes. this are very strong signs for this kind of error:
- if I declare one additional local variable in the function that calls the failing ReadString() it works.
- but if, additionaly to the extra declaration, I initialize the nr_of_lflags var it crashes again.