LabWindows/CVI

cancel
Showing results for 
Search instead for 
Did you mean: 

out-of-bounds pointer arithmetic

// Bert Brahmer
// Voith Turbo H+L
// bert.brahmer@voith.com
// 2007-08-01
//
// The following code will compile fine
// But there will be a runtime error
// I know well that the coding style is not what we consider nice.
// The code is machine generated (simulation environment)
// I can not change the code - I must get it running with no
// source changes allowed under CVI 6.0
//
// Any suggestions ?
struct {
 double a;
 double b;
 double c;
} Data;
void foo ( void )
{
 double * ptr;
 
 ptr = & Data.a;
 
 *ptr++ = 1.2;
 *ptr++ = 3.4; // Here, the runtime error "out-of-bounds pointer.." will apperar
 *ptr = 5.6;
}
0 Kudos
Message 1 of 7
(5,080 Views)

Have you tried compiling for a Release Build, instead of a Debug one? This problem may be due to incorrect operation of the CVI debug system and may well disappear in Release mode.

JR

0 Kudos
Message 2 of 7
(5,073 Views)
Hi Bert,

Actually, the runtime error is legitimate. You are taking the address of a double (think of it as an array of 1), then incrementing past that double, which is out of bounds.  Depending on structure packing, the elements may not even be completely contiguous, and the compiler is not going to let you treat members in a structure as if they were elements in an array.  What if Data.b was an int instead of a double?

Given that you can't change the code, you can avoid the runtime error by compiling in Release mode, turning off runtime error checking in Options>>Build Options, or using "Enable 'O' Option" on the particular .c file to compile it without debugging info.

Hope this helps.

Mert A.
National Instruments
Message 3 of 7
(5,073 Views)

Hi JR, Mert

Thanks for directing me towards "release mode". Yes, indeed: the code will compile and run o.k. in release mode. At least, looking at my log file outputs. I might be able to live with that code in release mode (no debugging). But I need to debug the rest of the application framework.

So far, I could not manage to compile the project with some files in debug and other files in release mode.

Any help on this one ?

Again, thanks a lot!

Bert

P.S.: obviously, the code in question is generated with some older K&R style in mind. In these good (?) old days, anything was possible... The strong runtime checking of CVI has helped me a lot in past projects. But in this case, I would like to turn it off.

0 Kudos
Message 4 of 7
(5,053 Views)
Well, in my last post I mentioned compiling your source file with the 'O' option, which sounds like what you want.  You can set this option on specific files in your project, and it causes them to be compiled without debugging info.  In CVI 7.1 and later, I know this option can be set from the Edit menu or by right-clicking source files in the project tree. I don't recall exactly where this option lives in CVI 6.0, but if you search the help for the Enable 'O' Option topic, you should be able to find it.

If you have trouble, let me know.

Mert A.
National Instruments
Message 5 of 7
(5,040 Views)
Bert / Mert,

In CVI 6.0, the "Enable 'O' option" terminology was not used. To accomplish this in 6.0, go to your project window, look for a column labeled 'O' in the middle section of the window, and double-click under that option next to the file for which you want to disable debugging.

Luis
Message 6 of 7
(5,034 Views)

Gentlemen,

Now I managed to switch off runtime checking selectively (O Option). I got what I needed.

Thanks to the community

0 Kudos
Message 7 of 7
(5,020 Views)