Errors, bugs, questions - page 3150

 
Nikolai Semko #:

ternary operator looks more concise (IMHO)

int limit = prev_calculated==0 ? 0: prev_calculated-1;

even more concise way :

int limit = prev_calculated-bool(prev_calculated);

:))

 
Nikolai Semko #:

I already wrote that with this construction you are accessing the buffer index with rates_total (when prev_calculated == 0 ).
And this is an overflow, because rates_total is the buffer size, the last element of which rates_total is -1

Yes I understand why the overflow is happening now!

Why did this construct work before and whydoesn't it work now?

int limit = rates_total-prev_calculated;

for(int i=limit; i>=0; i--)

Because the buffer is allocated exactly to rates_total
and notrates_total+1

I'm waiting to hear what Artyom has to say, he understands the issue.
 
Roman #:

Yes I understand why the overflow is happening now!

Why did this design work before,but now it doesn't?

Because the buffer is allocated exactly to rates_total
and notrates_total+1

There's no such thing as miracles.
If it worked before, it must have been a different code.

 
Roman #:

With this design.


indicator buffer goes out of bounds.

Please show me an example forticks with cycle i>=0
maybe I've forgotten what I'm doing wrong
.

roughly reduce index by 2 or 3 at maximal edge to be sure).

 
Nikolai Semko #:

There are no miracles.
If it worked before, it must have been a different code

Previously, the correct limit calculation was

int limit = rates_total-1-prev_calculated;

and it would go into the i>=0 loop.

for(int i=limit; i>=0; i--)

But it won't work now because the limit turns out to be -1

 
This discussion is off-topic, it belongs in some newbie thread
 
Roman #:

The correct calculation used to be

and it would go into loop i>=0

Now it won't go in because the limit turns out to be -1

I couldn't log in with the same code before, too.
don't make stuff up.

download the old build from Hatimlansky and check it, if you don't believe me.

 
TheXpert #:
This discussion is off-topic here, it belongs in some newbie thread

If you haven't used this design before, then refrain with your offtop.

 
Nikolai Semko #:

I couldn't log in with the same code before either
don't make this up

from Hatimlansky download the old build and check it if you don't believe me.

Artem also used this build.
Which he described above, so only he understands the problem here.

 
Roman #:

The correct calculation used to be

and it would go into loop i>=0

And now it does not, because the limit turns out to be -1.

Always there was a check: if(limit>1) limit=rates_total-1. This is for cases when there is no i+something in calculations. If there is, then these "how many-something" should be included to the construct: limit=rates_total-1-some-something.

Without it, there would always be an array overrun. Because rates_total is nothing else but Bars(). Correspondingly, if there are 5000 bars and we address index 5000, we will fall outside the array's limits (the calculation of bars starts with zero).

In your example, the calculation of limit is wrong:

int limit = rates_total-1-prev_calculated;

It should be like this:

int limit = rates_total-prev_calculated;

And after it check for limit>1

and if limit is greater than one, then limit = rates_total-1

Reason: