[Ocfs2-test-devel] [PATCH 42/59] mmap-test: fix segment fault
Junxiao Bi
junxiao.bi at oracle.com
Thu Oct 8 23:29:44 PDT 2015
On 09/25/2015 11:04 AM, Eric Ren wrote:
> Hi Junxiao,
>
>>>> +
>>>> + /* fix offset if the file size is multiple of page size */
>>>> + if (offset == 0)
>>>> + offset = page_size;
>>>> +
>>>
>>> I cannot understand the below.
>>> 1. if (.st_size < page_size && .st_size != 0)
>>> both if-statement won't hit;
>>>
>>> 2. if (.st_size > page_size && .st_size % page_size != 0)
>>> 1st if-statement won't hit;
>>> 2st if-statement won't hit, also;
>>>
>>> 3. if (.st_size !=0 && .st_size % page_size == 0)
>>> 1st if-statement hit!
>>> 2st if-statement won't hit!
>>>
>>> 4. if (.st_size == 0)
>>> 1st if-statement hit;
>>> 2st if-statement will hit!!! As a result, offset varied 0,
>>> page_size, and 0 again.
>>>
>>> So, the 2th if-statement is odd! Or I mistake something?
>> 2th is for the case st_size == 0, do you mean it's useless and can be
>> dropped?
>
> If so, yes, it's useless.
Without 2th if, "ptr" will point to wrong address?
ptr = buf + (stat_buf.st_size - offset);
Thanks,
Junxiao.
>
> Thanks,
> Eric
>
>>
>> Thanks,
>> Junxiao.
>>>
>>> Thanks,
>>> Eric Ren
>>>
>>>> + if (offset > stat_buf.st_size)
>>>> + offset = stat_buf.st_size;
>>>> +
>>>> ptr = buf + (stat_buf.st_size - offset);
>>>> remain = page_size - offset;
>>>>
>>>> --
>>>> 1.7.9.5
>>>>
>>>>
>>>> _______________________________________________
>>>> Ocfs2-test-devel mailing list
>>>> Ocfs2-test-devel at oss.oracle.com
>>>> https://oss.oracle.com/mailman/listinfo/ocfs2-test-devel
>>>>
>>
>>
More information about the Ocfs2-test-devel
mailing list