Re: realloc() failing under DOS (why it does'nt ...)
- Posted by Robert Craig <rds at RapidEuphoria.com> Nov 08, 2001
- 465 views
pseudonomus writes: > s = (char*)Realloc(s, i); > s[i-1] = 'X'; > s[i] = 0; /* EOS */ In C, if s is a pointer to i bytes, then s[i] is *not* a valid element. The subscripts run from 0 to i-1. You are writing a byte beyond the allocated space. Sometimes this won't matter. Other times it will lead to disaster. > Yet this code in Eu: > ... > works perfectly fast, and does not crash Euphoria. > ... > Is it a fluke that Euphoria does not fail when > appending? I've been pulling my hair out for many years, working with malloc, realloc and friends. I think I have most of the bugs out now. Buy the source in 2 weeks and learn all the tricks of the trade. Regards, Rob Craig Rapid Deployment Software http://www.RapidEuphoria.com