Page 1 of 1
AddFingerprintBuffer() with handling of empty strings
Posted: Mon Jan 02, 2017 12:09 pm
by langinagel
Howdy, the crucial code:
Code: Select all
Length = StringByteLength(*Buffer\string)
AddFingerprintBuffer(FingerprintNo, @*Buffer\string , Length)
Problem: when string = "" , Length is 0 and AddFingerprintBuffer() gets stucked.
Any workaround is not obvious to me, since Fingerprint() yields to
MD5 checksum = d41d8cd98f00b204e9800998ecf8427e (StartFingerprint -Example with empty string)
and an empty string is not a full undefined situation.
Greetings
LN
Re: AddFingerprintBuffer() with handling of empty strings
Posted: Mon Jan 02, 2017 12:55 pm
by Fred
You shouldn't pass a zero length to AddFingerprintBuffer() (a debugger warning should be displayed). Or may be you just want to ignore the function when a zero length is specified ?
Re: AddFingerprintBuffer() with handling of empty strings
Posted: Mon Jan 02, 2017 12:59 pm
by Lunasole
langinagel wrote:
Problem: when string = "" , Length is 0 and AddFingerprintBuffer() gets stucked.
The following code doesn't gets stuck in 5.5 and returns hash you mentioned correctly. Only if run with debugger it warns that length is 0.
Code: Select all
EnableExplicit
Structure AB
String.s
EndStructure
Define *Buffer.AB = AllocateStructure(AB)
Define Length = StringByteLength(*Buffer\string)
UseMD5Fingerprint()
StartFingerprint(0, #PB_Cipher_MD5)
AddFingerprintBuffer(0, @*Buffer\string , Length)
MessageRequester("", FinishFingerprint(0))
Re: AddFingerprintBuffer() with handling of empty strings
Posted: Mon Jan 02, 2017 4:47 pm
by langinagel
OK,
I have to admit the "problem" occurs only in Debug-mode.
But I hesitate to put a function blocked in Debug-Mode into full function without Debug.
Usually compiler warnings do have a meaning that something is not the way it should be.
But maybe it is just me and the rest of the world does not about it.
Greetings
LN
Re: AddFingerprintBuffer() with handling of empty strings
Posted: Mon Jan 02, 2017 8:13 pm
by Lunasole
langinagel wrote:
But I hesitate to put a function blocked in Debug-Mode into full function without Debug.
Usually compiler warnings do have a meaning that something is not the way it should be.
Well PB warnings are mostly useless as for me, in my case they were rather annoying when I've seen them (like "you used ID > 1000"). Should probably completely disable them in IDE settings (the second option is to add DisableDegugger/EnableDegugger around every line which annoys).