After getting Cell Info, EXC_BAD_ACCESS is thrown

情到浓时终转凉″ 提交于 2019-12-10 23:06:10

问题


I'm using CellStumbler to obtain the iPhone's cell ID, location area code and other information.

After calling getInfo, I'm getting an EXC_BAD_ACCESS and I can't figure out why. This is all undocumented private functions, but certainly someone can help. The problem isn't associated with any of the lines in the function, it's only after running it that it happens.

Cell Stumbler

I'm aware this isn't App Store approvable.

  int cellcount;
_CTServerConnectionCellMonitorGetCellCount(&t1,sc,&cellcount);

printf("Cell count: %x\n",cellcount);

printf("Size = %lx\n", sizeof(struct CellInfo));

unsigned char *a=malloc(sizeof(struct CellInfo));

for(b=0;b<cellcount;b++)
{       
    _CTServerConnectionCellMonitorGetCellInfo(&t1,sc,b,a); memcpy(&cellinfo,a,sizeof(struct CellInfo));
    printf("Cell Site: %d, MNC: %d, ",b,cellinfo.servingmnc);
    printf("Location: %d, Cell ID: %d, Station: %d, ",cellinfo.location, cellinfo.cellid, cellinfo.station);
    printf("Freq: %d, RxLevel: %d, ", cellinfo.freq, cellinfo.rxlevel);
    printf("C1: %d, C2: %d\n", cellinfo.c1, cellinfo.c2);
}
if(a) free(a);

This is the getCellInfo function available in the CellStumbler project above. The error occurs after this is called, but not necessarily in this function, only after, as if an after effect of running this is some memory mangling.


回答1:


I've temporarily solved this problem, by removing the for loop and only running _CTServerConnectionCellMonitorGetCellInfo once.



来源:https://stackoverflow.com/questions/8532677/after-getting-cell-info-exc-bad-access-is-thrown

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!