Note that there are some explanatory texts on larger screens.

plurals
  1. POAccess violations on string operations in Delphi
    primarykey
    data
    text
    <p>I have a Delphi application that reads data form a file and stores it in an array. Each row in a file contains an address, lineTypeIndicator and data. This is the algorithm (contains code that I believe is critical):</p> <pre><code>AssignFile(inputFile, inFileName); Reset(inputFile); while not EOF(inputFile) do begin Readln(inputFile,fileLineBuffer); if Copy(fileLineBuffer, 8, 2) = '01' then //Never managed to catch the error here begin break; end; //extract the address from the line and use it to determine max and min address. end; //Now that you have min and max address, use it to set the length of an char array SetLength(memoryArray,(lastAddress - firstAddress) * 2); Reset(inputFile); while not EOF(inputFile) do begin Readln(inputFile,fileLineBuffer); if Copy(fileLineBuffer, 8, 2) = '01' then //I caught all the errors here begin break; end; //extract the address and data from the fileLineBuffer and place it in the corresponding place in an array end; </code></pre> <p>This code is executed every time the user clicks the corresponding button on a form. It runs the first few times it is executed, but then after a few runs i get this:</p> <blockquote> <p>MyProgram.exe faulted with message: 'access violation at 0x00406111: write of address 0x00090d1c (this varies). Proceess stopped. Use step or run to continue.</p> </blockquote> <p>To me, this smells like some kind of heap overflow. I have tried replacing </p> <pre><code>if Copy(fileLineBuffer, 8, 2) = '01' then </code></pre> <p>with</p> <pre><code>lineTypeBuffer := Copy(fileLineBuffer, 8, 2); if lineTypeBuffer = '01' then </code></pre> <p>or</p> <pre><code>if (fileLineBuffer[8] = '0') and (fileLineBuffer[9] = '1') then </code></pre> <p>but it did not help. Any suggestions on how I should approach this problem?</p> <p>P.S. Tried running it on Win7 32 bit and Win7 64 bit - no difference P.P.S. sorry for the long question.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload