On Mon, Apr 19, 2021 at 10:08:50AM -0700, Boris Burkov wrote: > On Mon, Apr 19, 2021 at 09:05:49PM +0800, Su Yue wrote: > > @@ -1158,6 +1158,16 @@ static int check_resize_args(const char *amount, > > const char *path) { > > } > > old_size = di_args[dev_idx].total_bytes; > > > > + /* For target sizes without '+'/'-' sign prefix(e.g. 1:150g) */ > > + if (mod == 0) { > > + new_size = diff; > > + diff = max(old_size, new_size) - min(old_size, > > new_size); > > + if (new_size > old_size) > > + mod = 1; > > + else if (new_size < old_size) > > + mod = -1; > > + } > > + > > if (mod < 0) { > > if (diff > old_size) { > > error("current size is %s which is smaller than > > %s", > > This fix seems correct to me, but it feels a tiny bit over-complicated. > Personally, I think it would be cleaner to do something like: > > if (mod == 0) { > new_size = diff; > } else if (mod < 0) { > // >0 check > new_size = old_size - diff > } else { > // overflow check > new_size = old_size + diff > }
Right, this looks much better and shares a lot of with the code that follows the original fix.