lkml.org 
[lkml]   [2019]   [Mar]   [4]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectRe: [PATCH] fs: Avoid signed overflow UBSAN warning
On Sat, Feb 23, 2019 at 05:02:10PM +0800, Hongbo Yao wrote:
> I ran into this:
> UBSAN: Undefined behaviour in fs/read_write.c:251:11
> signed integer overflow:
> 9223372036854775805 + 9223372036854775805 cannot be represented in
> type 'long long int'
>
> Use unsigned types to do math, it doesn't throw a UBSAN warning
> when it does overflow.This patch doesn't change generated code.

You don't need to be this verbose to fix it.

> - offset += file->f_pos;
> + offset = (u64)file->f_pos + (u64)offset;

offset += (u64)file->f_pos;

\
 
 \ /
  Last update: 2019-03-05 05:27    [W:1.037 / U:0.528 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site