Question

Here is the objective-c sister question, which might provide some insight: c and objective-c -- const char* and char*

I am doing the following:

g_ADPCMstate.valprev=32767;
g_ADPCMstate.index=0;


const char *modulatedBytes1 = {0xca,0x82,0x00,0x00,0x80,0x80,0x80,0x80};
char *modulatedBytes =  (char *)modulatedBytes1;
unsigned int moduleatedLength = 8;
short *decompressedBytes = NULL;

adpcm_decoder(modulatedBytes, decompressedBytes, moduleatedLength, &g_ADPCMstate);

The function declaration is:

void      
adpcm_decoder(indata, outdata, len, state)      
    char indata[];      
    short outdata[];      
    int len;      
    struct adpcm_state *state; 

g_ADPCMstate is the global instance variable for a adpcm_state struct. http://codepad.org/5vyd0CXA is the full code. The function crashes when *outp++ = valprev; happens and I get a BAD ACCESS statement from my debugger. outp is a pointer to outData while valprev is a long.

The problem has to be in my understanding of pointers and either modulatedBytes and/or decompressedBytes

I have little understanding of C and lower level concepts. I would love some insight into my problem.

Was it helpful?

Solution

You pass short *decompressedBytes = NULL; as the outdata argument to adpcm_decoder(), and then try to dereference it. Did you forget to allocate decompressedBytes?

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top