Errors, bugs, questions - page 2966

 
fxsaber:

Discussed.

The error is not obvious there because: "maybe it was intended that way".

Here it is after executing function GetLastError() = ERR_WRONG_STRING_DATE. If the date is wrong, why is the result not wrong?

 
fxsaber:

I doubt it.

I didn't bother... I counted - you have 30 lines, I have 13

 
A100:

I didn't bother... I counted - you have 30 lines, I have 13.

The main thing is to get the same result and not to lose performance.

 

Error in binary search for a value in a sorted array:

void OnStart()
  {
   long hash[]= {-8017261424500504960,-7417030212113027668,-4495301772150012897,8444435679621798267};
   long my_hash=hash[3];
   int index=ArrayBsearch(hash,my_hash);
   ArrayPrint(hash);
   Print(my_hash,": ",index);
  }

Result:

2021.02.19 15:46:22.937 test3 (EURUSD,M1)       -8017261424500504960 -7417030212113027668 -4495301772150012897  8444435679621798267
2021.02.19 15:46:22.937 test3 (EURUSD,M1)       8444435679621798267: 2

Instead of 2 it should be 3

 
Aliaksandr Hryshyn:

Error in binary search for a value in a sorted array:

Result:

Instead of 2 it should be 3

//+------------------------------------------------------------------+
//| если добавить еще одно положительное число, то ошибки нет. где-то|
//|косяк в алгоритме бинарного поиска при переходе с минуса на плюс. |
//+------------------------------------------------------------------+
void OnStart()
  {
   long hash[]= {-8017261424500504960,-7417030212113027668,-4495301772150012897,8444435679621798267,8444435679621798268};
   ArrayPrint(hash);
   for(int i=0; i<ArraySize(hash); i++)
     {
      long my_hash=hash[i];
      int index=ArrayBsearch(hash,my_hash);
      Print(my_hash,": ",index);
     }
  }
//+------------------------------------------------------------------+
//| >>>| -8017261424500504960 -7417030212113027668                   |
//|-4495301772150012897 8444435679621798267  8444435679621798268     |
//|   -8017261424500504960: 0                                        |
//|   -7417030212113027668: 1                                        |
//|   -4495301772150012897: 2                                        |
//|   8444435679621798267: 3                                         |
//|   8444435679621798268: 4                                         |
//+------------------------------------------------------------------+
 
DMITRII PECHERITSA:

It's not a question of getting around the error, but of fixing it, especially since this function can be used in many sources, even standard ones. And it is possible that it is used in the terminal code itself, code editor...

 
Aliaksandr Hryshyn:

It's not a question of getting around the error, but of fixing it, especially since this function can be used in many sources, even standard ones. And it is possible that it is used in the terminal code itself, code editor...

I think the problem is with large bits in a situation where almost all bits are busy. it's amazing that someone found this error after so much time.


 
DMITRII PECHERITSA:

They will probably fix it. in my opinion, the problem is with large longs in a situation where almost all bits are busy. it's surprising that someone found this bug after so much time.


I'm surprised they haven't found this bug in a frequently used function in such a long time.

 

Again, about uninitialised variables. It's clear that their value can be unpredictable in any way. But this is the first time I encountered that they can change their value by themselves at runtime of a function (I haven't found it by searching). Here's the script code and what I get:

//--- проверка поведения неинициализированных переменных
void OnStart()
  {
   Print("проверка поведения неинициализированных переменных");
   long a, b;


//тест без изменения значений переменных
   PrintFormat("a==%I64d, b==%I64d", a, b);
   Print("a==1:", a == 1);
   Print("a==2:", a == 2);
   Print("b==1:", b == 1);
   Print("b==2:", b == 2);

   PrintFormat("%I64d", 1);  //после этого начинаются чудеса

   PrintFormat("a==%I64d", a);
   PrintFormat("b==%I64d", b);
   Print("a==1:", a == 1);
   Print("a==2:", a == 2);
   Print("b==1:", b == 1);
   Print("b==2:", b == 2);
   PrintFormat("a==%I64d, b==%I64d", a, b);
   Print("a==1:", a == 1);
   Print("a==2:", a == 2);
   Print("b==1:", b == 1);
   Print("b==2:", b == 2);

//тест с изменением значения переменных
   int x, y = 0;
   Print("x=", x, " y=", y);
   Print("y = x++");
   y = x++;
   Print("x=", x, " y=", y);
  }

result:

2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    проверка поведения неинициализированных переменных
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==0, b==-10289152
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==1:false
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==2:false
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==1:false
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==2:false
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    1
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==1
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==1
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==1:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==2:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==1:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==2:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==1, b==-10289152
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==1:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    a==2:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==1:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    b==2:true
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    x=1 y=0
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    y = x++
2021.02.19 20:23:07.446 TestBug (Eu-3.21,H1)    x=1 y=0

terminal:
2021.02.19 19:30:47.003 Terminal Opening Broker x64 build 2755 started for JSC ''Opening Broker''
2021.02.19 19 19:30:47.113 Terminal Windows 7 Service Pack 1 build 7601, Intel Core i5-2520M @ 2.50GHz, 5 / 7 Gb memory, 41 / 287 Gb disk, IE 11, UAC, GMT+3

If the script runs repeatedly, the initial values of variables a,b and x may change, but the overall behavior is constant:

1. In the first part of the script, the values of variables a and b in the code do not change, but after running PrintFormat("%I64d", 1) suddenly PrintFormat("a==%I64d", a) outputs 1, the same for b. And most interestingly (a==1)==true and immediately (a==2)==true (for b as well)!!! In the last call PrintFormat("a==%I64d, b==%I64d", a, b) shows a==1, but b == the value that was at the beginning of the script.

2. In the second part of the script I try to change the value of the uninitial variable. After y=x++ the value of x should change. But it remains the same (in this run ==1).

Please, someone try to run the script and post the output.

Hence question to connoisseurs - is this normal behaviour (like undefined behaviour)? Or is it a bug?

 
mktr8591:

Again, about uninitialised variables. It's clear that their value can be unpredictable in any way. But this is the first time I encountered that they can change their value by themselves at runtime of a function (I haven't found it by searching). Here's the script code and what I get:

result:


terminal:
2021.02.19 19:30:47.003 Terminal Opening Broker x64 build 2755 started for JSC ''Opening Broker''
2021.02.19 19 19:30:47.113 Terminal Windows 7 Service Pack 1 build 7601, Intel Core i5-2520M @ 2.50GHz, 5 / 7 Gb memory, 41 / 287 Gb disk, IE 11, UAC, GMT+3

If the script runs repeatedly, the initial values of variables a,b and x may change, but the overall behavior is constant:

1. In the first part of the script, the values of variables a and b in the code do not change, but after running PrintFormat("%I64d", 1) suddenly PrintFormat("a==%I64d", a) outputs 1, the same for b. And most interestingly (a==1)==true and immediately (a==2)==true (for b as well)!!! In the last call PrintFormat("a==%I64d, b==%I64d", a, b) shows a==1, but b == the value that was at the beginning of the script.

2. In the second part of the script I try to change the value of the uninitial variable. After y=x++ the value of x should change. But it remains the same (in this run ==1).

Please, someone try to run the script and post the output.

Hence question to connoisseurs - is this normal behaviour (like undefined behaviour)? Or is it a bug?

Not initialising your variables is abnormal behaviour. Initialise and there will be no such questions.
Reason: