List for cgit developers and users
 help / color / mirror / Atom feed
From: whydoubt at gmail.com (Jeff Smith)
Subject: [PATCH 1/2] cgit: introduce parse_{bool, int}() for for cgitrc parsing
Date: Tue, 8 Jan 2019 08:05:10 -0600	[thread overview]
Message-ID: <CAPX7N=5rq6TUwFPD4bLf31J6pgGKTgOzMDy03y1O73OwBcAJ6w@mail.gmail.com> (raw)
In-Reply-To: <20190107153535.21620-1-list@eworm.de>

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>


  parent reply	other threads:[~2019-01-08 14:05 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-07-16 14:38 [PATCH 1/1] cgitrc: handle value "0" for max-repo-count list
2018-07-16 14:41 ` list
2018-09-11  6:56   ` list
2018-10-18 22:52     ` Jason
2018-11-23 16:08       ` list
2018-12-07  4:10         ` Jason
2019-01-07 15:34         ` list
2019-01-07 15:35           ` [PATCH 1/2] cgit: introduce parse_{bool, int}() for for cgitrc parsing list
2019-01-07 15:35             ` [PATCH 2/2] cgit: sanitize max-repo-count list
2019-01-07 20:54             ` [PATCH 1/2] cgit: introduce parse_{bool, int}() for for cgitrc parsing list
2019-01-08 14:05             ` whydoubt [this message]
2019-01-10 19:23           ` [PATCH 1/1] cgitrc: handle value "0" for max-repo-count tlatorre

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to='CAPX7N=5rq6TUwFPD4bLf31J6pgGKTgOzMDy03y1O73OwBcAJ6w@mail.gmail.com' \
    --to=cgit@lists.zx2c4.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).