Different unallocated memory behavior between versions of Visual Studio

I have a strange situation. I have been trying to implement a camera SDK 10 with over 10 years ago in my camera management software. Manifacturer is no longer in business, and I have no chance of receiving official assistance. So, I'm here, looking for some help in my ugly problem.

SDK comes with samples Visual Studio 6.0. One of the include files has a structure ending in a single byte array, as shown below:

typedef struct AVData {
    ...  
    BYTE audioVideoData[1];
}AVDATA, *PAVDATA;

But this dedicated byte array of bytes accepts video frames and is rather strange; it works fine with Visual Studio 6.0. If I try it with Visual Studio 2005/2008/2010, I will start to receive error messages Memory Access Violationthat make sense, since after that space for an array with a fixed size cannot be allocated, no? But does the same code work fine with VS 6.0 ?! This is probably due to differences in the runtime of the compiler or C ++, but I am not very versed in this topic, so it’s hard for me to say a specific reason.

I tried resizing to the expected maximum number of bytes, as shown below:

typedef struct AVData {
    ...  
    BYTE audioVideoData[20000];
}AVDATA, *PAVDATA;

This helped it to work, but from time to time I get problems with memory access when trying to destroy the library decoder object.

- . SDK, DLL, Lib Header. :

1) Visual Studio 6.0?

2) - ( ..), VS/++?

3) , , - ?

+5
3

IIRC , , .

struct {
  int len;
  char name[1];
} s;

"name" , , :

char* foo = "abc";
int len = strlen(foo);

struct s* p = malloc( sizeof(int) + len + 1 );

p->len = len;
strcpy(p->name, foo );

, visual studio, , , #pragma pack (1), ? , VS6 .

+3

C, , , . ( Windows . BITMAPINFO.)

- (, ), , . , , :

int size = /* calculate frame size somehow */
AVDATA * data = (AVDATA*) malloc(sizeof(AVDATA) + size);
// use data->audioVideoData
+3

The code will almost certainly exhibit undefined behavior in some way, and there is no way to fix this except to fix the interface or source code of the SDK. Since this is no longer in business, it is impossible.

+1
source

All Articles