LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

out-of-bounds pointer argument (past end of array)

I am getting a runtime out of bounds error on the following line:

memset(szTempBuf,0,sizeof(szTempBuf));

char szTempBuf[513] is the definition. It seems that it works sometimes, and other times it has that error always at the same place. I have even had that same error come up at that same line when I changed the line to strcat(ptrMem->szScript,szBuffer);. It seems that after I reboot it usually works OK, for one try. Any ideas? Am I stomping memory somewhere?Should I try more RAM (I currently have 96M)
0 Kudos
Message 1 of 4
(3,301 Views)
hi,
try this:

memset (szTempBuf, 0x0, 513*sizeof(char));

If there is nothing else wrong, it should solve your problem.

luck, flo.
0 Kudos
Message 2 of 4
(3,301 Views)
oups ! sorry my mistake!
it's exactly the same thing. the line is fine. check the pointers allocation and tabs used before this particular line.
A funny thing that happened to me once was that I was writting error messages past the end of my buffer array and it did not bothered CVI at all... but my memory was corrupted past this point and I had strange behaviour on perfectly correct lines of code.
bye, flo
0 Kudos
Message 3 of 4
(3,301 Views)
Sorry, I can't duplicate your error. I can run your memset statement repeatedly with no problems.
The only warning I have is if you memset anything other than 0 to a length of sizeof(szTempBuf), you overwrite the terminating null. So then you'd no longer have a null terminating string (not an 'sz' in your prefixing nominclature). You could still use szTempBuf as an array of char, but it wouldn't be a string. If you want to memset anything other than 0, try sizeof(szTempBuf)-1.
But even if I intentionally overwrite the terminating null, I don't get an out of bounds error. I get other errors when I try to use szTempBuf as a string, but I get no errors on memset.
Could you post a bigger chunk of your code?
0 Kudos
Message 4 of 4
(3,301 Views)