C segmentation fault before/during return statement -


I print the value that I am returning back to my return statement, and to print back the returned value I'll tell my code right after the function call, however, I get a split mistake after my first print statement and before me (interesting to pay attention, this is always the third time the function is called, anytime before or Second, never Was neither later). I tried to print all the data that I am working to see to be that my remaining code was doing something, maybe it should not be, but by that time my data looks fine. Here's the job:

  int findHydrogen (struct amino * amino, int nPos, float * diff, int totRead) {struct atom * atom; Int * Bond; Int numBonds; Int i; Int radial; Int numatoms; NumAtoms = (* amino) .numAtoms; Atom = (strip atom *) molk (shapeoff (strip atom) * numAtoms); Atom = (* amino). Atom; Numbonds = atoms [nPos] .numbonds; Bond = (Int *) Mallok (Sizoff (Int) * Newbands); Bond = atom [npo]. Bonds; (I = 0; i & lt; (* amino) .numAtoms; i ++) printf ("ATOM \ t \ t% d% s \ t0001 \ t% f \ t% f \ t% f \ n" ", I + 1, atom [i]. Type, atom [i]. X, atom [i]., Atom [i] .z); (I = 0; i & lt; numbonds; i ++) if (atom [bond] [i] - totRead]. [0] == 'H') {diff [0] = atoms [bond [i] - totRead] .x - atom [nPos] .x; Diff [1] = atoms [bond [i] - totRead] .- Nuclear [npeas] .y; Diff [2] = Atomic [bond] [i] - totRead] .z - Atom [nPos] .z; RetVal = bond [i] - totRead; Bond = (integer *) malloc (size); Free (bond); Atom = (straight atom *) molk (shapeoff (strip atom)); Free (atomic); Printf ("2% d \ n", retal); Return rate; }}  

As I mentioned earlier, it cures the first two times, when I run it, the third time it prints the correct value of retVal, then there is a mistake. The function is called, which I do:

  hPos = find hydrogen ((and amino acids [ii]), npo, dff, dot raid; Printf ("% d \ n", hips);    

It is not easy to guess where the error is from this code (potential for this Just about every bug in the code of the bug) - you probably have more buffer, although if you're * on the nick, run your program down, you should be able to find the error faster.

These lines seem weird:

  atom = (strip atom *) molk (shapeoff (stripe atom) * numAtoms); Atom = (* amino). Atom;  

You are leaking memory, as you discard the returned indicators by malloc. There is only one thing with bonds , and again the same thing inside your loop.


Comments

Popular posts from this blog

windows - Heroku throws SQLITE3 Read only exception -

lex - Building a lexical Analyzer in Java -

python - rename keys in a dictionary -