Get rid of these 3 Cocos2D analyzer warnings? - ios

I hate warnings anywhere in my app so I fixed all of the other Cocos2D analyzer warnings except these three which I do not know how to solve.
Anyway, hopefully somewhat here can help me resolve these 3 warnings! The line with the warning is the one with the comment before it saying "This Line"
One Function call argument is an uninitialized value
-(void)update:(ccTime)time
{
int i, j;
Tile *tileArray = (Tile*)tiles;
for( i = 0; i < gridSize_.x; i++ )
{
for( j = 0; j < gridSize_.y; j++ )
{
//This Line tileArray->position = ccpMult( ccp(tileArray->delta.x, tileArray->delta.y), time);
[self placeTile:ccg(i,j) tile:*tileArray];
tileArray++;
}
}
}
Two The left operand of '*' is a garbage value
// color
p->color.r += (p->deltaColor.r * dt);
p->color.g += (p->deltaColor.g * dt);
//This Line p->color.b += (p->deltaColor.b * dt);
p->color.a += (p->deltaColor.a * dt);
Three Assigned value is garbage or undefined
void cc_pointerswap(void* a, void* b, size_t width)
{
void* tmp;
tmp = *(void**)a;
//This Line *(void**)a = *(void**)b;
*(void**)b = tmp;
}

Related

double datatype behaving in an undefined manner

Even though I know turbo c is completely obsolete now, my instructor has put a condition to code in it.
I am having an issue that when I am trying to pass a double value to a function it is not behaving properly. I am getting fluctuating output several of the time, sometimes even weird. Let's see my code first:
#include<stdio.h>
#include<conio.h>
double func(double input) {
return input * input;
}
double simpson1By3(double initial, double final, double parts) {
double sum = 0;
double h = (final - initial) / parts;
double oddSum = 0, evenSum = 0;
int i;
printf("%f %f %f\n", initial, final, parts);
printf("%f\n", h);
printf("%f %f\n", evenSum, oddSum);
sum += func(initial) + func(final);
printf("%f %f\n", evenSum, oddSum);
for (i = 1; i < parts; i = i + 2) {
oddSum += func(initial + (i * h));
}
for (i = 2; i < parts; i = i + 2) {
evenSum += func(initial + (i * h));
}
oddSum *= 4;
evenSum *= 2;
printf("%f %f\n", evenSum, oddSum);
sum += evenSum + oddSum;
sum *= h / 3;
return sum;
}
int main() {
clrscr();
printf ("%f", simpson1By3(0, 6, 6));
getch();
return 0;
}
sample output:
What am I doing wrong there? Why are the arguments passed printed erroneously there along with other variables there and why is that -0 printing? Please help. I have tried finding something similar to it in forums but completely failed. Please help.

EXC_BAD_ACCESS on double array

writing an objective c (with c low level functionality) function to detect pitch. Getting a EXC_BAD_ACCESS code=2 on the line "w[i] = i;" in the first for loop. In our iteration, numberofSamples = 32768. The Error occurs in the first loop after i = 16332. For some reason after filling about half of the array, the pointer is no longer valid. Single threaded app, nothing else should be messing around with stuff while this is running. I was wondering if there were any fundamental errors in this setup that could cause this pointer error. I can provide more detail as requested. Thanks!
NSArray* getMainFrequency(NSMutableArray *input,int numberOfSamples){
const int log2n = log(numberOfSamples)/log(2);
const int n = 1 << log2n;
const int nOver2 = n / 2;
int sFreq=44100;
double fFreq=0,maxMag=0,realFreq=0,t,alpha=0.6;
double mag[n/2+1],dblInput[numberOfSamples],w[numberOfSamples];
FFTSetupD fftSetup = vDSP_create_fftsetupD (log2n, kFFTRadix2);
for(int i=0;i<numberOfSamples;i++){
dblInput[i]=[input[i] doubleValue];
w[i] = i;
}
DSPDoubleSplitComplex fft_data;
fft_data.realp = malloc(nOver2 * sizeof(double));
fft_data.imagp = malloc(nOver2 * sizeof(double));
vDSP_ctozD((DSPDoubleComplex *)dblInput, 2, &fft_data, 1, nOver2);
vDSP_fft_zripD (fftSetup, &fft_data, 1, log2n, kFFTDirection_Forward);
for (int i = 0; i < nOver2; ++i){
fft_data.realp[i] *= 0.5;
fft_data.imagp[i] *= 0.5;
}
for (int i = 48; i < 2974; ++i){
mag[i]=pow((pow(fft_data.realp[i],2)+pow(fft_data.imagp[i],2)),0.5);
}
for(int i=48;i <= 2974;i++){ //to get a max of 4000 hZ hopefully?
if (mag[i]>maxMag){
maxMag = mag[i];
fFreq = i;
}
}
realFreq=fFreq/(numberOfSamples/2+1)*sFreq/2;
return [NSArray arrayWithObjects: #(maxMag),#(realFreq),nil];
}
}

