Re: Bug/Gross InEfficiency in HeathField's fgetline program
In data Thu, 18 Oct 2007 08:07:58 +0200, ¬a\/b scrisse:
>In data Wed, 17 Oct 2007 17:00:13 +0200, ¬a\/b scrisse:
>
>> /* test: if n bytes starting at s
>> // overlaps n bytes starting at t
// overlaps m bytes starting at t
>> */
>>/* assume a pointer has the same size of an int and one unsigned */
>>/* return 1 if error or overlap 0 otherwise */
>>int mem_overlap123(char* s, int n, char* t, int m)
>>{if(s==0|| t==0 || n<0 || m<0) return 0;
> ^^^^^^^^^^^^^
>
>return 1
>
>> /* no array can have the address 0
>> if( ((int)s)>=0 &&((int)(s+n-1))<= 0) return 1;
>
>> if( ((int)t)>=0 &&((int)(t+n-1))<= 0) return 1;
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
>
>if( ((int)t)>=0 &&((int)(t+m-1))<= 0) return 1;
>
>> if( ((int)s)<=0 &&((int)(s+n-1))>= 0) return 1;
>> if( ((int)t)<=0 &&((int)(t+n-1))>= 0) return 1;
>^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ^^
>
>if( ((int)t)<=0 &&((int)(t+m-1))>= 0) return 1;
there is anhother error
the 'singular' points are two 0 and INT_MAX
--0 == -1 ++INT_MAX!=0
>> /* s----- t------ || t----- s------*/
>> if( (unsigned)(s+n-1) < (unsigned) t) return 0;
>> if( (unsigned)(t+m-1) < (unsigned) s) return 0;
>> return 1;
>>}
>>
>>not tested
>>how many errors do you see?
|