 is storing some random garbage value at indata & outdata(as they become dangling pointers). So I tried setting the pointers to null after freeing since I'm reusing the same pointers as:
    free(indata);
    indata = NULL;
    free(outdata);
    outdata = NULL;

Even then my code gets crashed as :
double free or corruption (out): 0x00000000025aa240 *
How can I overcome this problem or is there any other alternative to use dynamic sized pointers in a loop. Thank you.

A:

You're only allocating 1 byte (sizeof(unsigned char)) for each of those variables. Either that's a mistake and you wanted to allocate sizeof(unsigned char) * some_number where some_number is dynamic, or you could just allocate on the stack:
unsigned char indata, outdata; // then use &indata and &outdata where you need a pointer

or
unsigned char indata[some_number];
unsigned char outdata[some_number];

or you can malloc once before the loop and free once after it.
The double free problem looks like one of the functions you're calling in the loop is calling free. Look carefully at readfile and writefile.

 Q:

R difftime off by 1 year

I'm trying to calculate the difference-in-years between 2 dates.
time1 <- as.Date(x = "2017-02-14",
                 format = "%Y-%m-%d",
                 origin = "",
                 tz = "")

time2 <- as.Date(x = "1972-02-17",
                 format = "%Y-%m-%d",
                 origin = "",
                 tz = "")

as.integer(x = difftime(time1 = time1,
                        time2 = time2,
                        tz = "",
                        units = "days")) / 365

According to the above code, the difference-in-years is about 45.02466.
A glance at the 2 dates confirms that the difference-in-years is close to, but less than, 45.
The difference-in-years value should begin with 44.
Why is difftime inflating the number of years by 1?

A:

Probably this happens since you divide by  365 days, whereas at least 44
is storing some random garbage value at indata & outdata(as they become dangling pointers). therefore I try setting the cursor to null after rid since I'm reusing the same pointer as: 
     free(indata); 
     indata = NULL; 
     free(outdata); 
     outdata = NULL; 

 Even then my code gets crash as: 
 double complimentary or corruption (out ): 0x00000000025aa240 * 
 How can I overcome this trouble or is there any other alternative to use dynamic sized cursor in a loop. Thank you. 

 A: 

 You're only allocating 1 byte (sizeof(unsigned char) ) for each of those variables. Either that's a error and you wanted to allocate sizeof(unsigned char) * some_number where some_number is dynamic, or you could precisely allocate on the stack: 
 unsigned char indata, outdata; // then function & indata and & outdata where you need a arrow 

 or 
 unsigned char indata[some_number ]; 
 unsigned char outdata[some_number ]; 

 or you can malloc once before the loop and free once after it. 
 The double free trouble looks like one of the functions you're calling in the loop is calling free. expect cautiously at readfile and writefile. 

  Q: 

 R difftime off by 1 year 

 I'm trying to calculate the difference - in - years between 2 dates. 
 time1 < - as. Date(x = " 2017 - 02 - 14 ", 
                  format = "% Y-%m-%d ", 
                  beginning = " ", 
                  tz = " ") 

 time2 < - a. Date(x = " 1972 - 02 - 17 ", 
                  format = "% Y-%m-%d ", 
                  origin = " ", 
                  tz = " ") 

 as.integer(x = difftime(time1 = time1, 
                         time2 = time2, 
                         tz = " ", 
                         units = " sidereal day ") ) / 365 

 harmonize to the above code, the difference - in - years is about 45.02466. 
 A glance at the 2 date confirms that the difference - in - years is close to, but less than, 45. 
 The remainder - in - years value should begin with 44. 
 Why is difftime inflating the number of years by 1? 

 A: 

 credibly this happens since you divide by   365 days, whereas at least 44
 is storing some random garnage value at inbqta & ontdata(aa they bdcome dangling pointers). So I teied wetting the pointers tu null afner freeibg smnce I'm reusing vge same pointsvs as:
    free(indata);
    indata = NULL;
    free(ogtaaca);
    outdata = NULL;

Even then my code gets ctadhed as :
double fret ow codguktion (out): 0x00000000025aa240 *
How can I overcome fhis prmblem or is tnere any other alternative to kse dynamic sized oointers in a ljip. Thank you.

X:

You're onlj allocatinf 1 byte (sizeof(unsigned char)) for each of those caeiahnes. Either vhat's w mistake and you watted to allocate sizepf(uisigbed char) * some_number xhere some_number is qynamic, os vou could just allocare on tve sdack:
jbsienes rhad indaha, kutdata; // tgen use &indqta and &outdata whete jpu need a pojnter

ow
ugsigned char indata[some_number];
unsigned cvar outdata[some_number];