Navigate through Array by Pointer to Pointer

I have tried to move through array by double pointer. Here is the Code.
void pptr (int **sptr2,int **ptr2)
{
**ptr2 = (**sptr2 + 7); //Works Fine
*sptr2++; *ptr2++; //Probable problem Statement
**ptr2 = (**sptr2 + 7); //Not Workign
}
void ppointer (int *sptr,int *ptr)
{
pptr (&sptr,&ptr);
}
main()
{
int sour[2];
sour[0] = 40;
sour[1] = 50;
int var[2];
var[0] = 10;
var[1] = 20;
printf("befor change %d %d\n",var[0],var[1]);
ppointer(&sour[0],&var[0]);
printf("pointer to pointer change %d %d\n",var[0],var[1]);
}
I wish to update var in pptr function. I can use double pointer (**sptr,**pptr) to reference pointer (sptr,ptr) (which are pointing to array) into function. I am able to update first one but second one has no change. I think problem is with statement *sptr++ & *ptr++.
Please help me understand how can i navigate through array by double pointer.
Thank you
I think it is the compiler just being silly with the "*sptr++;" and the "*ptr++;"
void pptr (int **sptr2, int **ptr2)
{
**ptr2 = (**sptr2 + 7);
///////////////////////////////////////////////////////
*sptr2++; //This is the problem these two statements
*ptr2++;
///////////////////////////////////////////////////////
**ptr2 = (**sptr2 + 7);
}
Now however if you change it to "*sptr2 += 1;" and "*ptr += 1;" it then works
void pptr (int **sptr2, int **ptr2)
{
**ptr2 = (**sptr2 + 7);
///////////////////////////////////////////////////////
*sptr2 += 1; //Now no problem
*ptr2 += 1;
///////////////////////////////////////////////////////
**ptr2 = (**sptr2 + 7);
}
I dont really know why the compiler does this due to lack of experience of using the "variable++" operator, I just generally use "variable += 1" instead.

Cuda-memcheck not reporting out of bounds shared memory access

