On 15.04.21 14:48, Willy Tarreau wrote:
On Thu, Apr 15, 2021 at 02:17:45PM +0200, Aleksandar Lazic wrote:
I, by far, prefer Tim's proposal here, as I do not even understand the
first one, sorry Aleks, please don't feel offended :-)

Well you know my focus is to support HAProxy and therefore it's okay.
The contribution was in the past much easier, but you know time changes.

It's not getting harder, we've always had numerous round trips,
however now there are more people participating and it's getting
increasingly difficult to maintain a constant level of quality so
it is important to take care about maintainability, which implies
being carefull about the coding style (which is really not strict)
and a good level of English in the doc (which remains achievable
as most of the contributors are not native speakers so we're not
using advanced English). In addition there's nothing wrong with
saying "I need someone to reword this part where I don't feel at
ease", it's just that nobody will force it on you as it would not
be kind nor respectful of your work.

In fact I'd say that it's got easier because most of the requirements
have been formalized by now, or are not unique to this project but
shared with other ones.

Okay, got you.

  From my point of view is it necessary to check if the value is a negative
value and only then should be checked if the max '-' range is reached.

But the first one is implied by the second. It looks like a logical
error when read like this, it makes one think the author had something
different in mind. It's like writing "if (a < 0 && a < -2)". It is
particularly confusing.

Well then then this does not work anymore

If so it precisely shows that a problem remains somewhere else.

Hm, maybe.

http-request set-var(sess.pay_int) req.body,json_query('$.integer',"int"),add(1)

with the given defines.

#define JSON_INT_MAX ((1ULL << 53) - 1)
#define JSON_INT_MIN (0 - JSON_INT_MAX)

Because "{"integer":4}" => 5" and 5 is bigger then JSON_INT_MIN which is 
(0-JSON_INT_MAX)

This sequence works because I check if the value is negative "smp->data.u.sint < 
0"
and only then check if the negative max border "JSON_INT_MIN"  is reached.

I'm sorry but I don't get it.

if (smp->data.u.sint < 0 && smp->data.u.sint < JSON_INT_MIN)

The same belongs to the positive max int.

Now when I remove the check "smp->data.u.sint < 0" every positive value is
bigger then JSON INT_MIN and returns 0.

But don't you agree that this test DOES nothing ? If it changes anything
it means the issue is somewhere else and is a hidden bug waiting to strike
and that we must address it.

Look:

     if (smp->data.u.sint < 0 && smp->data.u.sint < JSON_INT_MIN)

is exactly equivalent to:

     if (smp->data.u.sint < JSON_INT_MIN && smp->data.u.sint < 0)

JSON_INT_MIN < 0 so the first part implies the second one. Said differently,
there is no value of sint that validates <JSON_INT_MIN without validating <0.

I think it checks if the value is negative or positive and then verify if the
value is bigger then the the max allowed value, +/-.

Maybe I thing wrong, so let us work with concrete values.

```
printf("\n\n>> smp->data.u.sint :%lld: < JSON_INT_MIN :%lld: if-no-check:%d:<<\n",   
smp->data.u.sint,JSON_INT_MIN,(smp->data.u.sint < JSON_INT_MIN));
printf(    ">> smp->data.u.sint :%lld: > JSON_INT_MAX :%lld: if-no-check:%d:<<\n\n", 
smp->data.u.sint,JSON_INT_MAX,(smp->data.u.sint > JSON_INT_MAX));

if (smp->data.u.sint < 0 && smp->data.u.sint < JSON_INT_MIN)
        return 0;
else if (smp->data.u.sint > 0 && smp->data.u.sint > JSON_INT_MAX)
        return 0;

```

Input is here 4.
>> smp->data.u.sint :4: < JSON_INT_MIN :-9007199254740991: if-no-check:1:<<
>> smp->data.u.sint :4: > JSON_INT_MAX :9007199254740991:  if-no-check:0:<<

Input is here -4.

>> smp->data.u.sint :-4: < JSON_INT_MIN :-9007199254740991: if-no-check:0:<<
>> smp->data.u.sint :-4: > JSON_INT_MAX :9007199254740991:  if-no-check:1:<<

This looks to me when the comparing is done with a positive value then it
will be true for the JSON_INT_MIN and when the comparing is done with a negative
value then will it be true for JSON_INT_MAX.

So the concrete question is how to check the value in the positive and negative
range without the "smp->data.u.sint < 0" or "smp->data.u.sint > 0".

I haven't found any other solution, I'm open for any suggestion?

Willy


Regards
Aleks

Reply via email to