> On Mar 19, 2015, at 4:49 AM, Cyril Hrubis <chru...@suse.cz> wrote:
> 
> Hi!
>> off_t in 64bit in ILP32 ABI while the compiler will default 32bit
>> for constant. It lead to pass the negative 32bit integer to kernel,
>> and kernel will treat it as 64bit positive integer.
>> 
>> It could also fix in glibc while we think that there are lots of
>> advantage if leave off_t remains 64bit.
>> 
>> Signed-off-by: Zhang Jian(Bamvor) <bamvor.zhangj...@huawei.com>
>> ---
>> testcases/kernel/fs/ftest/ftest02.c | 2 +-
>> 1 file changed, 1 insertion(+), 1 deletion(-)
>> 
>> diff --git a/testcases/kernel/fs/ftest/ftest02.c 
>> b/testcases/kernel/fs/ftest/ftest02.c
>> index ec70d9b..153bd09 100644
>> --- a/testcases/kernel/fs/ftest/ftest02.c
>> +++ b/testcases/kernel/fs/ftest/ftest02.c
>> @@ -268,7 +268,7 @@ static void crfile(int me, int count)
>>    val = write(fd, crmsg, sizeof(crmsg) - 1);
>>    warn(val, "write", 0);
>> 
>> -    val = lseek(fd, -(sizeof(crmsg) - 1), 1);
>> +    val = lseek(fd, -(off_t)(sizeof(crmsg) - 1), 1);
> 
> Hmm, this is doing lseek(fd, -size_of_message, SEEK_CUR), wouldn't it be
> easier to use the offset we passed to the first lseek() with SEEK_SET
> instead?
> 
> And I do not really understand why this does not work. All I can see
> that the expression is evaluated as: sizeof() returns size of the
> message as size_t, which is 32 bit,

32bit unsigned value

> we decrement it by one and then
> negate it. We have negative 32 bit number.

no we have a big unsigned 32bit value which is the two comps of size-1. 

> Then the compiler should pick
> up the lseek() prototype from glibc header and figure out that it should
> convert the second parameter to off_t. What I'm missing here?

Casting between unsigned 32bit to an unsigned 64bit value is a zero extend 
operation rather than a size extend one. So casting to 64bit before taking the 
twos complement (negative), give a different value where the upper 32bits are 
ones rather than zero. 

Thanks,
Andrew


> 
> -- 
> Cyril Hrubis
> chru...@suse.cz

------------------------------------------------------------------------------
Dive into the World of Parallel Programming The Go Parallel Website, sponsored
by Intel and developed in partnership with Slashdot Media, is your hub for all
things parallel software development, from weekly thought leadership blogs to
news, videos, case studies, tutorials and more. Take a look and join the 
conversation now. http://goparallel.sourceforge.net/
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

Reply via email to