Errors, bugs, questions - page 727

 
Renat:

A question was raised about FileReadArray, and in the explanation I pointed out that it has a feature that reads the wrong type of data.

hence the question: how does this feature fit in with language security?

If it's ok, why not make a standard function to convert a bit field to the right type?

In general, either put things in order and remove this feature or let people implement long arithmetic.

Here's an example of this feature through a wipe file:

double arr[]; ulong arr1[]; 
//+------------------------------------------------------------------+
void OnStart()
  {   
   ArrayResize(arr,1); arr[0]=123.2564;
   WriteArrayFile();
   ReadArrayFile();
   Print(arr1[0]);
  }
//+------------------------------------------------------------------+
void WriteArrayFile(string folder="Calculator")
  {
   int han=FileOpen(folder+".dat",FILE_WRITE|FILE_BIN);
   if(han!=INVALID_HANDLE)
     {      
      FileWriteArray(han,arr);              
      FileClose(han);
     }
  }
//+------------------------------------------------------------------+
void ReadArrayFile(string folder="Calculator")
  {
   int han=FileOpen(folder+".dat",FILE_READ|FILE_BIN);
   if(han!=INVALID_HANDLE)
     {      
      FileReadArray(han,arr1);             
      FileClose(han);
     }
  }
//+------------------------------------------------------------------+
 
Paranoia detected.
 
TheXpert:
Paranoia detected.

You should think it over.

I'm actually in favour of deeming it safe and making its counterpart without using a file, but directly.

But if MQ recognizes it as unsafe, then it should be removed from the function as well.

ZZZY By the way maybe I really lug something wrong today, I have not answered two questions, you enlighten me, point the finger where stupid.

 
Urain:

Here's an example of this fix via file with wiping the screw:


Why go through a file? It's easier than that. Read about Data type conversion of simple structures
 
 
Renat:
When testing on crosses there is accurate modelling and other rates for correct conversion of profits and margin requirements.
Try running the visualisation and you will immediately understand the amount of calculations based on the number of background characters in the marketwatch.
I can understand it all, but a 13.7x difference in speed... Well, 2x is okay. And the puppyish joy of opening price testing speed on majors has been replaced by tearful dejection on crosses. And instead of using 30 native remote agents, we'll have to bribe the cludes again... Abyss!
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
Документация по MQL5: Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы
  • www.mql5.com
Стандартные константы, перечисления и структуры / Константы индикаторов / Ценовые константы - Документация по MQL5
 
Urain:

Develop the thought.

I'm actually in favour of deeming it safe and making its counterpart without using a file, but directly.

But if MQ recognizes it as unsafe, it should be removed from the function as well.

ZZZY By the way maybe I'm really babbling today something not right, I have not answered two questions, you really enlighten me, point the finger where dumb.

The file itself is impersonal. It is not known beforehand which way this file was written. In other words, the functionality described above cannot be banned. Of course, you can organoleptically detect a pure text file, and there are some issues with Unicode and Ansi-encodings.

So you can read any file at will. And it won't lead to any dangerous situation, because the sizes of reads (and writes too) are controlled. You won't be able to break the stack. You will not be able to get an address into process memory in any way.

 
muallch:
I can understand that, but a 13.7 times speed difference... Well, 2x is okay. And the puppyish joy of testing speed at opening prices on majors has been replaced by tearful dejection on crosses. And instead of using 30 native remote agents, we'll have to bribe the cludes again... Abyss!
We are looking into this issue. Opening price testing on crosses will be accelerated.
 
stringo:

The file itself is an impersonal file. It is not known in advance how the file was recorded. In other words, the functionality described above cannot be prohibited. It is of course possible to organoleptically detect a pure text file, and there are nuances with Unicode and Ansi encodings.

So you can read any file at will. And it won't lead to any dangerous situation, because the sizes of reads (and writes too) are controlled. You won't be able to break the stack. You cannot get an address into process memory in any way.

Then I see no reason not to introduce a direct read function without type conversion, ala

double a=123.2564; ulong b;

b=Byte(a,TYPE_ULONG);
Print(b);
//--- результат 4638373815016729713

Put it in a function and everything will be safe.

 
Urain:

Then I see no reason not to introduce a direct data reading function without type conversion, ala

Put it in a function and everything will be safe.

struct __double { double v; }

struct __long { long v; }

__double a; __long b;

a.v=123.456;

b=a;

b.v=4638373815016729713;

not hard.

+ read besides the top links https://www.mql5.com/ru/articles/364


And conversion from one type to another can be done either using macros or functions.

but there's nothing really complicated about it.

Избавляемся от балласта самодельных DLL
Избавляемся от балласта самодельных DLL
  • 2012.01.31
  • o_O
  • www.mql5.com
Если MQL5-программисту недостаточно функционала языка, он вынужден обращаться к дополнительным инструментам. Для этого приходится использовать другой язык программирования и создавать промежуточную DLL. В MQL5 имеется механизм представления разных типов данных с помощью структур и передачи их в API, но к сожалению, MQL5 не отвечает нам на вопрос о том, как вытянуть данные из принятого указателя. В данной статье мы поставим точку в этом вопросе и покажем простые механизмы обмена сложными типами данных и работе с ними.
Reason: