LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

Error Out-of-bounds pointer argument (before start of array)

Hello everyone,

I'm getting a fatal run-time error, Out-of-bounds pointer argument (before start of array). I have looked at previous post and haven't found a solution. I know there is a post asking about the same exact problem but I still don't understand what is going wrong. The gist of the program is it basically parses data files and populates an excel file. I can run this program with zero errors on a different batch of data files. The error occurs in the for loop and is repeatable and occurs on the same iteration, index = 15. Any ideas? 

 

FileListArray = (char **)malloc(count_files * sizeof(char *));

for(index =0; index < count_files; index++)
{
FileListArray[index] = (char *)malloc(40*sizeof(char));
}

 

... 

 for (index = 0; index < count_files; index++)
{
Fmt(data_file_name, "%s<%s", FileListArray[index]);

in_file = OpenFile(data_file_name, VAL_READ_ONLY, VAL_OPEN_AS_IS, VAL_ASCII);

...

 

Thanks.

0 Kudos
Message 1 of 9
(4,564 Views)

Hi Tim\n,

Thanks for posting on the discussion board with your code and the pointer argument. I did have a few follow up questions to try to narrow the issue.

 

Is this the previous post you were referring to?

 

http://forums.ni.com/t5/LabWindows-CVI/Error-Out-of-bounds-pointer-argument-before-start-of-array/td...

 

Additionally, the copy paste is helpful but could you also send screenshots of the errors you're recieving?

 

Are you able to run different programs within the parse data file that has nothing to do with Excel and does it function properly at index = 15?

 

Does the error not appear on different data files? 

Regards,

Ali S.
Applications Engineering
National Instruments
0 Kudos
Message 2 of 9
(4,515 Views)

Hi ali.s,

Correct, that is the post I am referring to in my original post.

CVI 6 is what we are using at work.  Here is a screen shot of the source code and error:Capture.PNG

 

I get the same error in a diffrerent project on the same data files, but it uses the same code. It also stops on index = 15. This program is automating picture pasting to powerpoint:

Capture1.PNG

 

The error does not happen on a different set of data files. It looks to be dependent on a particular set of data files but I have no clue why.

Thanks for your response ali.s.

 

Tim

0 Kudos
Message 3 of 9
(4,511 Views)

I think your calls to Fmt() may be a problem.  You are formatting for two string arguments, but only providing one.  Thus, your second argument is undefined and weirdness ensues.

 

You may get more information by setting your compiler warnings level higher than you currently have it.

0 Kudos
Message 4 of 9
(4,410 Views)

@S2rt wrote:

I think your calls to Fmt() may be a problem.  You are formatting for two string arguments, but only providing one.  Thus, your second argument is undefined and weirdness ensues.

 

You may get more information by setting your compiler warnings level higher than you currently have it.


Can you please explain the formatting that I'm doing wrong? I looked over the Fmt() function in the help section but couldn't understand what you mean. Fmt() doesn't return an error -1, it returns 1. 

How do I raise the warning level? 

 

Thanks.

Tim

0 Kudos
Message 5 of 9
(4,303 Views)

In the format command (Fmt) your format string is "%s<%s". From the Fmt() help page, "If a target data type other than string is desired, the format string must begin with the specifier of the desired target type, followed by the "‹" symbol, followed by the source specifiers."  You have provided two string specifiers, so I can't really say what will happen at run time (perhaps a run-time error?).   If you had provided a second string argument I would expect your formatted string to be, "string1<string2". Try changing your format string to "%s". You may have to explicitly add a null terminator to your string, "%s\0".

You can step through the program in debug mode and use the Watch window to see how the string is actually formatted.

 

Warning level: Options->Build Options->Compiler Warnings (or something similar - I'm using CVI2013).

0 Kudos
Message 6 of 9
(4,295 Views)

I think by string1 and string 2 you mean sources. From the help menu:

Formatting Functions

The character '<' serves as a visual reminder of the direction of the data transformation from the sources to the target and separates the single target format specifier from the source format specifiers and literals. You can omit the target format specifier, in which case the functions assume a %s string format. If you omit the target format specifier, you can omit the '<' character or retain it for clarity.

Notice that the target format specifier is located to the left of the '<' symbol, just as the target parameter is located to the left of the format string. Likewise, the source format specifiers are located to the right of the '<' symbol, just as the source parameters are located to the right of the format string.

From my understanding the < arrow serperates source from target. I can omit it like you mention but the same error occurs. I changed the compiler warnings to agressive and check marked all boxes. Project compiles fine  and I checked the variable window and the strings look fine in the variable window. 

According to the help menu the comment on the error is as follows:

Run-time Errors and Warnings

 

Pointer expression you passed to the library function is invalid because it refers to a location that is before the start of an array. The expression is probably the result of previous illegal pointer arithmetic.

 

So some place I did some illegal pointer arithmetic, maybe in the FileListArray...

 

 

0 Kudos
Message 7 of 9
(4,284 Views)

Are you sure your file names can never get longer than 39 chars? That would seem pretty low for a full filepath!

 

You also don't show the declaration of data_file_name. Is it long enough?

 

And I'm not understanding why you have this line in the code:

Fmt(data_file_name, "%s<%s", FileListArray[index]);

 

You could simply pass FileListArray[index] as filename to the OpenFile() function.

Rolf Kalbermatter
My Blog
0 Kudos
Message 8 of 9
(4,258 Views)

@rolfk wrote:

Are you sure your file names can never get longer than 39 chars? That would seem pretty low for a full filepath!

 

You also don't show the declaration of data_file_name. Is it long enough?

 

And I'm not understanding why you have this line in the code:

Fmt(data_file_name, "%s<%s", FileListArray[index]);

 

You could simply pass FileListArray[index] as filename to the OpenFile() function.


40 chars should be ok, the file name is a set amount of characters an example of a file names is (38+\0):

xxxxxxxxxxxxx-xxxx_xxx_xx_xx_xxxxx.txt

It should only have to be long enough for the file name correct? I set the directory by SetDir().

 

data_file_name is decalared as data_file_name[MAX_FILENAME_LEN];

 

You are are right it's an uncessary step. I commented it out  and changed it like you recommended. Now the same error appears on a different line and variable. The declaration is: dev_id[20]={'\0'};. I use the variable window to view dev_id and it's ok. 

How can I find where the pointer arithmetic is going wrong?

 

Thanks.

0 Kudos
Message 9 of 9
(4,244 Views)