AddFingerprintBuffer() with handling of empty strings

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
langinagel
Enthusiast
Enthusiast
Posts: 131
Joined: Fri Jan 28, 2005 11:53 pm
Location: Germany
Contact:

AddFingerprintBuffer() with handling of empty strings

Post 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
https://www.doerpsoft.org

Boost. Work. Efficiency.
Fred
Administrator
Administrator
Posts: 18162
Joined: Fri May 17, 2002 4:39 pm
Location: France
Contact:

Re: AddFingerprintBuffer() with handling of empty strings

Post 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 ?
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: AddFingerprintBuffer() with handling of empty strings

Post 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))
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
User avatar
langinagel
Enthusiast
Enthusiast
Posts: 131
Joined: Fri Jan 28, 2005 11:53 pm
Location: Germany
Contact:

Re: AddFingerprintBuffer() with handling of empty strings

Post 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
https://www.doerpsoft.org

Boost. Work. Efficiency.
User avatar
Lunasole
Addict
Addict
Posts: 1091
Joined: Mon Oct 26, 2015 2:55 am
Location: UA
Contact:

Re: AddFingerprintBuffer() with handling of empty strings

Post 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).
"W̷i̷s̷h̷i̷n̷g o̷n a s̷t̷a̷r"
Post Reply