我已经声明了这样的双指针
UInt8 **contentKeyCtx;
Run Code Online (Sandbox Code Playgroud)
此变量作为参数发送到函数内部函数中有局部变量
UInt8 *localckc = NULL;
localckc = calloc(1, localckcSize);
Run Code Online (Sandbox Code Playgroud)
然后分配了一些值数组 localckc
当我尝试这样做
*contentKeyCtx = localckc;
Run Code Online (Sandbox Code Playgroud)
我得到了分段错误
我做错了什么?主功能
int main (int argc, char *argv[])
{
OSStatus result; // SInt32
UInt8 *inBuff, *outBuff;
UInt32 inBuffSize, outBuffSize;
UInt8 **contentKeyCtx = calloc(1, sizeof(UInt8**));
UInt32 *contentKeyCtxSize;
FILE *fp;
const UInt8 *assetId = {0x1b, 0xf7, 0xf5, 0x3f, 0x5d, 0x5d, 0x5a, 0x1f};// what is this?
inBuff=calloc(1,INBUFFSIZE);
outBuff=calloc(1,OUTBUFFSIZE);
inBuffSize = fread(inBuff, sizeof(UInt8), INBUFFSIZE, fp);
fclose(fp);
// IK we have some data. Now what?
result = SKDServerGenCKC(inBuff, inBuffSize, assetId, contentKeyCtx, contentKeyCtxSize);
free(inBuff);
free(outBuff);
printf("Result is %d\n", result );
return 0;
}
Run Code Online (Sandbox Code Playgroud)
实际功能实施
OSStatus SKDServerGenCKC(
const UInt8 *serverPlaybackCtx,
UInt32 serverPlaybackCtxSize,
const UInt8 *assetId,
UInt8 **contentKeyCtx,
UInt32 *contentKeyCtxSize)
{
UInt8 *localckc = NULL;
UInt32 localckcSize = 0;
PS_RequireAction(ckcContainer != NULL, return kDRMSKDServerParamErr;)
PS_RequireAction(contentKeyCtx != NULL, return kDRMSKDServerParamErr;)
PS_RequireAction(contentKeyCtxSize != NULL, return kDRMSKDServerParamErr;)
...
localckc = calloc(1, localckcSize);
status = SKDServerWriteBytes(
&ckcContainer->parser.currentOffset, PS_AES128_IV_SZ,
ckcContainer->aesKeyIV, localckcSize, localckc);
...
*contentKeyCtx = localckc;
}
Run Code Online (Sandbox Code Playgroud)
您现在提供的功能实现与您对问题的原始描述有很大不同.现在很清楚,涉及的指针contentKeyCtx是函数参数,而不是本地或文件范围变量,代码显示它被用于将函数计算的指针传递回函数的调用者.
在这种情况下,函数调用的相应实际参数应该是一个适当类型的变量的地址,函数将在其中存储生成的指针值,如下所示:
UInt8 *contentKeyCtx;
UInt32 contentKeyCtxSize = 0;
OSStatus status;
status = SKDServerGenCKC(..., &contentKeyCtx, &contentKeyCtxSize);
Run Code Online (Sandbox Code Playgroud)
类似适用于最后一个参数,如图所示; 它显然用于返回返回指针所指向的空间的大小.