Hi,
I'm trying to assign variables where vpSec0 points.
void * vpSec0 = NULL;
CreateHVFESection0(vpSec0);
CreateHVFESection0 function is below.
void CreateHVFESection0(void * vpSec0)
{
int hSec0;
size_t * nbytes = (size_t *) malloc(sizeof(size_t));
hSec0 = bitio_o_open();
/* 'B','U','F','R' */
bitio_o_append(hSec0,66,8);
bitio_o_append(hSec0,85,8);
bitio_o_append(hSec0,70,8);
bitio_o_append(hSec0,82,8);
/* Total length of BUFR message in bytes */
bitio_o_append(hSec0,0,24);
/* BUFR Edition Number = 4 */
bitio_o_append(hSec0,4,8);
vpSec0 = bitio_o_close(hSec0, nbytes);
free(nbytes);
nbytes = NULL;
}
CreateHVFESection0 uses some other functions. But I think the problem is here:
vpSec0 = bitio_o_close(hSec0, nbytes);
because i run the program with gdb debugger. Before coming here, vpSec0 is 0x0, means NULL. Everything is normal to here.
void *bitio_o_close (handle, nbytes)
int handle;
size_t *nbytes;
/* This function closes a output-bitstream identified by HANDLE and returns
a pointer to the memory-area holding the bit-stream.
parameters:
HANDLE: Bit-stream-handle
NBYTES: number of bytes in the bitstream.
The funcion returns a pointer to the memory-area holding the bit-stream or
NULL if an invalid handle was specified. The memory area must be freed by
the calling function.
*/
{
if (!bios[handle].used) return NULL;
/******* Fill up the last byte with 0-bits */
while (bios[handle].nbits % 8 != 0) bitio_o_append (handle, 0, 1);
*nbytes = (size_t) ((bios[handle].nbits - 1) / 8 + 1);
bios[handle].used = 0;
return (void *) bios[handle].buf;
}
void *bitio_o_close (handle, nbytes)
int handle;
size_t *nbytes;
/* This function closes a output-bitstream identified by HANDLE and returns
a pointer to the memory-area holding the bit-stream.
parameters:
HANDLE: Bit-stream-handle
NBYTES: number of bytes in the bitstream.
The funcion returns a pointer to the memory-area holding the bit-stream or
NULL if an invalid handle was specified. The memory area must be freed by
the calling function.
*/
{
if (!bios[handle].used) return NULL;
/******* Fill up the last byte with 0-bits */
while (bios[handle].nbits % 8 != 0) bitio_o_append (handle, 0, 1);
*nbytes = (size_t) ((bios[handle].nbits - 1) / 8 + 1);
bios[handle].used = 0;
return (void *) bios[handle].buf;
}
when i step into bitio_o_close function, before
return (void *) bios[handle].buf
, the address of bios[handle].buf is 0x2a99700930. So we expect that after returning, vpSec0's address will also be 0x2a99700930. But after returning when i print vpSec0, it's address seems 0xffffffff99700930, and this is out of bounds which falls me in Segmentation faults further in my program.
Please help.
Thanx.