Recent

Author Topic: [SOLVED] StringToHex might not return a result  (Read 1027 times)

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
[SOLVED] StringToHex might not return a result
« on: August 11, 2023, 08:22:34 pm »
packages/fcl-hash/src/fphashutils.pp has the following function
Code: Pascal  [Select][+][-]
  1. function StringToHex(const s: ansistring): ansistring;
  2. begin
  3.   if s='' then exit;
  4.   BytesToHexStr(Result,@s[1],length(s));
  5. end;
The code of this function might not assign a result.
« Last Edit: August 12, 2023, 01:26:47 pm by lagprogramming »

domasz

  • Hero Member
  • *****
  • Posts: 553
Re: StringToHex might not return a result
« Reply #1 on: August 11, 2023, 08:28:17 pm »
Seems someone forgot 3 chars
Code: Pascal  [Select][+][-]
  1.     function StringToHex(const s: ansistring): ansistring;
  2.     begin
  3.       if s='' then exit(s);
  4.       BytesToHexStr(Result,@s[1],length(s));
  5.     end;
« Last Edit: August 11, 2023, 08:30:03 pm by domasz »

lagprogramming

  • Sr. Member
  • ****
  • Posts: 407
Re: StringToHex might not return a result
« Reply #2 on: August 11, 2023, 08:33:15 pm »
Seems someone forgot 3 chars
Code: Pascal  [Select][+][-]
  1.     function StringToHex(const s: ansistring): ansistring;
  2.     begin
  3.       if s='' then exit(s);
  4.       BytesToHexStr(Result,@s[1],length(s));
  5.     end;
Maybe 4: :-\ exit('');
Edit: Should this function be allowed to return an empty string?  :-\ We'll see.
« Last Edit: August 11, 2023, 08:36:33 pm by lagprogramming »

Thaddy

  • Hero Member
  • *****
  • Posts: 16169
  • Censorship about opinions does not belong here.
Re: StringToHex might not return a result
« Reply #3 on: August 11, 2023, 08:38:57 pm »
That is flawed indeed, use syutils and the helper ToHexString.
If I smell bad code it usually is bad code and that includes my own code.

AlexTP

  • Hero Member
  • *****
  • Posts: 2481
    • UVviewsoft

 

TinyPortal © 2005-2018