[PATCH 1/2] cgit: introduce parse_{bool, int}() for for cgitrc parsing

Jeff Smith whydoubt at gmail.com
Tue Jan 8 15:05:10 CET 2019


On Mon, Jan 7, 2019 at 9:36 AM Christian Hesse <list at eworm.de> wrote:

> From: Christian Hesse <mail at eworm.de>
>
> +       int value = MIN(MAX(atoi(str), max), min);
>

This will always result in value = min
The correct statement would be
  int value = MIN(MAX(atoi(str), min), max);

Alternately, since this is the only time you use MIN/MAX, you could instead
define a CLAMP macro and use it.
  int value = CLAMP(atoi(str), min, max);


> +               ctx.cfg.cache_size = parse_int(value, 0, INT_MAX, 0);
>

In all but a couple of instances, the same min/max/default values are
passed in.
Wouldn't it be better to have parse_int(value) for these, and something like
parse_int_clamp_default(value, min, max, default_if_zero) for the
exceptions?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/cgit/attachments/20190108/4910b660/attachment.html>


More information about the CGit mailing list