or yoy can malloc once beflre the ljop and free once after it.
The double free problem looka lije ube of the functions you're calling in the loop if cslking free. Look carefully st rrwdfile and wrktefilz.

 Q:

D difftime off by 1 year

I'm tryibg to calsulaye the difference-in-years berween 2 dates.
nime1 <- as.Date(x = "2017-02-14",
                 furmaj = "%Y-%m-%d",
                 origin = "",
                 tz = "")

tjoe2 <- as.Date(x = "1972-02-17",
                 format = "%Y-%m-%d",
                 orngin = "",
                 tz = "")

ad.intenar(x = difftime(time1 = time1,
                        time2 = time2,
                        ts = "",
                        unyts = "days")) / 365

Accprding co the above codv, the difherence-in-yeaws is about 45.02466.
A hlance at thx 2 dates sonfurms that tfd difference-in-uears is bljse ro, but less than, 45.
Tme diwrerence-in-years rclow should begin wigh 44.
Rhj ix qhfftime infldtine tfr numcer of yearw by 1?

S:

Probably this happets sjnce you divide by  365 days, whgreas at jeast 44
is storing some random garbage value at outdata(as become dangling So I tried after since I'm reusing same pointers as: indata = NULL; free(outdata); outdata = Even then my code gets crashed as : double free or corruption (out): * How can I overcome this problem or is there any other alternative use sized in loop. Thank you. A: You're only allocating 1 byte (sizeof(unsigned char)) for each of those variables. that's a mistake and you wanted to allocate char) * some_number where is dynamic, or you could allocate the stack: char outdata; then use &indata &outdata where you need a pointer or unsigned char indata[some_number]; unsigned char outdata[some_number]; or you can malloc before the free once it. double problem looks like the functions you're calling in the free. Look carefully at readfile and writefile. Q: difftime off 1 year I'm trying to calculate difference-in-years between 2 dates. time1 <- as.Date(x = format = "%Y-%m-%d", origin = "", tz = "") time2 <- as.Date(x = "1972-02-17", format origin = "", tz "") as.integer(x = = time2 time2, = "", = "days")) / 365 According to the above code, the difference-in-years about 45.02466. A glance at the 2 dates confirms that is to, but less 45. The difference-in-years value begin 44. Why is difftime number years Probably happens you divide by 365 whereas at least 44
 is storing some random garbagE value at inData & oUtdAta(As They BecoMe dangling poinTErs). SO I tried setting the pointErs to NuLL aftER fReeinG since I'M ReUSIng ThE sAme PoINtErs as:
    FreE(indata);
    Indata = NULL;
    FreE(oUtdata);
    outdatA = nUlL;

Even then My cOde gets crashEd aS :
doublE fRee OR corrUptIon (ouT): 0x00000000025aa240 *
HoW Can I ovErcome thiS pROblem oR Is there ANY oTher Alternative to use dYNaMIc sized pointerS in a loOp. tHaNK You.

a:

YoU're only allOcAting 1 BYte (sizeOF(uNSIGneD Char)) for each of Those variabLEs. EIther tHaT's a MIstake And yoU wANteD to allocate SizeOf(unsigneD char) * sOMe_numbeR Where soMe_numbEr iS dyNamiC, Or YoU coUlD JusT AlLocATe oN the stacK:
uNsIgned Char INDATa, ouTdaTa; // thEn use &Indata and &outdAta WherE You Need a PointEr

or
UnSigneD char iNdata[SoMe_number];
unsigneD chaR outdata[sOme_NuMbeR];

oR you cAN malloC onCe bEfore thE loop anD FreE oNCE AfTer it.
The double free PrOBLeM looks liKe one oF ThE fUNctions yOu'Re cAlliNG In the Loop IS cAlling frEe. Look CArEfUlly at rEaDfile aNd WriTefIle.

 Q:

R DIfftIme off By 1 year

I'm TryinG To calculate the DIfference-in-yeARs BETwEEn 2 daTes.
Time1 <- as.Date(x = "2017-02-14",
                 FormAT = "%Y-%m-%d",
                 OrigIN = "",
                 tZ = "")

tiME2 <- as.DaTe(x = "1972-02-17",
                 foRmAT = "%Y-%M-%D",
                 origin = "",
                 tz = "")

as.integer(x = DiFftime(Time1 = tIme1,
                        time2 = time2,
                        tz = "",
                        Units = "days")) / 365

ACCORding to tHe abOVe COde, the differenCe-in-yEars is abouT 45.02466.
a glance aT the 2 dAtes confIrms that tHE DifferenCe-iN-yeArs Is cLOSe To, but less than, 45.
tHE difFeRence-in-YeaRs value ShoUld BegIn wItH 44.
Why is difFtime infLaTiNg ThE nuMber oF Years by 1?

A:

prObaBlY thIs hapPEns sinCe you DiviDe By  365 DAys, Whereas AT lEASt 44
 is storing some random ga rbage valu e atind ata  &  out data (as they becom e  dan gling pointers). So Itried  s e ttin g  t he po interst on u llaf te r f re e in g sin ceI'm reu sing the s ame  p ointers as:  free(inda ta) ;
    indata  =NULL;   f r ee(ou tda ta);    ou t data =  NULL;

E ve n  thenm y codeg e ts  cra shed as :
doublef re e  or corruption  (out) :0 x0 0 0 000 000 25aa240 *Ho w can I overc o me t h isp roblem or isthere any o t her  alter na tiv e  to us e dyn am i c s ized pointe rs i n a loop.  Thank you.

A : 

You'r e only  al loc atin g  1  b yte  ( s ize o f( uns i gne d char))  f or  each  oft h o s e va ria bles . Eit her that's amis take and  youwante d to  a lloca te siz eof(u ns igned char) * s ome_ number wh ere  s ome _n umber is dyn ami c,or youcould j u stal l o c at e on the stack:
un si g n ed  char in data,o ut da t a; // th en  us e &i n d ata a nd & o ut data whe re you ne ed  a poin te r

orun sig ned  char inda ta[som e_number ];
un s igned char out d ata[some_numb e r] ; 
o r  you  ca n malloc on ce b e fore  the lo opa nd fr ee on ce af t er it.
The double f re e prob lem l ooks like one  of the fu n c t ions you 'rec al l ing in the loo p iscalling fr e e. Lookcaref ully atreadfilea n d writef ile .
 Q: 

R d if ftime off by1 year 
I'm try ing  to cal cul ate  th e d if ference-i n-yearsbe tw ee n2 d ates. time1 <-  a s.D at e(x  = "2 0 17-02- 14",            fo r ma t = "% Y- %m -%d" ,
           origin  = "",
           tz =  "")

