Re: Bug/Gross InEfficiency in HeathField's fgetline program
In data Fri, 19 Oct 2007 08:49:43 +0200, ¬a\/b scrisse:
/* test: if n bytes starting at s
// overlaps m bytes starting at t
*/
#define uns unsigned
/* assume a pointer has the same size of one unsigned */
/* return 1 if error or overlap 0 otherwise
if you like uns == size_t
*/
int mem_overlap123(char* s, int n, char* t, int m)
{if(s==0|| t==0) return 1;
/* s and t can not go trhu 0 address */
/* s----- t------- */
if((uns)(s+n-1) < (uns) s) return 1;
if((uns)(t+m-1) < (uns) t) return 1;
/* overlap */
/* s----- t------ || t----- s------*/
if( (uns)(s+n-1) < (uns) t) return 0;
if( (uns)(t+m-1) < (uns) s) return 0;
return 1;
}
|