CharArrayToString bug with build 5660

 

I just discovered an error when decoding base64 code after updating the terminal (in previous versions this error was not encountered)

string Base64Encode(string text) {
  uchar src[], dst[], key[] = {};
  StringToCharArray(text, src, 0, -1, CP_UTF8);
  ArrayResize(src, ArraySize(src) - 1);
  int res = CryptEncode(CRYPT_BASE64, src, key, dst);
  return (res > 0) ? CharArrayToString(dst, 0, -1, CP_ACP) : "";
}

string Base64Decode(string text) {
  uchar src[], dst[], key[] = {};
  StringToCharArray(text, src, 0, -1, CP_ACP);
  ArrayResize(src, ArraySize(src) - 1);
  int res = CryptDecode(CRYPT_BASE64, src, key, dst);
  return (res > 0) ? CharArrayToString(dst, 0, res, CP_UTF8) : "";
}

void OnStart() {
  string o = "«abc»—";
  string en = Base64Encode(o);
  string de = Base64Decode(en);

  Print(o);
  Print(en);
  Print(de);
}


Result:     


 

Confirmed and reported to MQ.

The problem is with CharArrayToString() so I edited your topic.

 
Alain Verleyen #:

Confirmed and reported to MQ.

The problem is with CharArrayToString() so I edited your topic.

Thank you
 
Fixed from build 5663.
 

It raises another problem. 1 leaked strings left when I run this code. Is it a bug and does it affect long-term performance?

Alain Verleyen #:
Fixed from build 5663.
 
Le Minh Duc #:

It raises another problem. 1 leaked strings left when I run this code. Is it a bug and does it affect long-term performance?

Yes know issue already reported.
 
Le Minh Duc #:

It raises another problem. 1 leaked strings left when I run this code. Is it a bug and does it affect long-term performance?

Fixed in build 5664.