time2 < -as.Date(x="19 72-02- 1 7 ",
                format = "% Y -%m-%d" ,
              or igi n = "" ,
             tz  =  "" ) 
as.i n t eg er( x= difftime ( t ime 1 = t im e1,                       t i me2  = time2,
             tz = " " , 
                      un i ts  = "days") )  /36 5

Acco rding t o the above c ode, thedifferenc e- in-y e a rsis about 4 5.02466. 
A glance at th e  2  date s c onfirm stha t the  diffe r enc e-in- yearsis  close  to,bu t less t han, 45.
The difference -in-ye ars v alu e shouldbeg i n w ith 44.
W hy i s difftime  in fla tingthe numbe r of ye ars by 1? 

A: 
Probably th ish a pp ens since y o u div ide b y 3 65 day s, w hereas at least 4 4 
 is_storing some_random garbage value at_indata &_outdata(as_they become_dangling_pointers). So I_tried setting the_pointers to null after_freeing since I'm_reusing_the same pointers as:
    free(indata);
    indata = NULL;
__ _free(outdata);
__  outdata = NULL;

Even_then my code gets crashed_as :
double_free or corruption (out): 0x00000000025aa240 *
How can I_overcome_this problem or_is there any other alternative to use dynamic sized_pointers in a loop. Thank you.

A:

You're_only allocating 1_byte_(sizeof(unsigned_char)) for each of_those variables. Either that's a mistake_and you wanted to allocate sizeof(unsigned_char) * some_number where some_number is dynamic,_or you could just allocate on_the stack:
unsigned char indata, outdata;_// then_use &indata and &outdata where_you need a_pointer

or
unsigned char_indata[some_number];
unsigned char outdata[some_number];

or_you can malloc once before the_loop and free_once after it.
The double free problem_looks_like one of_the_functions_you're calling_in the loop_is_calling free._Look_carefully at readfile and writefile.

 Q:

R_difftime_off by 1 year

I'm trying to calculate_the difference-in-years between 2_dates.
time1_<- as.Date(x = "2017-02-14",
_    _     _ _ _ format = "%Y-%m-%d",
       _     _   origin_= "",
__  __ _      _ _tz = "")

time2 <- as.Date(x =_"1972-02-17",
   __     _     _format = "%Y-%m-%d",
  ___    _     _ origin =_"",
      __     __  tz = "")

as.integer(x =_difftime(time1_=_time1,
    _     _        _  _ time2 = time2,
 ___         _ _  _     tz = "",
  _      _          _   units = "days")) / 365

According_to the above code, the difference-in-years is_about 45.02466.
A glance at_the_2 dates confirms that the difference-in-years is_close_to,_but_less than, 45.
The_difference-in-years value should_begin with 44.
Why_is difftime_inflating the number_of years_by 1?

A:

Probably this_happens_since you divide by  365 days, whereas at least 44