CVS | CVSHORT BUG

General FreeBASIC programming questions.
albert
Posts: 5313
Joined: Sep 28, 2006 2:41
Location: California, USA

CVS | CVSHORT BUG

Postby albert » May 26, 2019 18:03

I found a bug in the cvs,cvshort functions.... It returns 0 for single chrs

I thought i had data compression accomplished , and then found the bug...

Code: Select all


screen 19

print cvs("A")
print cvshort("A")

print cvs("AA")
print cvshort("AA")

sleep
end

fxm
Posts: 9310
Joined: Apr 22, 2009 12:46
Location: Paris suburbs, FRANCE

Re: CVS | CVSHORT BUG

Postby fxm » May 26, 2019 18:21

Have you well read the documentation?
The behavior that you highlight is perfectly described in the documentation for each keyword?
albert
Posts: 5313
Joined: Sep 28, 2006 2:41
Location: California, USA

Re: CVS | CVSHORT BUG

Postby albert » May 27, 2019 1:50

cvshort returns 0 if you pass it a single byte..

cvshort returns signed value when passed 2 bytes.

when you assign the cvshort to a ushort it returns correct ushort value.
when you assign the cvshort to a ulongint it returns max ulongint - signed short value. instead of the ushort value.

Code: Select all


screen 19

dim as ulongint n1
dim as ushort n2

 print cvshort( chr(200) )
 
 print cvshort ( chr(200) + chr(200) )
 
 n1 = cvshort ( chr(200) + chr(200) )
 
 print n1
 
 n2 = cvshort ( chr(200) + chr(200) )
 
 print n2
 
 sleep
 end
 
counting_pine
Site Admin
Posts: 6174
Joined: Jul 05, 2005 17:32
Location: Manchester, Lancs

Re: CVS | CVSHORT BUG

Postby counting_pine » May 29, 2019 13:33

The simplest workaround for this is to pad the string with enough Null characters (i.e. 'Chr(0)') to make sure the string is long enough.

Code: Select all

dim as string s = chr(200)
print cvshort(s & chr(0))
print cvs(s & string(3, 0))

Return to “General”

Who is online

Users browsing this forum: No registered users and 1 guest