[Ocfs2-test-devel] [PATCH 42/59] mmap-test: fix segment fault

Eric Ren zren at suse.com
Tue Sep 22 22:13:56 PDT 2015


Hello Junxiao,

Please look at comment below.

On Mon, Sep 14, 2015 at 10:44:28AM +0800, Junxiao Bi wrote: 
> When test file size is multiple of page size, there will be write out of
> mmap range and cause segment fault.
> 
> Signed-off-by: Junxiao Bi <junxiao.bi at oracle.com>
> ---
>  programs/mmap_test/mmap_test.c |    8 ++++++++
>  1 file changed, 8 insertions(+)
> 
> diff --git a/programs/mmap_test/mmap_test.c b/programs/mmap_test/mmap_test.c
> index 9edbb58..711bb81 100644
> --- a/programs/mmap_test/mmap_test.c
> +++ b/programs/mmap_test/mmap_test.c
> @@ -80,6 +80,14 @@ int main(int argc, char *argv[])
>      }
>  
>      offset = stat_buf.st_size % page_size;
> +
> +    /* 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?

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