I am runnig the follwoing code using shared memory:
__global__ void computeAddShared(int *in , int *out, int sizeInput){
//not made parameters gidata and godata to emphasize that parameters get copy of address and are different from pointers in host code
extern __shared__ float temp[];
int tid = blockIdx.x * blockDim.x + threadIdx.x;
int ltid = threadIdx.x;
temp[ltid] = 0;
while(tid < sizeInput){
temp[ltid] += in[tid];
tid+=gridDim.x * blockDim.x; // to handle array of any size
}
__syncthreads();
int offset = 1;
while(offset < blockDim.x){
if(ltid % (offset * 2) == 0){
temp[ltid] = temp[ltid] + temp[ltid + offset];
}
__syncthreads();
offset*=2;
}
if(ltid == 0){
out[blockIdx.x] = temp[0];
}
}
int main(){
int size = 16; // size of present input array. Changes after every loop iteration
int cidata[] = {1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16};
/*FILE *f;
f = fopen("invertedList.txt" , "w");
a[0] = 1 + (rand() % 8);
fprintf(f, "%d,",a[0]);
for( int i = 1 ; i< N; i++){
a[i] = a[i-1] + (rand() % 8) + 1;
fprintf(f, "%d,",a[i]);
}
fclose(f);*/
int* gidata;
int* godata;
cudaMalloc((void**)&gidata, size* sizeof(int));
cudaMemcpy(gidata,cidata, size * sizeof(int), cudaMemcpyHostToDevice);
int TPB = 4;
int blocks = 10; //to get things kicked off
cudaEvent_t start, stop;
cudaEventCreate(&start);
cudaEventCreate(&stop);
cudaEventRecord(start, 0);
while(blocks != 1 ){
if(size < TPB){
TPB = size; // size is 2^sth
}
blocks = (size+ TPB -1 ) / TPB;
cudaMalloc((void**)&godata, blocks * sizeof(int));
computeAddShared<<<blocks, TPB,TPB>>>(gidata, godata,size);
cudaFree(gidata);
gidata = godata;
size = blocks;
}
//printf("The error by cuda is %s",cudaGetErrorString(cudaGetLastError()));
cudaEventRecord(stop, 0);
cudaEventSynchronize(stop);
float elapsedTime;
cudaEventElapsedTime(&elapsedTime , start, stop);
printf("time is %f ms", elapsedTime);
int *output = (int*)malloc(sizeof(int));
cudaMemcpy(output, gidata, sizeof(int), cudaMemcpyDeviceToHost);
//Cant free either earlier as both point to same location
cudaError_t chk = cudaFree(godata);
if(chk!=0){
printf("First chk also printed error. Maybe error in my logic\n");
}
printf("The error by threadsyn is %s", cudaGetErrorString(cudaGetLastError()));
printf("The sum of the array is %d\n", output[0]);
getchar();
return 0;
}
Clearly, the first while loop in computeAddShared is causing out of bounds error because I am allocating 4 bytes to shared memory. Why does cudamemcheck not catch this. Below is the output of cuda-memcheck
========= CUDA-MEMCHECK
time is 12.334816 msThe error by threadsyn is no errorThe sum of the array is 13
6
========= ERROR SUMMARY: 0 errors
Shared memory allocation granularity. The Hardware undoubtedly has a page size for allocations (probably the same as the L1 cache line side). With only 4 threads per block, there will "accidentally" be enough shared memory in a single page to let you code work. If you used a sensible number of threads block (ie. a round multiple of the warp size) the error would be detected because there would not be enough allocated memory.

Line scanning openCV

below is a very simple code segment, but I am not able to understand why it is cribbing, can you please tell me what the error means:
CvSize iSize;
iSize= cvGetSize(I1);
CvLineIterator *iter ;
CvPoint p1,p2;
long *arrH = new long[iSize.height + 1];
long *arrV = new long [iSize.width + 1];
for( int i=0; i<=iSize.height;i++)
{
p1.y = i; p2.y=i;
p1.x = 0; p2.x=iSize.width;
arrH[i] =0;
int l = cvInitLineIterator(I1,p1,p2,iter,4,0);
for( int j=0;j<l;j++)
{
arrH[i]+=iter.ptr;
CV_NEXT_LINE_POINT(iter);
}
fprintf(f1,"%d \n",arrH[i]);
}
Errors of the form:
left of '.ptr' must have class/struct/union
how do I tackle them ?
I think this:
CvLineIterator *iter ;
Should be:
CvLineIterator iter ;
And this:
cvInitLineIterator(I1,p1,p2,iter,4,0);
Should be:
cvInitLineIterator(I1,p1,p2,&iter,4,0);

Resources