I am manipulating a C code which requires me to extract a value, perform calculations and put the value back in the original variable.
The task of putting back the value causes the error:
Run-time check failiure-Stack around variable 'x' was corrupted.
Here's the code:
int RBSPtoNALU (unsigned char *rbsp, NALU_t *nalu, int rbsp_size, int nal_unit_type, int nal_reference_idc, int UseAnnexbLongStartcode)
{
int len;
int num = nalu->buf; ***//nalu->buf is the information i am extracting***
int r = 0,newnum=0;
while (num > 0) ***// Doing a simple reverse operation***
{
r = num % 10;
newnum = newnum * 10 + r;
num =(num/10);
}
byte x = newnum;
printf("x is in c %c \n", x);
printf("x is in d %d \n \n \n", x); getchar();
nalu->buf = &x; ***// My efforts end here***
assert (nalu != NULL);
assert (nal_reference_idc <=3 && nal_reference_idc >=0);
#if (MVC_EXTENSION_ENABLE)
assert (nal_unit_type > 0 && nal_unit_type <= NALU_TYPE_SLC_EXT);
#else
assert (nal_unit_type > 0 && nal_unit_type <= NALU_TYPE_FILL);
#endif
assert (rbsp_size < MAXRBSPSIZE);
nalu->startcodeprefix_len = UseAnnexbLongStartcode ? 4 : 3;
nalu->forbidden_bit = 0;
nalu->nal_reference_idc = (NalRefIdc) nal_reference_idc;
nalu->nal_unit_type = (NaluType) nal_unit_type;
#if (MVC_EXTENSION_ENABLE)
if(nal_unit_type==NALU_TYPE_PREFIX || nal_unit_type==NALU_TYPE_SLC_EXT)
{
nalu->svc_extension_flag = 0;
//nalu->non_idr_flag = (nal_reference_idc==NALU_PRIORITY_HIGHEST) ? 0:1;
nalu->reserved_one_bit = 1;
}
else
nalu->svc_extension_flag = 0;
endif
len = RBSPtoEBSP (nalu->buf, rbsp, rbsp_size);
nalu->len = len;
printf("length len is %d", len); printf("\n \n");
return len;
} ***//end of code***
nalu is an instance of the struct NALU_t with the following definition:
typedef struct nalu_t
{
int startcodeprefix_len; //!< 4 for parameter sets and first slice in picture, 3 for everything else (suggested)
unsigned len; //!< Length of the NAL unit (Excluding the start code, which does not belong to the NALU)
unsigned max_size; //!< NAL Unit Buffer size
int forbidden_bit; //!< should be always FALSE
NaluType nal_unit_type; //!< NALU_TYPE_xxxx
NalRefIdc nal_reference_idc; //!< NALU_PRIORITY_xxxx
***byte *buf;*** //!< contains the first byte followed by the EBSP
uint16 lost_packets; //!< true, if packet loss is detected
#if (MVC_EXTENSION_ENABLE)
int svc_extension_flag; //!< should be always 0, for MVC
int non_idr_flag; //!< 0 = current is IDR
int priority_id; //!< a lower value of priority_id specifies a higher priority
int view_id; //!< view identifier for the NAL unit
int temporal_id; //!< temporal identifier for the NAL unit
int anchor_pic_flag; //!< anchor access unit
int inter_view_flag; //!< inter-view prediction enable
int reserved_one_bit; //!< shall be equal to 1
#endif
} NALU_t;
buf is a pointer reference to byte which is a struct defined as follows:
typedef unsigned char byte;