bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: address warnings from GCC's UB sanitizer


From: Paul Eggert
Subject: Re: address warnings from GCC's UB sanitizer
Date: Thu, 14 Mar 2019 14:26:13 -0700
User-agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.5.1

On 3/14/19 1:43 PM, Akim Demaille wrote:
>
> But maybe this piece of code is obsolete anyway?  I mean, currently mbsnwidth 
> returns an int anyway, and seems to deal with overflow by itself.  So I guess 
> we don't even need this precaution today.

That's right. add_column_width was originally written when mbsnwidth did
not detect overflow, and so that precaution was present (whether
correctly implemented or not, doesn't matter now). Nowadays we can
remove the precautioin.


> +  return column <= INT_MAX - width ? column + width : INT_MAX;

Nowadays a better (i.e., more-efficient, and I think easier-to-follow)
way of writing this is:

  int result;
  return INT_ADD_WRAPV (column, width, &result) : INT_MAX : result;

where INT_ADD_WRAPV is defined in intprops.h.




reply via email to

[Prev in Thread] Current Thread [Next in Thread]